Block-Adblocker-blocker

Blocks Anti-adblockers on several Indian News Sites

Verze ze dne 06. 07. 2016. Zobrazit nejnovější verzi.

  1. // ==UserScript==
  2. // @name Block-Adblocker-blocker
  3. // @namespace http://www.piyushsoni.com
  4. // @description Blocks Anti-adblockers on several Indian News Sites
  5. // @include http://timesofindia.indiatimes.com/*
  6. // @include http://www.hindustantimes.com/*
  7. // @include http://*.ndtv.com/*
  8. // @include http://*.anandabazar.com/*
  9. // @run-at document-start
  10. // @version 1.20
  11. // @grant none
  12. // @author Piyush Soni (irrationalapps+blockerblocker@gmail.com)
  13. // @license GNU LGPL v3 (https://www.gnu.org/licenses/lgpl-3.0.html)
  14. // ==/UserScript==
  15.  
  16. var url = window.location.href.toLowerCase();
  17. var domain = new URL(url).hostname.replace("www.","");
  18. var mapPagesBlockerBlockers = {};
  19. var countStopped = 0;
  20. var countToCheck = 0;
  21. var arrPageBlockers;
  22.  
  23.  
  24. //Add new blocker list here
  25. ///mapPagesBlockerBlockers['<domain>'] = ['<external script source match>','<inline script source match>', <stop any 1 r more(count)>]
  26. mapPagesBlockerBlockers['indiatimes.com'] = [['detector', 'blocked.cms'], 1];
  27. mapPagesBlockerBlockers['hindustantimes.com'] = [['BlockerScript', 'checkAdBlocker'], 2];
  28. mapPagesBlockerBlockers['ndtv.com'] = [['canRunAds'], 1];
  29. mapPagesBlockerBlockers['anandabazar.com'] = [['custom.js', 'checkAdBlock'], 2];
  30.  
  31.  
  32.  
  33. var arrDomain = domain.split('.');
  34. if(arrDomain.length > 2)
  35. domain = arrDomain[arrDomain.length - 2] + "." + arrDomain[arrDomain.length - 1];
  36.  
  37. function scriptListener(e)
  38. {
  39. let i = 0;
  40. let src = e.target.src;
  41. let html = e.target.innerHTML;
  42. for(i=0; i < arrPageBlockers.length; ++i)
  43. {
  44. let blocker = arrPageBlockers[i];
  45. if(blocker.length > 0 && ((typeof src != "undefined" && src && src.indexOf(blocker) >= 0) || (typeof html != "undefined" && html && html.indexOf(blocker) >= 0)))
  46. {
  47. //Stop this nonsense.
  48. e.preventDefault();
  49. e.stopPropagation();
  50. console.log("Blocked an Anti-adblocker for " + domain);
  51.  
  52. countStopped++;
  53. if(countStopped >= countToCheck)
  54. {
  55. //We're done, remove the event listener now
  56. window.removeEventListener(e.type, arguments.callee, true);
  57. }
  58. }
  59. }
  60. }
  61.  
  62. if(domain in mapPagesBlockerBlockers)
  63. {
  64. arrPageBlockers = mapPagesBlockerBlockers[domain][0];
  65. countToCheck = mapPagesBlockerBlockers[domain][1];
  66. window.addEventListener('beforescriptexecute', scriptListener, true);
  67. }