Advertisement
Guest User

modded Adblock Protector for "cwtv.com"

a guest
Nov 9th, 2016
1,510
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name AdBlock Protector Script
  3. // @description Quick solutions against AdBlock detectors
  4. // @author X01X012013
  5. // @version 2.0.2
  6. // @encoding utf-8
  7. // @include http://*/*
  8. // @include https://*/*
  9. // @grant unsafeWindow
  10. // @run-at document-start
  11. // @homepage https://x01x012013.github.io/AdBlockProtector/
  12. // @supportURL https://github.com/X01X012013/AdBlockProtector/issues
  13. // @downloadURL https://x01x012013.github.io/AdBlockProtector/AdBlockProtector.user.js
  14. // ==/UserScript==
  15.  
  16. (function () {
  17.     "use strict";
  18.     /**
  19.      * Whether or not debug string should be logged.
  20.      * @const {boolean}
  21.      */
  22.     const debugMode = true;
  23.     //=====Library=====
  24.     /**
  25.      * The error message to show when this script takes effect.
  26.      * @const {string}
  27.      */
  28.     const errMsg = "Uncaught AdBlock Error: AdBlocker detectors are not allowed on this device. ";
  29.     /**
  30.      * Pointers to functions to hide.
  31.      * This array and {@link filterString} are parallel arrays, and is used in {@link hideFilter}.
  32.      * @var {Function}
  33.      */
  34.     let filterPointers = [];
  35.     /**
  36.      * The string values of the real function.
  37.      * This array and {@link filterPointer} are parallel arrays, and is used in {@link hideFilter}.
  38.      * @var {string}
  39.      */
  40.     let filterStrings = [];
  41.     /**
  42.      * Replace Function.prototype.toString() in order to prevent filters from being detected.
  43.      * Do not call this function multiple times.
  44.      * @function
  45.      * @return {boolean} True if the operation was successful, false otherwise.
  46.      */
  47.     const hideFilter = function () {
  48.         //The original function
  49.         const original = unsafeWindow.Function.prototype.toString;
  50.         //New function
  51.         const newFunc = function () {
  52.             //Check if this function is in the protected list
  53.             const index = filterPointers.indexOf(this);
  54.             if (index !== -1) {
  55.                 //Protected, return the string value of the real function instead
  56.                 return filterStrings[index];
  57.             } else {
  58.                 //Not protected, use original function to proceed
  59.                 return original.apply(this);
  60.             }
  61.         };
  62.         //Try to replace the function
  63.         try {
  64.             //Replace function
  65.             unsafeWindow.Function.prototype.toString = newFunc;
  66.             //Protect this function as well
  67.             filterPointers.push(newFunc);
  68.             filterStrings.push(original.toString());
  69.             //Debug - Log when activated
  70.             if (debugMode) {
  71.                 console.warn("Filters hidden. ");
  72.             }
  73.         } catch (err) {
  74.             //Failed to activate (will always log)
  75.             console.error("Failed to hide filters! ");
  76.             return false;
  77.         }
  78.         return true;
  79.     };
  80.     /**
  81.      * Prevent a string or function with specific keyword from executing.
  82.      * Use RegExp to combine filters, do not activate filter multiple times on the same function.
  83.      * @function
  84.      * @param {string} func - The name of the function to filter, use "." to separate multiple layers, max 2 layers.
  85.      * @param {RegExp} [filter=/[\S\s]/] - Filter to apply, block everything if this argument is missing.
  86.      * @return {boolean} True if the operation was successful, false otherwise.
  87.      */
  88.     const activateFilter = function (func, filter) {
  89.         //Default parameters
  90.         filter = filter || /[\S\s]/;
  91.         //Messages
  92.         const callMsg = " is called with these arguments: ",
  93.               passMsg = "Test passed. ",
  94.               activateMsg = "Filter activated on ",
  95.               failedMsg = "AdBlock Protector failed to activate filter on ";
  96.         //The original function, will be set later
  97.         let original;
  98.         //The function names array, will be set later if there is more than one layer
  99.         let fNames;
  100.         //The function with filters
  101.         const newFunc = function () {
  102.             //Debug - Log when called
  103.             if (debugMode) {
  104.                 console.warn(((typeof func === "string") ? func : func.join(".")) + callMsg);
  105.                 for (let i = 0; i < arguments.length; i++) {
  106.                     console.warn(arguments[i].toString());
  107.                 }
  108.             }
  109.             //Apply filter
  110.             for (let i = 0; i < arguments.length; i++) {
  111.                 if (filter.test(arguments[i].toString())) {
  112.                     //Not allowed (will always log)
  113.                     return console.error(errMsg);
  114.                 }
  115.             }
  116.             //Debug - Log when passed
  117.             if (debugMode) {
  118.                 console.info(passMsg);
  119.             }
  120.             //Allowed
  121.             if (typeof fNames === "object") {
  122.                 //Two layers
  123.                 return original.apply(unsafeWindow[fNames[0]], arguments);
  124.             } else {
  125.                 //One layer
  126.                 return original.apply(unsafeWindow, arguments);
  127.             }
  128.         };
  129.         //Try to replace the function
  130.         try {
  131.             //Replace function
  132.             if (func.includes(".")) {
  133.                 //Two layers
  134.                 fNames = func.split(".");
  135.                 original = unsafeWindow[fNames[0]][fNames[1]];
  136.                 unsafeWindow[fNames[0]][fNames[1]] = newFunc;
  137.             } else {
  138.                 //One layer
  139.                 original = unsafeWindow[func];
  140.                 unsafeWindow[func] = newFunc;
  141.             }
  142.             //Add this filter to protection list
  143.             filterPointers.push(newFunc);
  144.             filterStrings.push(original.toString());
  145.             //Debug - Log when activated
  146.             if (debugMode) {
  147.                 console.warn(activateMsg + func);
  148.             }
  149.         } catch (err) {
  150.             //Failed to activate (will always log)
  151.             console.error(failedMsg + func + "! ");
  152.             return false;
  153.         }
  154.         return true;
  155.     };
  156.     /**
  157.      * Defines a read-only property to unsafeWindow.
  158.      * @function
  159.      * @param {string} name - The name of the property to define.
  160.      * @param {*} val - The value to set.
  161.      * @return {boolean} True if the operation was successful, false otherwise.
  162.      */
  163.     const setReadOnly = function (name, val) {
  164.         //Try to set read only variable
  165.         try {
  166.             if (name.includes(".")) {
  167.                 //Two layers
  168.                 let nameArray = name.split(".");
  169.                 Object.defineProperty(unsafeWindow[nameArray[0]], nameArray[1], {
  170.                     value: val,
  171.                     configurable: false,
  172.                     writable: false
  173.                 });
  174.             } else {
  175.                 //One layer
  176.                 Object.defineProperty(unsafeWindow, name, {
  177.                     value: val,
  178.                     configurable: false,
  179.                     writable: false
  180.                 });
  181.             }
  182.             console.error(errMsg);
  183.         } catch (err) {
  184.             //Failed to activate (will always log)
  185.             console.error("AdBlock Protector failed to define read-only property " + name + "! ");
  186.             return false;
  187.         }
  188.         return true;
  189.     };
  190.     /**
  191.      * Run a function when an event triggers.
  192.      * @function
  193.      * @param {string} event - The name of the event.
  194.      * @param {Function} func - The function to run.
  195.      */
  196.     const onEvent = function (event, func) {
  197.         unsafeWindow.addEventListener(event, func);
  198.         console.error(errMsg);
  199.     };
  200.     /**
  201.      * Shortcut to document.domain.
  202.      * @const {string}
  203.      */
  204.     const Domain = document.domain;
  205.     //=====Main=====
  206.     //Hide filters
  207.     hideFilter();
  208.     //Debug - Log domain
  209.     if (debugMode) {
  210.         console.warn("Domain: " + Domain);
  211.     }
  212.     //Exact matching
  213.     switch (Domain) {
  214.         case "www.blockadblock.com":
  215.         case "blockadblock.com":
  216.             //Filter keyword from eval()
  217.             activateFilter("eval", /BlockAdblock/);
  218.             onEvent("load", function () {
  219.                 $("#babasbmsgx").remove();
  220.             });
  221.             break;
  222.         case "sc2casts.com":
  223.             //Lock scriptfailed() and disable setTimeout()
  224.             setReadOnly("scriptfailed", function () { });
  225.             activateFilter("setTimeout");
  226.             break;
  227.         case "infotainment.jagranjunction.com":
  228.             //Lock canRunAds and isAdsDisplayed to true
  229.             setReadOnly("canRunAds", true);
  230.             setReadOnly("isAdsDisplayed", true);
  231.             break;
  232.         case "haxoff.com":
  233.         case "fullstuff.co":
  234.         case "www.usapoliticstoday.com":
  235.             //Disable eval()
  236.             activateFilter("eval");
  237.             break;
  238.         case "malayalam.samayam.com":
  239.             //Lock canRun to true
  240.             setReadOnly("canRun", true);
  241.             break;
  242.         case "www.qbasic.net":
  243.             //Lock dload to a special version
  244.             setReadOnly("dload", function (dlID, fileID) {
  245.                 ga("send", "event", "Download", "Submit", fileID);
  246.                 location.href = "http://" + window.location.hostname + "/dl.php?id=" + dlID + "&file=" + fileID;
  247.                 window.success = true;
  248.                 return success;
  249.             });
  250.             break;
  251.         case "www.badtaste.it":
  252.         case "www.badtv.it":
  253.         case "www.badcomics.it":
  254.         case "www.badgames.it":
  255.             //Lock isAdBlockActive to false and set cookie adBlockChecked to disattivo
  256.             setReadOnly("isAdBlockActive", false);
  257.             document.cookie = "adBlockChecked=disattivo";
  258.             break;
  259.         case "ay.gy":
  260.             //Disable open() before page starts to load and set abgo to an empty function when the page loads
  261.             setReadOnly("open", function () { });
  262.             onEvent("load", function () {
  263.                 unsafeWindow.abgo = function () { };
  264.             });
  265.             //Skip countdown
  266.             const _setInterval = unsafeWindow.setInterval;
  267.             unsafeWindow.setInterval = function (func) {
  268.                 return _setInterval(func, 10);
  269.             };
  270.             break;
  271.         case "indianexpress.com":
  272.         case "www.jansatta.com":
  273.         case "www.financialexpress.com":
  274.             //Lock RunAds to true
  275.             setReadOnly("RunAds", true);
  276.             break;
  277.         case "www.livemint.com":
  278.             //SLock canRun1 to true
  279.             setReadOnly("canRun1", true);
  280.             break;
  281.         case "www.business-standard.com":
  282.             //Lock isBannerActive and adsLoaded to true
  283.             setReadOnly("isBannerActive", true);
  284.             setReadOnly("adsLoaded", true);
  285.             break;
  286.         case "userscloud.com":
  287.             //Show hidden div and remove block screen
  288.             onEvent("load", function () {
  289.                 $("#dl_link").show();
  290.                 $("#adblock_msg").remove();
  291.             });
  292.             break;
  293.         case "player.pl":
  294.             setReadOnly("TvnAdblockBoardUtils", false);
  295.             break;
  296.         case "www.vidlox.tv":
  297.         case "vidlox.tv":
  298.             //Lock xRds to false and cRAds to true
  299.             setReadOnly("xRds", false);
  300.             setReadOnly("cRAds", true);
  301.             break;
  302.         case "cwtv.com":
  303.             setReadOnly("wallConfig", false);
  304.             break;
  305.         default:
  306.             //Debug - Log when not in exact match list
  307.             if (debugMode) {
  308.                 console.warn(Domain + " is not in AdBlock Protector's exact match list. ");
  309.             }
  310.             break;
  311.     }
  312.     //Partial matching
  313.     if (Domain === "x01x012013.github.io" && document.location.href.indexOf("x01x012013.github.io/AdBlockProtector") !== -1) {
  314.         //Installation test of homepage
  315.         unsafeWindow.AdBlock_Protector_Script = true;
  316.     } else if (Domain.endsWith(".gamepedia.com")) {
  317.         //(Workaround) Remove element
  318.         onEvent("load", function () {
  319.             $("#atflb").remove();
  320.         });
  321.     } else if (Domain.endsWith(".cbox.ws")) {
  322.         //Lock koddostu_com_adblock_yok to true
  323.         setReadOnly("koddostu_com_adblock_yok", true);
  324.     } else if (Domain === "indiatimes.com" || Domain.endsWith(".indiatimes.com") || Domain.endsWith(".ahmedabadmirror.com")) {
  325.         //Filter keyword from document.addEventListener()
  326.         activateFilter("document.addEventListener", /function \_0x/);
  327.         //document.addEventListener should not be native code, but they are expecting native code, strange...
  328.         filterStrings[1] = "function addEventListener() { [native code] }";
  329.     } else if (Domain.endsWith(".pinkrod.com") || Domain.endsWith(".wetplace.com")) {
  330.         //Lock getAd and getUtm to an empty function
  331.         setReadOnly("getAd", function () { });
  332.         setReadOnly("getUtm", function () { });
  333.     } else if (debugMode) {
  334.         //Debug - Log when not in partial match list
  335.         console.warn(Domain + " is not in AdBlock Protector's partial match list. ");
  336.     }
  337.     //TV Nowa (Workaround)
  338.     (function () {
  339.         //Thanks to mikhoul and xxcriticxx for your precious help!
  340.         let domainExact = []; //"tvnfabula.pl", "itvnextra.pl", "tvn24bis.pl", "ttv.pl", "player.pl", "x-news.pl"
  341.         let domainPartial = [".tvn.pl", ".tvnstyle.pl", ".tvnturbo.pl"]; //".tvn7.pl", ".itvn.pl"
  342.         let homePages = ["http://www.tvn.pl/", "http://www.tvn7.pl/", "http://www.tvnstyle.pl/", "http://www.tvnturbo.pl/"];
  343.         //Check homepage first
  344.         if (homePages.includes(document.location.href)) {
  345.             //Home pages are currently handled by List
  346.         } else {
  347.             //Check exact domain
  348.             let isTVN = domainExact.includes(Domain);
  349.             //Check partial domain
  350.             for (let i = 0; i < domainPartial.length; i++) {
  351.                 if (Domain.endsWith(domainPartial[i])) {
  352.                     isTVN = true;
  353.                     break;
  354.                 }
  355.             }
  356.             //Apply video patch
  357.             if (isTVN) {
  358.                 //Temporary workaround: Replace the player
  359.                 onEvent("load", function () {
  360.                     $(".videoPlayer").parent().after($("<iframe width='100%' height='500px'>").attr("src", $(".videoPlayer").data("src"))).remove();
  361.                 });
  362.             }
  363.         }
  364.     })();
  365. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement