Advertisement
Guest User

utils.js

a guest
Apr 14th, 2017
871
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* ----------------------------------------------------------------------------------
  2.  * Authors: Grant Storey & Dillon Reisman
  3.  * Written: 3/5/17
  4.  * Last Updated: 3/7/17
  5.  * Description: Helper code for covering advertisements that have been found.
  6.  * Dependencies: jquery.
  7.  * ----------------------------------------------------------------------------------
  8.  */
  9.  
  10. // sets logging level
  11. var VERBOSE = false;
  12.  
  13. if (typeof NON_ENGLISH_LOCALE === 'undefined') {
  14.   var NON_ENGLISH_LOCALE = false;
  15. }
  16.  
  17. // return whether the container is already covered
  18. function alreadyCovered(container) {
  19.   return (container.find(".PAB_adBlockerCover").length > 0);
  20. }
  21.  
  22. // true if we want to overlay non-ads as well
  23. var showNonAd = false;
  24.  
  25. // return whether the container is already covered by the same type
  26. // of container. That is, if there is already an ad or non-ad container
  27. // we don't want to ad a container of a new type, but if an adchoices
  28. // icon has been added and it changed from non-ad to ad, we do want
  29. // to update.
  30. function alreadyCoveredSameType(container, newCoverIsAd) {
  31.   var alreadyCovered = (container.find(".PAB_adBlockerCover").length > 0);
  32.   var alreadyAd = (container.find(".PAB_isAnAd").length > 0)
  33.   return alreadyCovered && (alreadyAd || !newCoverIsAd);
  34. }
  35.  
  36. // Add a cover with "THIS IS AN AD" and the "Sponsored" text in the given
  37. // locale's language (if non-english).
  38. // container is the container to cover.
  39. // coverText is the text to show on the cover
  40. // matchingText only has a value if we are on Facebook in a non-english locale.
  41. // deepestOnly is true if we only want to include the deepest cover for this
  42. // area.
  43. // isAd is true if it is an ad
  44. // hasInterval is true if there is an interval check associated with this cover
  45. // intervalID is the id of that interval
  46. function coverContainer(container, coverText, matchingText, deepestOnly, isAd, hasInterval, intervalID) {
  47.     // if we aren't doing anything to non-ads and this isn't an ad, do nothing.
  48.     if (!isAd && !showNonAd) {
  49.       return false;
  50.     }
  51.  
  52.   // don't cover if this container is already covered;
  53.   if (alreadyCoveredSameType(container, false)) {
  54.     return false;
  55.   }
  56.  
  57.   // remove any existing covers (if we are moving from non-ad to ad)
  58.   container.find(".PAB_adBlockerCover").remove();
  59.  
  60.   // vary the color and classes based on whether this is an ad or not.
  61.   var color;
  62.   var classes = "PAB_adBlockerCover";
  63.   if (isAd) {
  64.     if (showNonAd) {
  65.       color = "rgba(255, 0, 0, 1)";
  66.     } else {
  67.       color = "rgba(255, 255, 255, 1)";
  68.     }
  69.     classes += " PAB_isAnAd";
  70.   } else {
  71.     color = "rgba(255, 255, 255, 1)";
  72.   }
  73.  
  74.   // some google ads have a height of 0 and then everything in overflow,
  75.   // so if that is the case set the height of the cover to be the overflow
  76.   // height.
  77.   var setHeight;
  78.   var containerHeight = container.height();
  79.   var containerScrollHeight = container.prop('scrollHeight');
  80.   if (containerHeight == 0 && containerScrollHeight > 0) {
  81.     setHeight = containerScrollHeight + "px";
  82.   } else {
  83.     setHeight = "100%"
  84.   }
  85.  
  86.   // create the cover to prepend.
  87.   var prepend = "<div class=\"" + classes + "\" style=\"height: " + setHeight + ";position: absolute;width: 100%;background-color: " + color + " !important;z-index: 100; visibility: visible;\">";
  88.   prepend += "<div class=\"PAB_closeButton\" style=\"position: absolute; right: 5px; top: 5px; cursor: pointer; padding: 0px 3px; border: 1px solid black; border-radius: 5px;\">";
  89.   prepend += "<strong>";
  90.   prepend += "X";
  91.   prepend += "</strong>";
  92.   prepend += "</div>";
  93.   prepend += "<div style=\"width: 100%;text-align:center;\">";
  94.   prepend += "<span style=\"color: black; font-size:60px;\">";
  95.   prepend += coverText;
  96.   prepend += "</span>";
  97.   // if we have "Sponsored" text in another language, add it below "THIS IS AN AD"
  98.   if (NON_ENGLISH_LOCALE && matchingText !== "") {
  99.     prepend += "<br/>"
  100.     prepend += "<span style=\"color: black; font-size:40px; background: rgba(255,255,255,1);\">";
  101.     prepend += "(" + matchingText + ")";
  102.     prepend += "</span>";
  103.   }
  104.   prepend += "</div>";
  105.   prepend += "</div>";
  106.   var myPrepend = prepend;
  107.  
  108.   // if we only want the deepest, remove any above this
  109.   if (deepestOnly) {
  110.     container.parents().each(function (index) {
  111.       $(this).children(".PAB_adBlockerCover").remove();
  112.     });
  113.   }
  114.   // if we only want the deepest covers and there is a cover within
  115.   // this container already, don't ad this cover.
  116.   if (!deepestOnly || !(container.find(".PAB_adBlockerCover").length > 0)) {
  117.     // prepend the cover
  118.     container.css("position", "relative");
  119.     container.prepend(myPrepend);
  120.  
  121.     // make sure the close button closes the cover
  122.     container.children().children(".PAB_closeButton").on("click", function () {
  123.       container.children(".PAB_adBlockerCover").css("visibility", "hidden");
  124.     });
  125.   }
  126.  
  127.  
  128.   // if this is an ad and we have an interval, stop the search for ads.
  129.   if (hasInterval && isAd) {
  130.     clearInterval(intervalID);
  131.   }
  132. }
  133.  
  134. /******************************************************
  135. ***** Demo of link clicking by x/y coordinate. This will work on a logged-in
  136. ***** facebook.com page.
  137. ***** The code clicks on the user's profile in the top bar.
  138. */
  139. /*
  140. setTimeout(function() {
  141.  
  142.     simulateClickByPoint(502,21);
  143.  
  144. }, 5000);
  145. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement