RU AdList JS Fixes

try to take over the world!

当前为 2017-09-24 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name RU AdList JS Fixes
  3. // @namespace ruadlist_js_fixes
  4. // @version 20170925.3
  5. // @description try to take over the world!
  6. // @author lainverse & dimisa
  7. // @match *://*/*
  8. // @grant unsafeWindow
  9. // @grant window.close
  10. // @grant GM_getValue
  11. // @grant GM_setValue
  12. // @run-at document-start
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17. let win = (unsafeWindow || window),
  18. // http://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser
  19. isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0,
  20. isChrome = !!window.chrome && !!window.chrome.webstore,
  21. isSafari = (Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0 ||
  22. (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window.safari || safari.pushNotification)),
  23. isFirefox = typeof InstallTrigger !== 'undefined',
  24. inIFrame = (win.self !== win.top),
  25. _getAttribute = Element.prototype.getAttribute,
  26. _setAttribute = Element.prototype.setAttribute,
  27. _de = document.documentElement,
  28. _appendChild = Document.prototype.appendChild.bind(_de),
  29. _removeChild = Document.prototype.removeChild.bind(_de),
  30. _createElement = Document.prototype.createElement.bind(document);
  31.  
  32. if (isFirefox && // Exit on image pages in Fx
  33. document.constructor.prototype.toString() === '[object ImageDocumentPrototype]')
  34. return;
  35.  
  36. // dTree 2.05 in some cases replaces Node object before my script kicks in :(
  37. if (!Node.prototype)
  38. {
  39. let ifr = _createElement('iframe');
  40. _appendChild(ifr);
  41. try {
  42. window.Node = ifr.contentWindow.Node;
  43. console.log('Node object restored. -_-');
  44. } catch(e) {
  45. console.log('Unable to restore Node object.', e);
  46. }
  47. _removeChild(ifr);
  48. }
  49.  
  50. // NodeList iterator polyfill (mostly for Safari)
  51. // https://jakearchibald.com/2014/iterators-gonna-iterate/
  52. if (!NodeList.prototype[Symbol.iterator]) {
  53. NodeList.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
  54. }
  55.  
  56. // Options
  57. let opts = {
  58. 'useWSIFunc': useWSI
  59. };
  60.  
  61. {
  62. let optsCall = function(callback)
  63. {
  64. // Register event listener
  65. let key = "optsCallEvent_" + Math.random().toString(36).substr(2),
  66. cb = callback.func.bind(callback.name);
  67. window.addEventListener(key, cb, false);
  68. // Generate and dispatch synthetic event
  69. let ev = document.createEvent("HTMLEvents");
  70. ev.initEvent(key, true, false);
  71. window.dispatchEvent(ev);
  72. // Remove listener
  73. window.removeEventListener(key, cb, false);
  74. };
  75.  
  76. let initOptsHandler = function()
  77. {
  78. opts[this] = GM_getValue(this, true);
  79. if (opts[this])
  80. opts[this+'Func']();
  81. };
  82.  
  83. optsCall({
  84. func: initOptsHandler,
  85. name: 'useWSI'
  86. });
  87.  
  88. // show options page
  89. let openOptions = function()
  90. {
  91. let ovl = _createElement('div'),
  92. inner = _createElement('div');
  93. ovl.style = (
  94. 'position: fixed;'+
  95. 'top:0; left:0;'+
  96. 'bottom: 0; right: 0;'+
  97. 'background: rgba(0,0,0,0.85);'+
  98. 'z-index: 2147483647;'+
  99. 'padding: 5em'
  100. );
  101. inner.style = (
  102. 'background: whitesmoke;'+
  103. 'font-size: 10pt;'+
  104. 'color: black;'+
  105. 'padding: 1em'
  106. );
  107. inner.textContent = 'JS Fixes Options: (reload page to apply)';
  108. inner.appendChild(_createElement('br'));
  109. inner.appendChild(_createElement('br'));
  110. ovl.addEventListener(
  111. 'click', function(e)
  112. {
  113. if (e.target === ovl) {
  114. ovl.parentNode.removeChild(ovl);
  115. e.preventDefault();
  116. }
  117. e.stopPropagation();
  118. }, false
  119. );
  120. // append checkbox with label function
  121. function addCheckbox(optName, optLabel)
  122. {
  123. let c = _createElement('input'),
  124. l = _createElement('label');
  125. c.type = 'checkbox';
  126. c.id = optName;
  127. optsCall({
  128. func: function()
  129. {
  130. c.checked = GM_getValue(this);
  131. },
  132. name: optName
  133. });
  134. c.addEventListener(
  135. 'click', function(e)
  136. {
  137. optsCall({
  138. func:function(){
  139. GM_setValue(this, e.target.checked);
  140. opts[this] = e.target.checked;
  141. },
  142. name:optName
  143. });
  144. }, true
  145. );
  146. l.textContent = optLabel;
  147. l.setAttribute('for', optName);
  148. inner.appendChild(c);
  149. inner.appendChild(l);
  150. inner.appendChild(_createElement('br'));
  151. }
  152. // append checkboxes
  153. addCheckbox('useWSI', 'Use WebSocket filter. Disable if experience problems with WebSocket connections.');
  154. document.body.appendChild(ovl);
  155. ovl.appendChild(inner);
  156. };
  157.  
  158. // monitor keys pressed for Ctrl+Alt+Shift+J > s > f code
  159. let opPos = 0, opKey = ['KeyJ','KeyS','KeyF'];
  160. document.addEventListener(
  161. 'keydown', function(e)
  162. {
  163. if ((e.code === opKey[opPos] || e.location) &&
  164. (!!opPos || e.altKey && e.ctrlKey && e.shiftKey))
  165. {
  166. opPos += e.location ? 0 : 1;
  167. e.stopPropagation();
  168. e.preventDefault();
  169. } else {
  170. opPos = 0;
  171. }
  172. if (opPos === opKey.length)
  173. {
  174. opPos = 0;
  175. openOptions();
  176. }
  177. }, false
  178. );
  179. }
  180.  
  181. // Special wrapper script to run scripts designed to override standard DOM functions
  182. // In Firefox appends supplied script to a page to make it run in page context and let
  183. // page content access overridden functions. In other browsers just run it as-is.
  184. function scriptLander(func, prepend)
  185. {
  186. if (!isFirefox)
  187. {
  188. func();
  189. return;
  190. }
  191. let script = _createElement('script');
  192. let inline = ['string', 'function'];
  193. script.textContent = '!function(){let win=window;' + (
  194. inline.includes(typeof prepend) && prepend ||
  195. prepend instanceof Array && prepend.join(';') || ''
  196. ) + ';!' + func + '();}();';
  197. _appendChild(script);
  198. _removeChild(script);
  199. }
  200.  
  201. function nullTools(log) {
  202. // jshint validthis:true
  203. let nt = this;
  204. function trace() { if (log) console.trace.apply(this, arguments); }
  205.  
  206. nt.define = function(obj, prop, val)
  207. {
  208. Object.defineProperty(
  209. obj, prop, {
  210. get: () => (trace('get', prop, 'of', obj, 'which is', val), val),
  211. set: (v) => (trace('set', prop, 'of', obj, 'to', v), v),
  212. enumerable: true
  213. }
  214. );
  215. };
  216. nt.proxy = function(obj)
  217. {
  218. return new Proxy(
  219. obj, {
  220. get: (t, p) => (trace('get', p, 'of', t, 'which is', t[p]), t[p]),
  221. set: (t, p, v) => (trace('set', p, 'of', t, 'to', v), v)
  222. }
  223. );
  224. };
  225. nt.func = (val) => () => (trace('call func, return', val), val);
  226. }
  227.  
  228. // Fake objects of advertisement networks to break their workflow
  229. scriptLander(
  230. function()
  231. {
  232. let nt = new nullTools();
  233. if (!('fuckAdBlock' in win))
  234. {
  235. let FuckAdBlock = function(options) {
  236. let self = this;
  237. self._options = {
  238. checkOnLoad: false,
  239. resetOnEnd: false,
  240. checking: false
  241. };
  242. self.setOption = function(opt, val)
  243. {
  244. if (val)
  245. self._options[opt] = val;
  246. else
  247. Object.assign(self._options, opt);
  248. };
  249. if (options)
  250. self.setOption(options);
  251.  
  252. self._var = { event: {} };
  253. self.clearEvent = function()
  254. {
  255. self._var.event.detected = [];
  256. self._var.event.notDetected = [];
  257. };
  258. self.clearEvent();
  259.  
  260. self.on = function(detected, fun)
  261. {
  262. self._var.event[detected?'detected':'notDetected'].push(fun);
  263. return self;
  264. };
  265. self.onDetected = function(cb)
  266. {
  267. return self.on(true, cb);
  268. };
  269. self.onNotDetected = function(cb)
  270. {
  271. return self.on(false, cb);
  272. };
  273. self.emitEvent = function()
  274. {
  275. for (let fun of self._var.event.notDetected)
  276. fun();
  277. if (self._options.resetOnEnd)
  278. self.clearEvent();
  279. return self;
  280. };
  281. self._creatBait = () => null;
  282. self._destroyBait = () => null;
  283. self._checkBait = function() {
  284. setTimeout((() => self.emitEvent()), 1);
  285. };
  286. self.check = function() {
  287. self._checkBait();
  288. return true;
  289. };
  290.  
  291. let callback = function()
  292. {
  293. if (self._options.checkOnLoad)
  294. setTimeout(self.check, 1);
  295. };
  296. window.addEventListener('load', callback, false);
  297. };
  298. nt.define(win, 'FuckAdBlock', FuckAdBlock);
  299. nt.define(win, 'fuckAdBlock', new FuckAdBlock({
  300. checkOnLoad: true,
  301. resetOnEnd: true
  302. }));
  303. }
  304. let hostname = location.hostname;
  305. if (hostname.startsWith('google.') || hostname.includes('.google.') ||
  306. // Google likes to define odd global variables like Ya
  307. ((hostname.startsWith('yandex.') || hostname.includes('.yandex.')) &&
  308. /^\/((yand)?search|images|video)/i.test(location.pathname) &&
  309. !hostname.startsWith('news.')) ||
  310. // Also, Yandex uses their Ya object for a lot of things on their pages and
  311. // wrapping it may cause problems. It's better to skip it in some cases.
  312. hostname.endsWith('github.io') || hostname.endsWith('grimtools.com'))
  313. return;
  314.  
  315. // Yandex API (ADBTools, Metrika)
  316. let Ya = new Proxy({}, {
  317. set: function(tgt, prop, val)
  318. {
  319. if (typeof val === 'object' && 'AdvManager' in val)
  320. val = tgt.Context;
  321. tgt[prop] = val;
  322. return tgt[prop];
  323. }
  324. });
  325. nt.define(Ya, '__isSent', true);
  326. nt.define(Ya, 'c', nt.func(null));
  327. nt.define(Ya, 'ADBTools', function(){
  328. for (let name of ['loadContext', 'testAdbStyle'])
  329. this[name] = nt.func(null);
  330. this.getCurrentState = nt.func(true);
  331. return nt.proxy(this);
  332. });
  333. if (!location.hostname.includes('kinopoisk.ru'))
  334. // kinopoisk uses adfox wrapped in Yandex code to display self-ads
  335. nt.define(Ya, 'adfoxCode', nt.proxy({
  336. create: nt.func(null),
  337. createAdaptive: nt.func(null),
  338. createScroll: nt.func(null)
  339. }));
  340. let AdvManager = function()
  341. {
  342. for (let name of ['renderDirect', 'getBid', 'releaseBid', 'getSkipToken', 'getAdSessionId'])
  343. this[name] = nt.func(null);
  344. this.render = function(o) {
  345. if (!o.renderTo)
  346. return;
  347. let placeholder = document.getElementById(o.renderTo);
  348. let parent = placeholder.parentNode;
  349. placeholder.style = 'display:none!important';
  350. parent.style = (parent.getAttribute('style')||'') + 'height:auto!important';
  351. // fix for Yandex TV pages
  352. if (location.hostname.startsWith('tv.yandex.'))
  353. {
  354. let sibling = placeholder.previousSibling;
  355. if (sibling && sibling.classList && sibling.classList.contains('tv-spin'))
  356. sibling.style.display = 'none';
  357. }
  358. };
  359. return nt.proxy(this);
  360. };
  361. nt.define(Ya, 'Context', nt.proxy({
  362. _callbacks: { push: (f) => f() },
  363. _asyncModeOn: true,
  364. _init: nt.func(null),
  365. AdvManager: new AdvManager()
  366. }));
  367. let Metrika = function()
  368. {
  369. for (let name of ['reachGoal', 'replacePhones', 'trackLinks', 'hit', 'params'])
  370. this[name] = nt.func(null);
  371. this.id = 0;
  372. return nt.proxy(this);
  373. };
  374. Metrika.counters = () => Ya._metrika.counters;
  375. nt.define(Ya, 'Metrika', Metrika);
  376. let counter = new Ya.Metrika();
  377. nt.define(Ya, '_metrika', nt.proxy({
  378. counter: counter,
  379. counters: [counter],
  380. hitParam: {},
  381. counterNum: 0,
  382. hitId: 0,
  383. v: 1
  384. }));
  385. nt.define(Ya, '_globalMetrikaHitId', 0);
  386. nt.define(win, 'Ya', Ya);
  387. // Yandex.Metrika callbacks
  388. let yandex_metrika_callbacks = [];
  389. document.addEventListener(
  390. 'DOMContentLoaded',
  391. (e) => {
  392. yandex_metrika_callbacks.forEach((f) => f && f.call(window));
  393. yandex_metrika_callbacks.length = 0;
  394. yandex_metrika_callbacks.push = (f) => setTimeout(f, 0);
  395. },
  396. false
  397. );
  398. nt.define(win, 'yandex_metrika_callbacks', yandex_metrika_callbacks);
  399. }, nullTools
  400. );
  401.  
  402. // Creates and return protected style (unless protection is manually disabled).
  403. // Protected style will re-add itself on removal and remaind enabled on attempt to disable it.
  404. function createStyle(rules, props, skip_protect)
  405. {
  406. props = props || {};
  407. props.type = 'text/css';
  408.  
  409. function _protect(style)
  410. {
  411. if (skip_protect)
  412. return;
  413.  
  414. Object.defineProperty(style, 'sheet', {
  415. value: null,
  416. enumerable: true
  417. });
  418. Object.defineProperty(style, 'disabled', {
  419. get: () => true, //pretend to be disabled
  420. set: () => null,
  421. enumerable: true
  422. });
  423. (new MutationObserver(
  424. (ms) => _removeChild(ms[0].target)
  425. )).observe(style, { childList: true });
  426. }
  427.  
  428.  
  429. function _create()
  430. {
  431. let style = _appendChild(_createElement('style'));
  432. Object.assign(style, props);
  433.  
  434. function insertRules(rule)
  435. {
  436. if (rule.forEach)
  437. rule.forEach(insertRules);
  438. else try {
  439. style.sheet.insertRule(rule, 0);
  440. } catch (e) {
  441. console.error(e);
  442. }
  443. }
  444.  
  445. insertRules(rules);
  446. _protect(style);
  447.  
  448. return style;
  449. }
  450.  
  451. let style = _create();
  452. if (skip_protect)
  453. return style;
  454.  
  455. function resolveInANewContext(resolve)
  456. {
  457. setTimeout(
  458. (resolve) => resolve(_create()),
  459. 0, resolve
  460. );
  461. }
  462.  
  463. (new MutationObserver(
  464. function(ms)
  465. {
  466. let m, node;
  467. for (m of ms) for (node of m.removedNodes)
  468. if (node === style)
  469. (new Promise(resolveInANewContext))
  470. .then((st) => (style = st));
  471. }
  472. )).observe(_de, { childList: true });
  473.  
  474. return style;
  475. }
  476.  
  477. // https://greasyfork.org/scripts/19144-websuckit/
  478. function useWSI()
  479. {
  480. // check does browser support Proxy and WebSocket
  481. if (typeof Proxy !== 'function' ||
  482. typeof WebSocket !== 'function')
  483. return;
  484.  
  485. function getWrappedCode(removeSelf)
  486. {
  487. let text = getWrappedCode.toString() + WSI.toString();
  488. text = (
  489. '(function(){"use strict";'+
  490. text.replace(/\/\/[^\r\n]*/g,'').replace(/[\s\r\n]+/g,' ')+
  491. '(new WSI(self||window)).init();'+
  492. (removeSelf?'let s = document.currentScript; if (s) {s.parentNode.removeChild(s);}':'')+
  493. '})();\n'
  494. );
  495. return text;
  496. }
  497.  
  498. function WSI(win, safeWin)
  499. {
  500. safeWin = safeWin || win;
  501. let masks = [], filter;
  502. for (filter of [// blacklist
  503. '||185.87.50.147^',
  504. '||10root25.website^', '||24video.xxx^',
  505. '||adlabs.ru^', '||adspayformymortgage.win^', '||aviabay.ru^',
  506. '||bgrndi.com^', '||brokeloy.com^',
  507. '||cnamerutor.ru^',
  508. '||docfilms.info^', '||dreadfula.ru^',
  509. '||et-code.ru^', '||etcodes.com^',
  510. '||franecki.net^', '||film-doma.ru^',
  511. '||free-torrent.org^', '||free-torrent.pw^',
  512. '||free-torrents.org^', '||free-torrents.pw^',
  513. '||game-torrent.info^', '||gocdn.ru^',
  514. '||hdkinoshka.com^', '||hghit.com^', '||hindcine.net^',
  515. '||kiev.ua^', '||kinotochka.net^',
  516. '||kinott.com^', '||kinott.ru^', '||kuveres.com^',
  517. '||lepubs.com^', '||luxadv.com^', '||luxup.ru^', '||luxupcdna.com^',
  518. '||mail.ru^', '||marketgid.com^', '||mixadvert.com^', '||mxtads.com^',
  519. '||nickhel.com^',
  520. '||oconner.biz^', '||oconner.link^', '||octoclick.net^', '||octozoon.org^',
  521. '||pkpojhc.com^',
  522. '||psma01.com^', '||psma02.com^', '||psma03.com^',
  523. '||recreativ.ru^', '||redtram.com^', '||regpole.com^', '||rootmedia.ws^', '||ruttwind.com^',
  524. '||skidl.ru^',
  525. '||torvind.com^', '||traffic-media.co^', '||trafmag.com^',
  526. '||webadvert-gid.ru^', '||webadvertgid.ru^',
  527. '||xxuhter.ru^',
  528. '||yuiout.online^',
  529. '||zoom-film.ru^'])
  530. masks.push(new RegExp(
  531. filter.replace(/([\\\/\[\].*+?(){}$])/g, '\\$1')
  532. .replace(/\^(?!$)/g,'\\.?[^\\w%._-]')
  533. .replace(/\^$/,'\\.?([^\\w%._-]|$)')
  534. .replace(/^\|\|/,'^(ws|http)s?:\\/+([^\/.]+\\.)*'),
  535. 'i'));
  536.  
  537. function isBlocked(url) {
  538. for (let mask of masks)
  539. if (mask.test(url))
  540. return true;
  541. return false;
  542. }
  543.  
  544. function wrapWebSocket(wsParent)
  545. {
  546. let _WebSocket = wsParent.WebSocket;
  547. // getter for properties of fake WS, returns fake functions
  548. // if there are functions with such name in the real WS and
  549. // also returns constants from real WS
  550. function wsGetter(target, name)
  551. {
  552. try {
  553. if (typeof _WebSocket.prototype[name] === 'function')
  554. {
  555. if (name === 'close' || name === 'send') // send also closes connection
  556. target.readyState = _WebSocket.CLOSED;
  557. return (
  558. function fake() {
  559. console.log('[WSI] Invoked function "'+name+'"', '| Tracing', (new Error()));
  560. return;
  561. }
  562. );
  563. }
  564. if (typeof _WebSocket.prototype[name] === 'number')
  565. return _WebSocket[name];
  566. } catch(ignore) {}
  567. return target[name];
  568. }
  569. // Wrap WS object
  570. wsParent.WebSocket = new Proxy(_WebSocket, {
  571. construct: function (target, args)
  572. {
  573. let url = args[0];
  574. console.log('[WSI] Opening socket on ' + url + ' \u2026');
  575. if (isBlocked(url))
  576. {
  577. console.log("[WSI] Blocked.");
  578. return new Proxy({
  579. url: url,
  580. readyState: _WebSocket.OPEN
  581. }, {
  582. get: wsGetter,
  583. set: (val) => val
  584. });
  585. }
  586. return Reflect.construct(target, args);
  587. }
  588. });
  589. }
  590.  
  591. function WorkerWrapper()
  592. {
  593. let realWorker = win.Worker;
  594. win.Worker = function Worker() {
  595. let isBlobURL = /^blob:/i,
  596. resourceURI = arguments[0],
  597. deepLogMode = false,
  598. _callbacks = new WeakMap(),
  599. _worker = null,
  600. _onevs = { names: ['onmessage', 'onerror'] },
  601. _actions = [],
  602. _self = this;
  603.  
  604. function log()
  605. {
  606. if (deepLogMode)
  607. console.log.apply(_self, arguments);
  608. }
  609.  
  610. function callbackWrapper(func)
  611. {
  612. if (typeof func !== 'function')
  613. return undefined;
  614.  
  615. return function callback()
  616. {
  617. return func.apply(_self, arguments);
  618. };
  619. }
  620.  
  621. function updateWorker()
  622. {
  623. for (let [action, name, args] of _actions) {
  624. log(_worker, action, name, args);
  625. if (action === 'set')
  626. _worker[name] = callbackWrapper(args);
  627. if (action === 'call')
  628. _worker[name].apply(_worker, args);
  629. }
  630. _actions.length = 0;
  631. log('Applied buffered actions.');
  632. }
  633.  
  634. for (let prop of _onevs.names)
  635. Object.defineProperty(_self, prop, {
  636. set: function(val) {
  637. _onevs[prop] = val;
  638. if (_worker)
  639. _worker[prop] = callbackWrapper(val);
  640. else {
  641. _actions.push(['set', prop, val]);
  642. log('Stored into buffer:', arguments);
  643. }
  644. return val;
  645. },
  646. get: () => _onevs[prop],
  647. enumerable: true
  648. });
  649.  
  650. _self.postMessage = function()
  651. {
  652. if (_worker)
  653. _worker.postMessage.apply(_worker, arguments);
  654. else {
  655. _actions.push(['call', 'postMessage', arguments]);
  656. log('Stored into buffer:', arguments);
  657. }
  658. };
  659. _self.terminate = function()
  660. {
  661. if (_worker)
  662. _worker.terminate();
  663. else {
  664. _actions.push(['call','terminate', arguments]);
  665. log('Stored into buffer:', arguments);
  666. }
  667. };
  668. _self.addEventListener = function(event, callback, other)
  669. {
  670. if (typeof callback !== 'function')
  671. return;
  672.  
  673. if (!_callbacks.has(callback))
  674. _callbacks.set(callback, callbackWrapper(callback));
  675.  
  676. arguments[1] = _callbacks.get(callback);
  677. if (_worker)
  678. _worker.addEventListener.apply(_worker, arguments);
  679. else {
  680. _actions.push(['call', 'addEventListener', arguments]);
  681. log('Stored into buffer:', arguments);
  682. }
  683. };
  684. _self.removeEventListener = function(event, callback, other)
  685. {
  686. if (typeof callback !== 'function' || !_callbacks.has(callback))
  687. return;
  688.  
  689. arguments[1] = _callbacks.get(callback);
  690. _callbacks.delete(callback);
  691. if (_worker)
  692. _worker.removeEventListener.apply(_worker, arguments);
  693. else {
  694. _actions.push(['call', 'removeEventListener', arguments]);
  695. log('Stored into buffer:', arguments);
  696. }
  697. };
  698.  
  699. if (!isBlobURL.test(resourceURI))
  700. {
  701. _worker = new realWorker(resourceURI);
  702. return; // not a blob, no need to wrap
  703. }
  704.  
  705. (new Promise(
  706. function(resolve, reject)
  707. {
  708. let xhr = new XMLHttpRequest();
  709. xhr.responseType = 'blob';
  710. try {
  711. xhr.open('GET', resourceURI, true);
  712. } catch(e) {
  713. return reject(e);
  714. }
  715. if (xhr.readyState !== XMLHttpRequest.OPENED) {
  716. // connection wasn't opened, unable to continue wrapping procedure
  717. return reject(xhr.readyState);
  718. }
  719. xhr.onload = function(e)
  720. {
  721. if (e.target.status === 200)
  722. {
  723. let reader = new FileReader();
  724. reader.addEventListener(
  725. 'loadend', function(e)
  726. {
  727. resolve(
  728. new realWorker(URL.createObjectURL(
  729. new Blob([getWrappedCode(false) + e.target.result])
  730. ))
  731. );
  732. }, false
  733. );
  734. reader.readAsText(e.target.response);
  735. } else {
  736. return reject(e);
  737. }
  738. };
  739. xhr.onerror = (e) => reject(e);
  740. xhr.send();
  741. }
  742. )).then(
  743. function(val)
  744. {
  745. _worker = val;
  746. updateWorker();
  747. }
  748. ).catch(
  749. function(e)
  750. {
  751. // connection were blocked by CSP or something else triggered error event on xhr object
  752. // unable to proceed with wrapper, return object as-is
  753. _worker = new realWorker(resourceURI);
  754. updateWorker();
  755. }
  756. );
  757.  
  758. if (deepLogMode)
  759. {
  760. return new Proxy(_self, {
  761. get: function(target, prop) {
  762. console.log('Worker _get_', prop);
  763. return target[prop];
  764. },
  765. set: function(target, prop, val) {
  766. console.log('Worker _set_', prop, '_to_', val);
  767. target[prop] = val;
  768. return val;
  769. }
  770. });
  771. }
  772. }.bind(safeWin);
  773. }
  774.  
  775. function CreateElementWrapper()
  776. {
  777. let key = '_'+Math.random().toString(36).substr(2),
  778. _createElement = Document.prototype.createElement,
  779. _addEventListener = Element.prototype.addEventListener,
  780. isDataURL = /^data:/i,
  781. isBlobURL = /^blob:/i;
  782.  
  783. // IFrame SRC get/set wrapper
  784. let ifGetSet = Object.getOwnPropertyDescriptor(HTMLIFrameElement.prototype, 'src');
  785. if (ifGetSet)
  786. {
  787. let code = encodeURIComponent('<scr'+'ipt>'+getWrappedCode(true)+'</scr'+'ipt>\n'),
  788. dataSrc = new WeakMap(),
  789. _ifSet = ifGetSet.set,
  790. _ifGet = ifGetSet.get;
  791. ifGetSet.set = function(val)
  792. {
  793. if (this[key] && val === dataSrc.get(this))
  794. { // if already processed data URL then do nothing
  795. delete this[key];
  796. return null;
  797. }
  798. let isData = isDataURL.test(val);
  799. if (isData && val.indexOf(code) < 0)
  800. {
  801. dataSrc.set(this, val);
  802. val = val.replace(',',',' + code);
  803. }
  804. if (!isData && dataSrc.get(this))
  805. dataSrc.delete(this);
  806. return _ifSet.call(this, val);
  807. };
  808. ifGetSet.get = function()
  809. {
  810. return dataSrc.get(this) || _ifGet.call(this);
  811. };
  812. Object.defineProperty(HTMLIFrameElement.prototype, 'src', ifGetSet);
  813. }
  814.  
  815. function frameSetWSWrapper(e)
  816. {
  817. let frm = e.target;
  818. try {
  819. if (!frm.src || isBlobURL.test(frm.src))
  820. wrapWebSocket(frm.contentWindow);
  821. } catch (ignore) {}
  822. }
  823.  
  824. let scriptMap = new WeakMap();
  825. scriptMap.isBlocked = isBlocked;
  826. let onErrorWrapper = {
  827. set: function(val)
  828. {
  829. if (scriptMap.has(this))
  830. {
  831. this.removeEventListener('error', scriptMap.get(this).wrp, false);
  832. scriptMap.delete(this);
  833. }
  834. if (!val || typeof val !== 'function')
  835. return val;
  836.  
  837. scriptMap.set(this, {
  838. org: val,
  839. wrp: function()
  840. {
  841. if (scriptMap.isBlocked(this.src))
  842. console.log('[WSI] Blocked "onerror" callback from', this);
  843. else
  844. scriptMap.get(this).org.apply(this, arguments);
  845. }
  846. });
  847. this.addEventListener('error', scriptMap.get(this).wrp, false);
  848.  
  849. return val;
  850. },
  851. get: function()
  852. {
  853. return scriptMap.has(this) ? scriptMap.get(this).org : null;
  854. },
  855. enumerable: true
  856. };
  857. Document.prototype.createElement = function createElement(name) {
  858. let el = _createElement.apply(this, arguments);
  859.  
  860. if (el.tagName === 'IFRAME')
  861. _addEventListener.call(el, 'load', frameSetWSWrapper, false);
  862. if (el.tagName === 'SCRIPT')
  863. Object.defineProperty(el, 'onerror', onErrorWrapper);
  864.  
  865. return el;
  866. };
  867.  
  868. document.addEventListener(
  869. 'DOMContentLoaded', function()
  870. {
  871. for (let ifr of document.querySelectorAll('IFRAME'))
  872. {
  873. if (isDataURL.test(ifr.src))
  874. {
  875. ifr[key] = true;
  876. ifr.src = ifr.src; // call setter and let it do the job
  877. }
  878. _addEventListener.call(ifr, 'load', frameSetWSWrapper, false);
  879. }
  880. }, false
  881. );
  882. }
  883.  
  884. this.init = function()
  885. {
  886. wrapWebSocket(win);
  887. if (!(/firefox/i.test(navigator.userAgent))) // skip WorkerWrapper in Firefox
  888. (new Promise(
  889. function(resolve, reject)
  890. { // test is it possible to run inline scripts
  891. if (self.constructor.name.indexOf('Worker') > -1)
  892. return resolve(); // running within a Worker
  893. let onerr = window.onerror,
  894. onscr = (e) => resolve();
  895. // for some reason addEventListener on 'error' doesn't catch this error
  896. window.onerror = (e) => reject(e);
  897. window.addEventListener('inlineSuccess', onscr, false);
  898. let scr = document.createElement('script');
  899. scr.textContent = "window.dispatchEvent(new Event('inlineSuccess'));";
  900. document.documentElement.appendChild(scr);
  901. document.documentElement.removeChild(scr);
  902. window.removeEventListener('inlineSuccess', onscr, false);
  903. window.onerror = onerr;
  904. }
  905. )).then(
  906. (e) => WorkerWrapper()
  907. ).catch(
  908. (e) => console.log('[WSI] Unable to create inline script. Skipping Worker wrapper to avoid further issues.', e)
  909. );
  910. if (typeof document !== 'undefined')
  911. CreateElementWrapper();
  912. };
  913. }
  914.  
  915. if (isFirefox)
  916. {
  917. let script = _createElement('script');
  918. script.textContent = getWrappedCode(true);
  919. _appendChild(script);
  920. _removeChild(script);
  921. return; //we don't want to call functions on page from here in Fx, so exit
  922. }
  923.  
  924. (new WSI((unsafeWindow||self||window),(self||window))).init();
  925. }
  926.  
  927. if (!isFirefox)
  928. { // scripts for non-Firefox browsers
  929. // https://greasyfork.org/scripts/14720-it-s-not-important
  930. {
  931. let imptt = /((display|(margin|padding)(-top|-bottom)?)\s*:[^;!]*)!\s*important/ig,
  932. ret_b = (a,b) => b,
  933. _toLowerCase = String.prototype.toLowerCase,
  934. protectedNodes = new WeakSet(),
  935. log = false;
  936.  
  937. let logger = function()
  938. {
  939. if (log)
  940. console.log('Some page elements became a bit less important.');
  941. log = false;
  942. };
  943.  
  944. let unimportanter = function(node)
  945. {
  946. let style = (node.nodeType === Node.ELEMENT_NODE) ?
  947. _getAttribute.call(node, 'style') : null;
  948.  
  949. if (!style || !imptt.test(style) || node.style.display === 'none' ||
  950. (node.src && node.src.slice(0,17) === 'chrome-extension:')) // Web of Trust IFRAME and similar
  951. return false; // get out if we have nothing to do here
  952.  
  953. protectedNodes.add(node);
  954. _setAttribute.call(node, 'style',
  955. style.replace(imptt, ret_b));
  956. log = true;
  957. };
  958.  
  959. (new MutationObserver(
  960. function(mutations)
  961. {
  962. setTimeout(
  963. function(ms)
  964. {
  965. let m, node;
  966. for (m of ms) for (node of m.addedNodes)
  967. unimportanter(node);
  968. logger();
  969. }, 0, mutations
  970. );
  971. }
  972. )).observe(document, {
  973. childList : true,
  974. subtree : true
  975. });
  976.  
  977. Element.prototype.setAttribute = function setAttribute(name, value)
  978. {
  979. "[native code]";
  980. let replaced = value;
  981. if (_toLowerCase.call(name) === 'style' && protectedNodes.has(this))
  982. replaced = value.replace(imptt, ret_b);
  983. log = (replaced !== value);
  984. logger();
  985. return _setAttribute.call(this, name, replaced);
  986. };
  987.  
  988. win.addEventListener (
  989. 'load', function()
  990. {
  991. for (let imp of document.querySelectorAll('[style*="!"]'))
  992. unimportanter(imp);
  993. logger();
  994. }, false
  995. );
  996. }
  997.  
  998. // Naive ABP Style protector
  999. {
  1000. let _querySelector = Document.prototype.querySelector.bind(document);
  1001. let _removeChild = Node.prototype.removeChild;
  1002. let _appendChild = Node.prototype.appendChild;
  1003. let createShadow = () => _createElement('shadow');
  1004. // Prevent adding fake content entry point
  1005. Node.prototype.appendChild = function(child)
  1006. {
  1007. if (this instanceof ShadowRoot &&
  1008. child instanceof HTMLContentElement)
  1009. return _appendChild.call(this, createShadow());
  1010. return _appendChild.apply(this, arguments);
  1011. };
  1012. {
  1013. let _shadowSelector = ShadowRoot.prototype.querySelector;
  1014. let _innerHTML = Object.getOwnPropertyDescriptor(ShadowRoot.prototype, 'innerHTML');
  1015. let _parentNode = Object.getOwnPropertyDescriptor(Node.prototype, 'parentNode');
  1016. if (_innerHTML && _parentNode)
  1017. {
  1018. let _set = _innerHTML.set;
  1019. let _getParent = _parentNode.get;
  1020. _innerHTML.configurable = false;
  1021. _innerHTML.set = function()
  1022. {
  1023. _set.apply(this, arguments);
  1024. let content = _shadowSelector.call(this, 'content');
  1025. if (content)
  1026. {
  1027. let parent = _getParent.call(content);
  1028. _removeChild.call(parent, content);
  1029. _appendChild.call(parent, createShadow());
  1030. }
  1031. };
  1032. }
  1033. Object.defineProperty(ShadowRoot.prototype, 'innerHTML', _innerHTML);
  1034. }
  1035. // Locate and apply extra protection to a style on top of what ABP does
  1036. let style;
  1037. (new Promise(
  1038. function(resolve, reject)
  1039. {
  1040. let getStyle = () => _querySelector('::shadow style');
  1041. style = getStyle();
  1042. if (style)
  1043. return resolve(style);
  1044. let intv = setInterval(
  1045. function()
  1046. {
  1047. style = getStyle();
  1048. if (!style)
  1049. return;
  1050. intv = clearInterval(intv);
  1051. return resolve(style);
  1052. }, 0
  1053. );
  1054. document.addEventListener(
  1055. 'DOMContentLoaded',
  1056. function()
  1057. {
  1058. if (intv)
  1059. clearInterval(intv);
  1060. style = getStyle();
  1061. return style ? resolve(style) : reject();
  1062. },
  1063. false
  1064. );
  1065. }
  1066. )).then(
  1067. function(style)
  1068. {
  1069. let emptyArr = [],
  1070. nullStr = {
  1071. get: () => '',
  1072. set: (x) => x
  1073. };
  1074. Object.defineProperties(style, {
  1075. innerHTML: nullStr,
  1076. textContent: nullStr
  1077. });
  1078. Object.defineProperties(style.sheet, {
  1079. deleteRule: () => null,
  1080. cssRules: emptyArr,
  1081. rules: emptyArr
  1082. });
  1083. }
  1084. ).catch(()=>null);
  1085. Node.prototype.removeChild = function(child)
  1086. {
  1087. if (child === style)
  1088. return;
  1089. return _removeChild.apply(this, arguments);
  1090. };
  1091. }
  1092. }
  1093. if (/^https?:\/\/(mail\.yandex\.|music\.yandex\.|news\.yandex\.|(www\.)?yandex\.[^\/]+\/(yand)?search[\/?])/i.test(win.location.href) ||
  1094. /^https?:\/\/tv\.yandex\./i.test(win.location.href))
  1095. {
  1096. // https://greasyfork.org/en/scripts/809-no-yandex-ads
  1097. let _querySelector = document.querySelector.bind(document),
  1098. _querySelectorAll = document.querySelectorAll.bind(document),
  1099. _getAttribute = Element.prototype.getAttribute,
  1100. _setAttribute = Element.prototype.setAttribute;
  1101. document.addEventListener(
  1102. 'DOMContentLoaded', function()
  1103. {
  1104. let adWords = [/Яндекс.Директ/i, /Реклама/i, /Ad/i],
  1105. genericAdSelectors = (
  1106. '.serp-adv__head + .serp-item,'+
  1107. '#adbanner,'+
  1108. '.serp-adv,'+
  1109. '.b-spec-adv,'+
  1110. 'div[class*="serp-adv__"]:not(.serp-adv__found):not(.serp-adv__displayed)'
  1111. );
  1112. // Generic ads removal and fixes
  1113. {
  1114. let node = _querySelector('.serp-header');
  1115. if (node)
  1116. node.style.marginTop = '0';
  1117. for (node of _querySelectorAll(genericAdSelectors))
  1118. remove(node);
  1119. }
  1120. // Short name for parentNode.removeChild
  1121. function remove(node) {
  1122. if (!node || !node.parentNode)
  1123. return false;
  1124. console.log('Removed node.');
  1125. node.parentNode.removeChild(node);
  1126. }
  1127. // Short name to hide node with style attribute
  1128. let hiddenNodes = new WeakSet();
  1129. function hide(node) {
  1130. if (hiddenNodes.has(node))
  1131. return false;
  1132. _setAttribute.call(node, 'style', 'display: none !important');
  1133. hiddenNodes.add(node);
  1134. console.log('Hid node.');
  1135. return true;
  1136. }
  1137. // Search ads
  1138. function removeSearchAds()
  1139. {
  1140. let res = false;
  1141. // hide unparsed Yandex ads if present
  1142. for (let node of _querySelectorAll('.serp-item[role="complementary"]'))
  1143. res = res|hide(node);
  1144. if (res) return 'Unparsed Yandex ads were hidden.';
  1145. // build list of ids related to natural results
  1146. let ids = [];
  1147. for (let style of _querySelectorAll('style[data-as^="serp-label"]'))
  1148. ids.push(style.textContent.replace(/\{.*\}/,'').trim());
  1149. // hide result nodes which doesn't contains any ids from the list (ads)
  1150. let nodes = _querySelectorAll('.serp-item[data-cid] > .organic');
  1151. if (ids.length > 0)
  1152. {
  1153. for (let node of nodes)
  1154. if (!node.querySelector(ids.join(',')))
  1155. res = res|hide(node.parentNode);
  1156. } else {
  1157. for (let node of nodes)
  1158. {
  1159. let label = (node.querySelector('.label')||{}).textContent;
  1160. if (adWords[1].test(label) || adWords[2].test(label))
  1161. res = res|hide(node.parentNode);
  1162. }
  1163. }
  1164. if (res)
  1165. return 'Parsed Yandex ads were hidden.';
  1166. else
  1167. return 'No ads were detected.';
  1168. }
  1169. function removeSearchAdsLog()
  1170. {
  1171. let res = removeSearchAds();
  1172. if (res) console.log(res);
  1173. }
  1174. // News ads
  1175. function removeNewsAds()
  1176. {
  1177. let node, block, item, items, mask, classes,
  1178. masks = [
  1179. { class: '.ads__wrapper', regex: /[^,]*?,[^,]*?\.ads__wrapper/ },
  1180. { class: '.ads__pool', regex: /[^,]*?,[^,]*?\.ads__pool/ }
  1181. ];
  1182. for (node of _querySelectorAll('style[nonce]'))
  1183. {
  1184. classes = node.innerText.replace(/\{[^}]+\}+/ig, '|').split('|');
  1185. for (block of classes) for (mask of masks)
  1186. if (block.includes(mask.class))
  1187. {
  1188. block = block.match(mask.regex)[0];
  1189. items = _querySelectorAll(block);
  1190. for (item of items)
  1191. remove(items[0]);
  1192. }
  1193. }
  1194. }
  1195. // Music ads
  1196. function removeMusicAds()
  1197. {
  1198. for (let node of _querySelectorAll('.ads-block'))
  1199. remove(node);
  1200. }
  1201. // Mail ads
  1202. function removeMailAds()
  1203. {
  1204. let slice = Array.prototype.slice,
  1205. nodes = slice.call(_querySelectorAll('.ns-view-folders')),
  1206. node, len, cls;
  1207.  
  1208. for (node of nodes)
  1209. if (!len || len > node.classList.length)
  1210. len = node.classList.length;
  1211.  
  1212. node = nodes.pop();
  1213. while (node)
  1214. {
  1215. if (node.classList.length > len)
  1216. for (cls of slice.call(node.classList))
  1217. if (cls.indexOf('-') === -1)
  1218. {
  1219. remove(node);
  1220. break;
  1221. }
  1222. node = nodes.pop();
  1223. }
  1224. }
  1225. // News fixes
  1226. function removePageAdsClass()
  1227. {
  1228. if (document.body.classList.contains("b-page_ads_yes"))
  1229. {
  1230. document.body.classList.remove("b-page_ads_yes");
  1231. console.log('Page ads class removed.');
  1232. }
  1233. }
  1234. // TV fixes
  1235. function removeTVAds()
  1236. {
  1237. for (let node of _querySelectorAll('div[class^="_"][data-reactid] > div'))
  1238. if (adWords[0].test(node.textContent) || node.querySelector('iframe:not([src])'))
  1239. {
  1240. if (node.offsetWidth)
  1241. {
  1242. let pad = document.createElement('div');
  1243. _setAttribute.call(pad, 'style', 'width:'+node.offsetWidth+'px');
  1244. node.parentNode.appendChild(pad);
  1245. }
  1246. remove(node);
  1247. }
  1248. }
  1249. // Function to attach an observer to monitor dynamic changes on the page
  1250. function pageUpdateObserver(func, obj, params) {
  1251. if (obj)
  1252. (new MutationObserver(func))
  1253. .observe(obj, (params || { childList:true, subtree:true }));
  1254. }
  1255.  
  1256. if (location.hostname.startsWith('mail.')) {
  1257. pageUpdateObserver(
  1258. function(ms, o)
  1259. {
  1260. let aside = _querySelector('.mail-Layout-Aside');
  1261. if (aside) {
  1262. o.disconnect();
  1263. pageUpdateObserver(removeMailAds, aside);
  1264. }
  1265. }, document.body
  1266. );
  1267. removeMailAds();
  1268. } else if (location.hostname.startsWith('music.')) {
  1269. pageUpdateObserver(removeMusicAds, _querySelector('.sidebar'));
  1270. removeMusicAds();
  1271. } else if (location.hostname.startsWith('news.')) {
  1272. pageUpdateObserver(removeNewsAds, document.body);
  1273. pageUpdateObserver(removePageAdsClass, document.body, { attributes:true, attributesFilter:['class'] });
  1274. removeNewsAds();
  1275. removePageAdsClass();
  1276. } else if (location.hostname.startsWith('tv.')) {
  1277. pageUpdateObserver(removeTVAds, document.body);
  1278. removeTVAds();
  1279. } else {
  1280. pageUpdateObserver(removeSearchAdsLog, _querySelector('.main__content'));
  1281. removeSearchAdsLog();
  1282. }
  1283. }
  1284. );
  1285. }
  1286.  
  1287. // Yandex Link Tracking
  1288. if (/^https?:\/\/([^.]+\.)*yandex\.[^\/]+/i.test(win.location.href))
  1289. {
  1290. let fakeRoot = {
  1291. firstChild: null,
  1292. appendChild: ()=>null,
  1293. querySelector: ()=>null,
  1294. querySelectorAll: ()=>null
  1295. };
  1296. Element.prototype.createShadowRoot = () => fakeRoot;
  1297. Object.defineProperty(Element.prototype, "shadowRoot", {
  1298. value: fakeRoot,
  1299. enumerable: true,
  1300. configurable: false
  1301. });
  1302. // Partially based on https://greasyfork.org/en/scripts/22737-remove-yandex-redirect
  1303. let selectors = (
  1304. 'A[onmousedown*="/jsredir"],'+
  1305. 'A[data-vdir-href],'+
  1306. 'A[data-counter]'
  1307. );
  1308. let removeTrackingAttributes = function(link)
  1309. {
  1310. link.removeAttribute('onmousedown');
  1311. if (link.hasAttribute('data-vdir-href')) {
  1312. link.removeAttribute('data-vdir-href');
  1313. link.removeAttribute('data-orig-href');
  1314. }
  1315. if (link.hasAttribute('data-counter')) {
  1316. link.removeAttribute('data-counter');
  1317. link.removeAttribute('data-bem');
  1318. }
  1319. };
  1320. let removeTracking = function(scope)
  1321. {
  1322. for (let link of scope.querySelectorAll(selectors))
  1323. removeTrackingAttributes(link);
  1324. };
  1325. document.addEventListener('DOMContentLoaded', (e) => removeTracking(e.target));
  1326. (new MutationObserver(
  1327. function(ms)
  1328. {
  1329. let m, node;
  1330. for (m of ms) for (node of m.addedNodes) if (node.nodeType === Node.ELEMENT_NODE)
  1331. if (node.tagName === 'A' && node.matches(selectors)) {
  1332. removeTrackingAttributes(node);
  1333. } else {
  1334. removeTracking(node);
  1335. }
  1336. }
  1337. )).observe(_de, { childList: true, subtree: true });
  1338.  
  1339. //skip fixes for other sites
  1340. return;
  1341. }
  1342.  
  1343. // https://greasyfork.org/en/scripts/21937-moonwalk-hdgo-kodik-fix v0.8 (adapted)
  1344. document.addEventListener(
  1345. 'DOMContentLoaded', function()
  1346. {//createPlayer();
  1347. function log (e) {
  1348. console.log('Player FIX: Detected', e, 'player in', win.location.href);
  1349. }
  1350. if (win.adv_enabled !== undefined && win.condition_detected !== undefined)
  1351. {
  1352. log('Moonwalk');
  1353. if (win.adv_enabled)
  1354. win.adv_enabled = false;
  1355. win.condition_detected = false;
  1356. if (win.MXoverrollCallback)
  1357. document.addEventListener(
  1358. 'click', function catcher(e)
  1359. {
  1360. e.stopPropagation();
  1361. win.MXoverrollCallback.call(window);
  1362. document.removeEventListener('click', catcher, true);
  1363. }, true
  1364. );
  1365. }
  1366. else if (win.stat_url !== undefined && win.is_html5 !== undefined && win.is_wp8 !== undefined)
  1367. {
  1368. log('HDGo');
  1369. document.body.onclick = null;
  1370. let tmp = document.querySelector('#swtf');
  1371. if (tmp)
  1372. tmp.style.display = 'none';
  1373. if (win.banner_second !== undefined)
  1374. win.banner_second = 0;
  1375. if (win.$banner_ads !== undefined)
  1376. win.$banner_ads = false;
  1377. if (win.$new_ads !== undefined)
  1378. win.$new_ads = false;
  1379. if (win.createCookie !== undefined)
  1380. win.createCookie('popup', 'true', '999');
  1381. if (win.canRunAds !== undefined && win.canRunAds !== true)
  1382. win.canRunAds = true;
  1383. }
  1384. else if (win.MXoverrollCallback && win.iframeSearch !== undefined)
  1385. {
  1386. log('Kodik');
  1387. let tmp = document.querySelector('.play_button');
  1388. if (tmp)
  1389. tmp.onclick = win.MXoverrollCallback.bind(window);
  1390. win.IsAdBlock = false;
  1391. }
  1392. else if (win.getnextepisode && win.uppodEvent)
  1393. {
  1394. log('Share-Serials.net');
  1395. scriptLander(
  1396. function()
  1397. {
  1398. let _setInterval = win.setInterval,
  1399. _setTimeout = win.setTimeout;
  1400. win.setInterval = function(func)
  1401. {
  1402. if (func instanceof Function && func.toString().indexOf('_delay') > -1)
  1403. {
  1404. let intv = _setInterval.call(
  1405. this, function()
  1406. {
  1407. _setTimeout.call(
  1408. this, function(intv)
  1409. {
  1410. clearInterval(intv);
  1411. let timer = document.querySelector('#timer');
  1412. if (timer)
  1413. timer.click();
  1414. }, 100, intv);
  1415. func.call(this);
  1416. }, 5
  1417. );
  1418.  
  1419. return intv;
  1420. }
  1421. return _setInterval.apply(this, arguments);
  1422. };
  1423. win.setTimeout = function(func) {
  1424. if (func instanceof Function && func.toString().indexOf('adv_showed') > -1)
  1425. {
  1426. return _setTimeout.call(this, func, 0);
  1427. }
  1428. return _setTimeout.apply(this, arguments);
  1429. };
  1430. }
  1431. );
  1432. }
  1433. }, false
  1434. );
  1435.  
  1436. // piguiqproxy.com circumvention prevention
  1437. scriptLander(
  1438. function()
  1439. {
  1440. let _open = XMLHttpRequest.prototype.open;
  1441. let blacklist = /[/.@](piguiqproxy\.com|rcdn\.pro)[:/]/i;
  1442. XMLHttpRequest.prototype.open = function(method, url)
  1443. {
  1444. if (method === 'GET' && blacklist.test(url))
  1445. {
  1446. this.send = () => null;
  1447. this.setRequestHeader = () => null;
  1448. console.log('Blocked request: ', url);
  1449. return;
  1450. }
  1451. return _open.apply(this, arguments);
  1452. };
  1453. }
  1454. );
  1455.  
  1456. // === Helper functions ===
  1457.  
  1458. // function to search and remove nodes by content
  1459. // selector - standard CSS selector to define set of nodes to check
  1460. // words - regular expression to check content of the suspicious nodes
  1461. // params - object with multiple extra parameters:
  1462. // .log - display log in the console
  1463. // .hide - set display to none instead of removing from the page
  1464. // .parent - parent node to remove if content is found in the child node
  1465. // .siblings - number of simling nodes to remove (excluding text nodes)
  1466. let scRemove = (node) => node.parentNode.removeChild(node);
  1467. let scHide = function(node)
  1468. {
  1469. let style = _getAttribute.call(node, 'style') || '',
  1470. hide = ';display:none!important;';
  1471. if (style.indexOf(hide) < 0)
  1472. _setAttribute.call(node, 'style', style + hide);
  1473. };
  1474. function scissors (selector, words, scope, params)
  1475. {
  1476. if (params.log)
  1477. console.log('[s] starting with', selector, words, scope, JSON.stringify(params));
  1478. let remFunc = (params.hide ? scHide : scRemove),
  1479. iterFunc = (params.siblings > 0 ? 'nextSibling' : 'previousSibling'),
  1480. toRemove = [],
  1481. siblings;
  1482. for (let node of scope.querySelectorAll(selector))
  1483. {
  1484. if (params.log)
  1485. console.log('[s] found node', node);
  1486. if (params.parent)
  1487. {
  1488. while(node !== scope && !(node.matches(params.parent)))
  1489. node = node.parentNode;
  1490. if (params.log)
  1491. console.log('[s] moving to parent node', node);
  1492. if (node === scope)
  1493. {
  1494. if (params.log)
  1495. console.log('[s] reached scope node, nothing to remove here.');
  1496. break;
  1497. }
  1498. }
  1499. if (words.test(node.innerHTML) || !node.childNodes.length)
  1500. {
  1501. // drill up to the specified parent node if required
  1502. if (toRemove.indexOf(node) === -1)
  1503. {
  1504. if (params.log)
  1505. console.log('[s] adding node into list for removal');
  1506. toRemove.push(node);
  1507. // add multiple nodes if defined more than one sibling
  1508. siblings = Math.abs(params.siblings) || 0;
  1509. while (siblings)
  1510. {
  1511. node = node[iterFunc];
  1512. if (node.nodeType === Node.ELEMENT_NODE)
  1513. {
  1514. if (params.log)
  1515. console.log('[s] adding sibling node', node);
  1516. toRemove.push(node);
  1517. siblings -= 1; //count only element nodes
  1518. }
  1519. else if (!params.hide)
  1520. {
  1521. if (params.log)
  1522. console.log('[s] adding sibling node', node);
  1523. toRemove.push(node);
  1524. }
  1525. }
  1526. } else {
  1527. if (params.log)
  1528. console.log('[s] node already marked for removal');
  1529. }
  1530. } else {
  1531. if (params.log)
  1532. console.log('[s] word test failed, proceed to the next node');
  1533. }
  1534. }
  1535. if (params.log)
  1536. console.log('[s] proceeding with', (params.hide?'hide':'removal'), 'of', toRemove);
  1537. for (let node of toRemove)
  1538. remFunc(node);
  1539.  
  1540. return toRemove.length;
  1541. }
  1542.  
  1543. // function to perform multiple checks if ads inserted with a delay
  1544. // by default does 30 checks withing a 3 seconds unless nonstop mode specified
  1545. // also does 1 extra check when a page completely loads
  1546. // selector and words - passed dow to scissors
  1547. // params - object with multiple extra parameters:
  1548. // .log - display log in the console
  1549. // .root - selector to narrow down scope to scan;
  1550. // .observe - if true then check will be performed continuously;
  1551. // Other parameters passed down to scissors.
  1552. function gardener(selector, words, params)
  1553. {
  1554. params = params || {};
  1555. if (params.log)
  1556. console.log('[g] starting with', selector, words, JSON.stringify(params));
  1557. let scope = [document];
  1558. function onevent(e)
  1559. {
  1560. for (let node of scope)
  1561. scissors(selector, words, node, params);
  1562. if (params.log)
  1563. console.log('[g] cleanup on', e.constructor.name.replace('Object', 'event'), e.type);
  1564. }
  1565. document.addEventListener(
  1566. 'DOMContentLoaded', (e) => {
  1567. // narrow down scope to a specific element
  1568. if (params.root)
  1569. {
  1570. scope = document.querySelectorAll(params.root);
  1571. if (!scope) // exit if the root element is not present on the page
  1572. return 0;
  1573. if (params.log)
  1574. console.log('[g] scope', scope);
  1575. }
  1576. // add observe mode if required
  1577. if (params.observe)
  1578. {
  1579. let params = { childList:true, subtree: true };
  1580. let observer = new MutationObserver(
  1581. function(ms)
  1582. {
  1583. for (let m of ms)
  1584. if (m.addedNodes.length)
  1585. onevent(m);
  1586. }
  1587. );
  1588. for (let node of scope)
  1589. observer.observe(node, params);
  1590. if (params.log)
  1591. console.log('[g] observer enabled');
  1592. }
  1593. onevent(e);
  1594. }, false);
  1595. // wait for a full page load to do one extra cut
  1596. win.addEventListener('load', onevent, false);
  1597. }
  1598.  
  1599. // wrap popular methods to open a new tab to catch specific behaviours
  1600. function createWindowOpenWrapper(openFunc, onClickFunc)
  1601. {
  1602. let _createElement = Document.prototype.createElement,
  1603. _appendChild = Element.prototype.appendChild,
  1604. fakeNative = (f) => (f.toString = () => 'function '+f.name+'() { [native code] }');
  1605.  
  1606. let nt = new nullTools();
  1607. fakeNative(openFunc);
  1608. function redefineOpen(obj)
  1609. {
  1610. nt.define(obj, 'open', openFunc);
  1611. nt.define(obj.document, 'open', openFunc);
  1612. nt.define(obj.Document.prototype, 'open', openFunc);
  1613. }
  1614. redefineOpen(win);
  1615.  
  1616. function createElement(name)
  1617. {
  1618. '[native code]';
  1619. // jshint validthis:true
  1620. let el = _createElement.apply(this, arguments);
  1621. // click-dispatch check for Google Chrome and similar browsers
  1622. if (el instanceof HTMLAnchorElement)
  1623. el.addEventListener(
  1624. 'click', onClickFunc, false
  1625. );
  1626. // redefine window.open in first-party frames
  1627. if (el instanceof HTMLIFrameElement || el instanceof HTMLObjectElement)
  1628. el.addEventListener(
  1629. 'load', function(e)
  1630. {
  1631. try {
  1632. redefineOpen(e.target.contentWindow);
  1633. } catch(ignore) {}
  1634. }, false
  1635. );
  1636. return el;
  1637. }
  1638. fakeNative(createElement);
  1639.  
  1640. function redefineCreateElement(obj)
  1641. {
  1642. nt.define(obj.document, 'createElement', createElement);
  1643. nt.define(obj.Document.prototype, 'createElement', createElement);
  1644. }
  1645. redefineCreateElement(win);
  1646.  
  1647. // wrap window.open in newly added first-party frames
  1648. Element.prototype.appendChild = function appendChild()
  1649. {
  1650. '[native code]';
  1651. let el = _appendChild.apply(this, arguments);
  1652. if (el instanceof HTMLIFrameElement) {
  1653. try {
  1654. redefineOpen(el.contentWindow);
  1655. redefineCreateElement(el.contentWindow);
  1656. } catch(ignore) {}
  1657. }
  1658. return el;
  1659. };
  1660. fakeNative(Element.prototype.appendChild);
  1661. }
  1662.  
  1663. // Function to catch and block various methods to open a new window with 3rd-party content.
  1664. // Some advertisement networks went way past simple window.open call to circumvent default popup protection.
  1665. // This funciton blocks window.open, ability to restore original window.open from an IFRAME object,
  1666. // ability to perform an untrusted (not initiated by user) click on a link, click on a link without a parent
  1667. // node or simply a link with piece of javascript code in the HREF attribute.
  1668. function preventPopups()
  1669. {
  1670. if (inIFrame)
  1671. {
  1672. win.top.postMessage({ name: 'sandbox-me', href: win.location.href }, '*');
  1673. return;
  1674. }
  1675.  
  1676. scriptLander(
  1677. function()
  1678. {
  1679. function open()
  1680. {
  1681. '[native code]';
  1682. console.log('Site attempted to open a new window', arguments);
  1683. return {
  1684. document: {
  1685. write: () => {},
  1686. writeln: () => {}
  1687. }
  1688. };
  1689. }
  1690.  
  1691. function clickHandler(e)
  1692. {
  1693. let link = e.target;
  1694. if (!link.parentNode || !e.isTrusted ||
  1695. (link.href && link.href.trim().toLowerCase().indexOf('javascript') === 0))
  1696. {
  1697. e.preventDefault();
  1698. console.log('Blocked suspicious click event', e, 'on', e.target);
  1699. }
  1700. }
  1701.  
  1702. createWindowOpenWrapper(open, clickHandler);
  1703.  
  1704. console.log('Popup prevention enabled.');
  1705. }, [nullTools, createWindowOpenWrapper]
  1706. );
  1707. }
  1708.  
  1709. // Helper function to close background tab if site opens itself in a new tab and then
  1710. // loads a 3rd-party page in the background one (thus performing background redirect).
  1711. function preventPopunders()
  1712. {
  1713. // create "close_me" event to call high-level window.close()
  1714. let eventName = 'close_me_' + Math.random().toString(36).substr(2);
  1715. let callClose = () => (console.log('close call'), window.close());
  1716. window.addEventListener(eventName, callClose, true);
  1717.  
  1718. scriptLander(
  1719. function()
  1720. {
  1721. let _open = window.open,
  1722. parseURL = document.createElement('A');
  1723. // get host of a provided URL with help of an anchor object
  1724. // unfortunately new URL(url, window.location) generates wrong URL in some cases
  1725. let getHost = (url) => (parseURL.href = url, parseURL.host);
  1726. // site went to a new tab and attempts to unload
  1727. // call for high-level close through event
  1728. let closeWindow = () => window.dispatchEvent(new CustomEvent(eventName, {}));
  1729. // check is URL local or goes to different site
  1730. function isLocal(url)
  1731. {
  1732. let loc = window.location;
  1733. if (url === loc.pathname || url === loc.href)
  1734. return true; // URL points to current pathname or full address
  1735. let host = getHost(url),
  1736. site = loc.host;
  1737. if (host === '')
  1738. return false; // URLs with unusual protocol may have empty 'host'
  1739. if (host.length > site.length)
  1740. [site, host] = [host, site];
  1741. return site.includes(host, site.length - host.length);
  1742. }
  1743.  
  1744. function open(url)
  1745. {
  1746. '[native code]';
  1747. if (url && isLocal(url))
  1748. window.addEventListener('unload', closeWindow, true);
  1749. // jshint validthis:true
  1750. return _open.apply(this, arguments);
  1751. }
  1752.  
  1753. function clickHandler(e)
  1754. {
  1755. if (!e.target.parentNode || !e.isTrusted)
  1756. window.addEventListener('unload', closeWindow, true);
  1757. }
  1758.  
  1759. createWindowOpenWrapper(open, clickHandler);
  1760.  
  1761. console.log("Background redirect prevention enabled.");
  1762. }, [nullTools, createWindowOpenWrapper, 'let eventName="'+eventName+'"']
  1763. );
  1764. }
  1765.  
  1766. // Mix between check for popups and popunders
  1767. // Significantly more agressive than both and can't be used as universal solution
  1768. function preventPopMix()
  1769. {
  1770. if (inIFrame)
  1771. {
  1772. win.top.postMessage({ name: 'sandbox-me', href: win.location.href }, '*');
  1773. return;
  1774. }
  1775.  
  1776. // create "close_me" event to call high-level window.close()
  1777. let eventName = 'close_me_' + Math.random().toString(36).substr(2);
  1778. let callClose = () => (console.log('close call'), window.close());
  1779. window.addEventListener(eventName, callClose, true);
  1780.  
  1781. scriptLander(
  1782. function()
  1783. {
  1784. let _open = window.open,
  1785. parseURL = document.createElement('A');
  1786. // get host of a provided URL with help of an anchor object
  1787. // unfortunately new URL(url, window.location) generates wrong URL in some cases
  1788. let getHost = (url) => (parseURL.href = url, parseURL.host);
  1789. // site went to a new tab and attempts to unload
  1790. // call for high-level close through event
  1791. let closeWindow = () => (_open(window.location,'_self'), window.dispatchEvent(new CustomEvent(eventName, {})));
  1792. // check is URL local or goes to different site
  1793. function isLocal(url)
  1794. {
  1795. let loc = window.location;
  1796. if (url === loc.pathname || url === loc.href)
  1797. return true; // URL points to current pathname or full address
  1798. let host = getHost(url),
  1799. site = loc.host;
  1800. if (host === '')
  1801. return false; // URLs with unusual protocol may have empty 'host'
  1802. if (host.length > site.length)
  1803. [site, host] = [host, site];
  1804. return site.includes(host, site.length - host.length);
  1805. }
  1806.  
  1807. // add check for redirect for 5 seconds, then disable it
  1808. function checkRedirect()
  1809. {
  1810. window.addEventListener('unload', closeWindow, true);
  1811. setTimeout(closeWindow=>window.removeEventListener('unload', closeWindow, true), 5000, closeWindow);
  1812. }
  1813.  
  1814. function open(url, name)
  1815. {
  1816. '[native code]';
  1817. if (url && isLocal(url) && (!name || name === '_blank'))
  1818. {
  1819. console.trace('Suspicious local new window', arguments);
  1820. checkRedirect();
  1821. // jshint validthis:true
  1822. return _open.apply(this, arguments);
  1823. }
  1824. console.trace('Blocked attempt to open a new window', arguments);
  1825. return {
  1826. document: {
  1827. write: () => {},
  1828. writeln: () => {}
  1829. }
  1830. };
  1831. }
  1832.  
  1833. function clickHandler(e)
  1834. {
  1835. let link = e.target,
  1836. url = link.href||'';
  1837. if (e.targetParentNode && e.isTrusted || link.target !== '_blank')
  1838. {
  1839. console.log('Link', link, 'were created dinamically, but looks fine.');
  1840. return true;
  1841. }
  1842. if (isLocal(url) && link.target === '_blank')
  1843. {
  1844. console.log('Suspicious local link', link);
  1845. checkRedirect();
  1846. return;
  1847. }
  1848. console.log('Blocked suspicious click on a link', link);
  1849. e.stopPropagation();
  1850. e.preventDefault();
  1851. }
  1852.  
  1853. createWindowOpenWrapper(open, clickHandler);
  1854.  
  1855. console.log("Mixed popups prevention enabled.");
  1856. }, [createWindowOpenWrapper, 'let eventName="'+eventName+'"']
  1857. );
  1858. }
  1859. // External listener for case when site known to open popups were loaded in iframe
  1860. // It will sandbox any iframe which will send message 'forbid.popups' (preventPopups sends it)
  1861. // Some sites replace frame's window.location with data-url to run in clean context
  1862. if (!inIFrame)
  1863. {
  1864. window.addEventListener(
  1865. 'message', function(e)
  1866. {
  1867. if (!e.data || e.data.name !== 'sandbox-me' || !e.data.href)
  1868. return;
  1869. let src = e.data.href;
  1870. for (let frame of document.querySelectorAll('iframe'))
  1871. if (frame.contentWindow === e.source)
  1872. {
  1873. if (frame.hasAttribute('sandbox'))
  1874. {
  1875. if (!frame.sandbox.contains('allow-popups'))
  1876. return; // exit frame since it's already sandboxed and popups are blocked
  1877. // remove allow-popups if frame already sandboxed
  1878. frame.sandbox.remove('allow-popups');
  1879. } else {
  1880. // set sandbox mode for troublesome frame and allow scripts, forms and a few other actions
  1881. // technically allowing both scripts and same-origin allows removal of the sandbox attribute,
  1882. // but to apply content must be reloaded and this script will re-apply it in the result
  1883. frame.setAttribute('sandbox','allow-forms allow-scripts allow-presentation allow-top-navigation allow-same-origin');
  1884. }
  1885. console.log('Disallowed popups from iframe', frame);
  1886.  
  1887. // reload frame content to apply restrictions
  1888. if (!src) {
  1889. src = frame.src;
  1890. console.log('Unable to get current iframe location, reloading from src', src);
  1891. } else
  1892. console.log('Reloading iframe with URL', src);
  1893. frame.src = 'about:blank';
  1894. frame.src = src;
  1895. }
  1896. }, false
  1897. );
  1898. }
  1899.  
  1900. // === Scripts for specific domains ===
  1901.  
  1902. let scripts = {};
  1903. // prevent popups and redirects block
  1904. // Popups
  1905. scripts.preventPopups = {
  1906. other: [
  1907. 'biqle.ru',
  1908. 'chaturbate.com',
  1909. 'dfiles.ru',
  1910. 'hentaiz.org',
  1911. 'mirrorcreator.com',
  1912. 'online-multy.ru',
  1913. 'radikal.ru',
  1914. 'seedoff.cc', 'seedoff.tv',
  1915. 'tapochek.net', 'thepiratebay.org', 'torseed.net',
  1916. 'unionpeer.com',
  1917. 'zippyshare.com'
  1918. ],
  1919. now: preventPopups
  1920. };
  1921. // Popunders (background redirect)
  1922. scripts.preventPopunders = {
  1923. other: [
  1924. 'mediafire.com', 'megapeer.org', 'megapeer.ru',
  1925. 'perfectgirls.net'
  1926. ],
  1927. now: preventPopunders
  1928. };
  1929. // PopMix (both types of popups encountered on site)
  1930. scripts['openload.co'] = {
  1931. other: ['oload.tv'],
  1932. now: () => {
  1933. if (location.pathname.startsWith('/embed/'))
  1934. {
  1935. let nt = new nullTools();
  1936. nt.define(win, 'BetterJsPop', {
  1937. add: ((a, b) => console.trace('BetterJsPop.add', a, b)),
  1938. config: ((o) => console.trace('BetterJsPop.config', o)),
  1939. Browser: { isChrome: true }
  1940. });
  1941. nt.define(win, 'isSandboxed', nt.func(null));
  1942. nt.define(win, 'adblock', false);
  1943. nt.define(win, 'adblock2', false);
  1944. nt.define(win, 'CNight', nt.proxy({
  1945. Anonymous: function()
  1946. {
  1947. return {
  1948. setThrottle: nt.func(null),
  1949. start: nt.func(null)
  1950. };
  1951. },
  1952. JobThread: nt.func(null),
  1953. Token: nt.func(null),
  1954. User: nt.func(null)
  1955. }));
  1956. } else
  1957. preventPopMix();
  1958. }
  1959. };
  1960. scripts['turbobit.net'] = preventPopMix;
  1961.  
  1962. // other
  1963. scripts['2picsun.ru'] = {
  1964. other: [
  1965. 'pics2sun.ru', '3pics-img.ru'
  1966. ],
  1967. now: () => {
  1968. Object.defineProperty(navigator, 'userAgent', {value: 'googlebot'});
  1969. }
  1970. };
  1971.  
  1972. scripts['4pda.ru'] = {
  1973. now: () => {
  1974. // https://greasyfork.org/en/scripts/14470-4pda-unbrender
  1975. let hStyle,
  1976. isForum = document.location.href.search('/forum/') !== -1,
  1977. remove = (node) => (node ? node.parentNode.removeChild(node) : null),
  1978. afterClean = () => remove(hStyle);
  1979.  
  1980. function beforeClean()
  1981. {
  1982. // attach styles before document displayed
  1983. hStyle = createStyle([
  1984. 'html { overflow-y: scroll }',
  1985. 'section[id] {'+(
  1986. 'position: absolute;'+
  1987. 'width: 100%'
  1988. )+'}',
  1989. 'article + aside * { display: none !important }',
  1990. '#header + div:after {'+(
  1991. 'content: "";'+
  1992. 'position: fixed;'+
  1993. 'top: 0;'+
  1994. 'left: 0;'+
  1995. 'width: 100%;'+
  1996. 'height: 100%;'+
  1997. 'background-color: #E6E7E9'
  1998. )+'}',
  1999. // http://codepen.io/Beaugust/pen/DByiE
  2000. '@keyframes spin { 100% { transform: rotate(360deg) } }',
  2001. 'article + aside:after {'+(
  2002. 'content: "";'+
  2003. 'position: absolute;'+
  2004. 'width: 150px;'+
  2005. 'height: 150px;'+
  2006. 'top: 150px;'+
  2007. 'left: 50%;'+
  2008. 'margin-top: -75px;'+
  2009. 'margin-left: -75px;'+
  2010. 'box-sizing: border-box;'+
  2011. 'border-radius: 100%;'+
  2012. 'border: 10px solid rgba(0, 0, 0, 0.2);'+
  2013. 'border-top-color: rgba(0, 0, 0, 0.6);'+
  2014. 'animation: spin 2s infinite linear'
  2015. )+'}'
  2016. ], {id:'ubrHider'}, true);
  2017.  
  2018. // display content of a page if time to load a page is more than 2 seconds to avoid
  2019. // blocking access to a page if it is loading for too long or stuck in a loading state
  2020. setTimeout(2000, afterClean);
  2021. }
  2022.  
  2023. createStyle([
  2024. '#nav .use-ad { display: block !important }',
  2025. 'article:not(.post) + article:not(#id),'+
  2026. 'html:not(#id)>body:not(#id) a[target="_blank"] img[height="90"] { display: none !important }'
  2027. ]);
  2028.  
  2029. if (!isForum)
  2030. beforeClean();
  2031.  
  2032. // save links to non-overridden functions to use later
  2033. let protectedElems;
  2034. // protect/hide changed attributes in case site attempt to restore them
  2035. function styleProtector(eventMode)
  2036. {
  2037. let _toLowerCase = String.prototype.toLowerCase,
  2038. isStyleText = (t) => (_toLowerCase.call(t) === 'style'),
  2039. protectedElems = new WeakMap();
  2040. function protoOverride(element, functionName, isStyleCheck, returnIfProtected)
  2041. {
  2042. let originalFunction = element.prototype[functionName];
  2043. element.prototype[functionName] = function wrapper()
  2044. {
  2045. if (protectedElems.has(this) && isStyleCheck(arguments[0]))
  2046. return returnIfProtected(this, arguments);
  2047. return originalFunction.apply(this, arguments);
  2048. };
  2049. }
  2050. protoOverride(Element, 'removeAttribute', isStyleText, () => undefined);
  2051. protoOverride(Element, 'hasAttribute', isStyleText, (_this) => protectedElems.get(_this) !== null);
  2052. protoOverride(Element, 'setAttribute', isStyleText, (_this, args) => protectedElems.set(_this, args[1]));
  2053. protoOverride(Element, 'getAttribute', isStyleText, (_this) => protectedElems.get(_this));
  2054. if (!eventMode)
  2055. return protectedElems;
  2056. else
  2057. {
  2058. let e = document.createEvent('Event');
  2059. e.initEvent('protoOverride', false, false);
  2060. window.protectedElems = protectedElems;
  2061. window.dispatchEvent(e);
  2062. }
  2063. }
  2064. if (!isFirefox)
  2065. protectedElems = styleProtector(false);
  2066. else
  2067. {
  2068. let script = document.createElement('script');
  2069. script.textContent = '(' + styleProtector.toString() + ')(true);';
  2070. window.addEventListener(
  2071. 'protoOverride', function protoOverrideCallback(e)
  2072. {
  2073. if (win.protectedElems) {
  2074. protectedElems = win.protectedElems;
  2075. delete win.protectedElems;
  2076. }
  2077. document.removeEventListener('protoOverride', protoOverrideCallback, true);
  2078. }, true
  2079. );
  2080. _appendChild(script);
  2081. _removeChild(script);
  2082. }
  2083.  
  2084. // clean a page
  2085. window.addEventListener(
  2086. 'DOMContentLoaded', function()
  2087. {
  2088. let width = () => window.innerWidth || _de.clientWidth || document.body.clientWidth || 0;
  2089. let height = () => window.innerHeight || _de.clientHeight || document.body.clientHeight || 0;
  2090.  
  2091. if (isForum)
  2092. {
  2093. let si = document.querySelector('#logostrip');
  2094. if (si)
  2095. remove(si.parentNode.nextSibling);
  2096. }
  2097.  
  2098. if (document.location.href.search('/forum/dl/') !== -1) {
  2099. document.body.setAttribute('style', (document.body.getAttribute('style')||'')+
  2100. ';background-color:black!important');
  2101. for (let itm of document.querySelectorAll('body>div'))
  2102. if (!itm.querySelector('.dw-fdwlink'))
  2103. remove(itm);
  2104. }
  2105.  
  2106. if (isForum) // Do not continue if it's a forum
  2107. return;
  2108.  
  2109. {
  2110. let si = document.querySelector('#header');
  2111. if (si)
  2112. {
  2113. let rem = si.previousSibling;
  2114. while (rem)
  2115. {
  2116. si = rem.previousSibling;
  2117. remove(rem);
  2118. rem = si;
  2119. }
  2120. }
  2121. }
  2122.  
  2123. for (let itm of document.querySelectorAll('#nav li[class]'))
  2124. if (itm && itm.querySelector('a[href^="/tag/"]'))
  2125. remove(itm);
  2126.  
  2127. let style, result,
  2128. fakeStyles = new WeakMap(),
  2129. styleProxy = {
  2130. get: function(target, prop)
  2131. {
  2132. let fakeStyle = fakeStyles.get(target);
  2133. return ((prop in fakeStyle) ? fakeStyle : target)[prop];
  2134. },
  2135. set: function(target, prop, value)
  2136. {
  2137. let fakeStyle = fakeStyles.get(target);
  2138. ((prop in fakeStyle) ? fakeStyle : target)[prop] = value;
  2139. return value;
  2140. }
  2141. };
  2142. for (let itm of document.querySelectorAll('DIV, A'))
  2143. {
  2144. if (itm.tagName ==='DIV' &&
  2145. itm.offsetWidth > 0.95 * width() &&
  2146. itm.offsetHeight > 0.85 * height())
  2147. {
  2148. style = window.getComputedStyle(itm, null);
  2149. result = [];
  2150.  
  2151. if (style.backgroundImage !== 'none')
  2152. result.push('background-image:none!important');
  2153.  
  2154. if (style.backgroundColor !== 'transparent' &&
  2155. style.backgroundColor !== 'rgba(0, 0, 0, 0)')
  2156. result.push('background-color:transparent!important');
  2157.  
  2158. if (result.length)
  2159. {
  2160. if (itm.getAttribute('style'))
  2161. result.unshift(itm.getAttribute('style'));
  2162.  
  2163. fakeStyles.set(itm.style, {
  2164. 'backgroundImage': itm.style.backgroundImage,
  2165. 'backgroundColor': itm.style.backgroundColor
  2166. });
  2167.  
  2168. try {
  2169. Object.defineProperty(itm, 'style', {
  2170. value: new Proxy(itm.style, styleProxy),
  2171. enumerable: true
  2172. });
  2173. } catch (e) {
  2174. console.log('Unable to protect style property.', e);
  2175. }
  2176.  
  2177. if (protectedElems)
  2178. protectedElems.set(itm, _getAttribute.call(itm, 'style'));
  2179.  
  2180. _setAttribute.call(itm, 'style', result.join(';'));
  2181. }
  2182. }
  2183. if (itm.tagName ==='A' &&
  2184. (itm.offsetWidth > 0.95 * width() ||
  2185. itm.offsetHeight > 0.85 * height()))
  2186. {
  2187. if (protectedElems)
  2188. protectedElems.set(itm, _getAttribute.call(itm, 'style'));
  2189.  
  2190. _setAttribute.call(itm, 'style', 'display:none!important');
  2191. }
  2192. }
  2193.  
  2194. for (let itm of document.querySelectorAll('ASIDE>DIV'))
  2195. if ( ((itm.querySelector('script, iframe, a[href*="/ad/www/"]') ||
  2196. itm.querySelector('img[src$=".gif"]:not([height="0"]), img[height="400"]')) &&
  2197. !itm.classList.contains('post') ) || !itm.childNodes.length )
  2198. remove(itm);
  2199.  
  2200. document.body.setAttribute('style', (document.body.getAttribute('style')||'')+';background-color:#E6E7E9!important');
  2201.  
  2202. // display content of the page
  2203. afterClean();
  2204. }
  2205. );
  2206. }
  2207. };
  2208.  
  2209. scripts['allmovie.pro'] = {
  2210. other: ['rufilmtv.org'],
  2211. dom: function()
  2212. {
  2213. // pretend to be Android to make site use different played for ads
  2214. if (isSafari)
  2215. return;
  2216. Object.defineProperty(navigator, 'userAgent', {
  2217. get: function(){ return 'Mozilla/5.0 (Linux; Android 4.1.1; Nexus 7 Build/JRO03D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19'; },
  2218. enumerable: true
  2219. });
  2220. }
  2221. };
  2222.  
  2223. scripts['anidub-online.ru'] = {
  2224. other: ['online.anidub.com'],
  2225. dom: function()
  2226. {
  2227. if (win.ogonekstart1)
  2228. win.ogonekstart1 = () => console.log("Fire in the hole!");
  2229. },
  2230. now: () => createStyle([
  2231. '.background {background: none!important;}',
  2232. '.background > script + div,'+
  2233. '.background > script ~ div:not([id]):not([class]) + div[id][class]'+
  2234. '{display:none!important}'
  2235. ])
  2236. };
  2237.  
  2238. scripts['drive2.ru'] = () => gardener('.c-block:not([data-metrika="recomm"]),.o-grid__item', />Реклама<\//i);
  2239.  
  2240. scripts['fishki.net'] = () => gardener('.drag_list > .drag_element, .list-view > .paddingtop15, .post-wrap', /543769|Новости\sпартнеров|Полезная\sреклама/);
  2241.  
  2242. scripts['gidonline.club'] = () => createStyle('.tray > div[style] {display: none!important}');
  2243.  
  2244. scripts['hdgo.cc'] = {
  2245. other: ['46.30.43.38', 'couber.be'],
  2246. now: () => (new MutationObserver(
  2247. function(ms)
  2248. {
  2249. let m, node;
  2250. for (m of ms) for (node of m.addedNodes)
  2251. if (node.tagName === 'SCRIPT' && _getAttribute.call(node, 'onerror') !== null)
  2252. node.removeAttribute('onerror');
  2253. }
  2254. )).observe(document.documentElement, { childList:true, subtree: true })
  2255. };
  2256.  
  2257. scripts['gismeteo.ru'] = {
  2258. other: ['gismeteo.ua'],
  2259. now: () => gardener('div > a[target^="_"]', /Яндекс\.Директ/i, { root: 'body', observe: true, parent: 'div[class*="frame"]'})
  2260. };
  2261.  
  2262. scripts['hdrezka.ag'] = () => {
  2263. Object.defineProperty(win, 'ab', { value: false, enumerable: true });
  2264. gardener('div[id][onclick][onmouseup][onmousedown]', /onmouseout/i);
  2265. };
  2266.  
  2267. scripts['imageban.ru'] = {
  2268. now: preventPopunders,
  2269. dom: () => win.addEventListener('unload', () => location.hash = 'x'+Math.random().toString(36).substr(2), true)
  2270. };
  2271.  
  2272. scripts['mail.ru'] = {
  2273. now: function()
  2274. {
  2275. // Trick to prevent mail.ru from removing 3rd-party styles
  2276. scriptLander(
  2277. () => Object.defineProperty(Object.prototype, 'restoreVisibility', {
  2278. get: () => (() => null),
  2279. set: () => null
  2280. })
  2281. );
  2282. /* Experimental code, disabled for end users for now
  2283. // Ads removal on e.mail.ru
  2284. if (window.location.hostname === 'e.mail.ru')
  2285. {
  2286. let selector = (
  2287. '.b-datalist div[class]:not([id]) > div[class]:not([class*="js-"]),'+
  2288. '.b-letter div[class]:not([id]) > div[class]:not([class*="js-"]):not([class*="drop"]):not([class*="letter"]):not([style]):not([id]),'+
  2289. 'div[id]:not([class]) > div[id][class]:not([class*="js-"]):not([class*="drop"]):not([style])'
  2290. );
  2291. let janitor = function(nodes)
  2292. {
  2293. let color;
  2294. for (let node of nodes)
  2295. {
  2296. if (node.nodeType !== Node.ELEMENT_NODE)
  2297. continue;
  2298. color = window.getComputedStyle(node).backgroundColor;
  2299. if (/^rgb\(/.test(color) && color !== 'rgb(255, 255, 255)')
  2300. {
  2301. node.style.display = 'none';
  2302. console.log('Hide node:', node);
  2303. }
  2304. }
  2305. };
  2306. janitor(document.querySelectorAll(selector));
  2307. (new MutationObserver(
  2308. function(ms)
  2309. {
  2310. for (let m of ms)
  2311. janitor(m.addedNodes);
  2312. }
  2313. )).observe(
  2314. document.documentElement, {
  2315. childList: true,
  2316. subtree: true
  2317. }
  2318. );
  2319. }
  2320. /**/
  2321. }
  2322. };
  2323.  
  2324. scripts['megogo.net'] = {
  2325. now: () => {
  2326. let nt = new nullTools();
  2327. nt.define(win, 'adBlock', false);
  2328. nt.define(win, 'showAdBlockMessage', nt.func(null));
  2329. }
  2330. };
  2331.  
  2332. scripts['naruto-base.su'] = () => gardener('div[id^="entryID"],.block', /href="http.*?target="_blank"/i);
  2333.  
  2334. scripts['overclockers.ru'] = {
  2335. now: () => {
  2336. createStyle('.fixoldhtml {display:block!important}');
  2337. if (!isChrome && !isOpera)
  2338. return; // Looks like my code works only in Chrome-like browsers
  2339. let noContentYet = true;
  2340. function jWrap()
  2341. {
  2342. win.$ = new Proxy(
  2343. win.$, {
  2344. apply: function(_$, _this, args)
  2345. {
  2346. let _ret = _$.apply(_this, args);
  2347. if (_ret[0] === document.body)
  2348. _ret.html = () => console.log('Anti-adblock prevented.');
  2349. return _ret;
  2350. }
  2351. }
  2352. );
  2353. win.jQuery = win.$;
  2354. }
  2355. (function jReady()
  2356. {
  2357. if (!win.$ && noContentYet)
  2358. setTimeout(jReady, 0);
  2359. else
  2360. jWrap();
  2361. })();
  2362. document.addEventListener ('DOMContentLoaded', () => (noContentYet = false), false);
  2363. }
  2364. };
  2365. scripts['forums.overclockers.ru'] = {
  2366. now: () => {
  2367. createStyle('.needblock {position: fixed; left: -10000px}');
  2368. Object.defineProperty(win, 'adblck', {
  2369. get: () => 'no',
  2370. set: () => null,
  2371. enumerable: true
  2372. });
  2373. }
  2374. };
  2375.  
  2376. scripts['pb.wtf'] = {
  2377. other: ['piratbit.org', 'piratbit.ru'],
  2378. now: () => {
  2379. // line above topic content and images in the slider in the header
  2380. gardener(
  2381. 'a[href^="/exit/"], a[href^="/fxt/"], a[href$="=="]',
  2382. /img|Реклама|center/i,
  2383. { root: '.release-navbar,#page_content', observe: true, parent: 'div,tr' }
  2384. );
  2385. // ads in comments
  2386. gardener('img[data-name="PiraBo"]', /./i, {root:'#main_content .table', observe:true, parent:'tr'});
  2387. }
  2388. };
  2389.  
  2390. scripts['pikabu.ru'] = () => gardener('.story', /story__sponsor|story__gag|profile\/ads"/i, {root: '.inner_wrap', observe: true});
  2391.  
  2392. scripts['qrz.ru'] = {
  2393. now: () => {
  2394. let nt = new nullTools();
  2395. nt.define(win, 'ab', false);
  2396. nt.define(win, 'tryMessage', nt.func(null));
  2397. }
  2398. };
  2399.  
  2400. scripts['razlozhi.ru'] = {
  2401. now: () => {
  2402. for (let func of ['createShadowRoot', 'attachShadow'])
  2403. if (func in Element.prototype)
  2404. Element.prototype[func] = function(){ return this.cloneNode(); };
  2405. }
  2406. };
  2407.  
  2408. scripts['rbc.ru'] = {
  2409. dom: () => {
  2410. let _preventDefault = Event.prototype.preventDefault;
  2411. Event.prototype.preventDefault = function preventDefault()
  2412. {
  2413. let t = this.target;
  2414. if (t instanceof HTMLAnchorElement || t.closest('A'))
  2415. throw new Error('an.yandex redirect prevention');
  2416. return _preventDefault.call(this);
  2417. };
  2418.  
  2419. function cleaner(nodes)
  2420. {
  2421. for (let node of nodes)
  2422. {
  2423. if (!node.classList || !node.classList.contains('js-yandex-counter'))
  2424. continue;
  2425. node.classList.remove('js-yandex-counter');
  2426. node.removeAttribute('data-yandex-name');
  2427. node.removeAttribute('data-yandex-params');
  2428. }
  2429. }
  2430. cleaner(_de.querySelectorAll('.js-yandex-counter'));
  2431.  
  2432. (new MutationObserver(
  2433. ms => { for (let m of ms) cleaner(m.addedNodes); }
  2434. )).observe(_de, {childList: true, subtree: true});
  2435. }
  2436. };
  2437.  
  2438. scripts['rp5.ru'] = {
  2439. other: ['rp5.by', 'rp5.kz', 'rp5.ua'],
  2440. dom: () => {
  2441. createStyle('#bannerBottom {display: none!important}');
  2442. let co = document.querySelector('#content');
  2443. if (!co)
  2444. return;
  2445. let nodes = co.children;
  2446. let i = nodes.length;
  2447. while(i--)
  2448. if (nodes[i].querySelector('a[href*="?AdvertMgmt="]'))
  2449. nodes[i].parentNode.removeChild(nodes[i]);
  2450. nodes = co.parentNode.children;
  2451. i = nodes.length;
  2452. while(i--)
  2453. if (nodes[i] !== co)
  2454. nodes[i].parentNode.removeChild(nodes[i]);
  2455. nodes = co.childNodes;
  2456. }
  2457. };
  2458.  
  2459. scripts['rustorka.com'] = {
  2460. other: ['rumedia.ws'],
  2461. now: () => {
  2462. createStyle('.header > div:not(.head-block) a, #sidebar1 img, #logo img {opacity:0!important}', {
  2463. id: 'tempHidingStyles'
  2464. }, true);
  2465. preventPopups();
  2466. },
  2467. dom: () => {
  2468. for (let o of document.querySelectorAll('IMG, A'))
  2469. if ((o.clientWidth === 728 && o.clientHeight === 90) ||
  2470. (o.clientWidth === 300 && o.clientHeight === 250))
  2471. {
  2472. while (o && o.tagName !== 'A')
  2473. o = o.parentNode;
  2474. if (o)
  2475. _setAttribute.call(o, 'style', 'display: none !important');
  2476. }
  2477. let s = document.querySelector('#tempHidingStyles');
  2478. s.parentNode.removeChild(s);
  2479. }
  2480. };
  2481.  
  2482. scripts['sport-express.ru'] = () => gardener('.js-relap__item',/>Реклама\s+<\//, {root:'.container', observe: true});
  2483.  
  2484. scripts['sports.ru'] = {
  2485. now: () => {
  2486. gardener('.aside-news-list__item', /aside-news-list__advert/i, {root:'.columns-layout__left', observe: true});
  2487. gardener('.material-list__item', /Реклама/i, {root:'.columns-layout', observe: true});
  2488. // extra functionality: shows/hides panel at the top depending on scroll direction
  2489. createStyle([
  2490. '.user-panel__fixed { transition: top 0.2s ease-in-out!important; }',
  2491. '.user-panel-up { top: -40px!important }'
  2492. ], {id: 'userPanelSlide'}, false);
  2493. },
  2494. dom: () => {
  2495. (function lookForPanel()
  2496. {
  2497. let panel = document.querySelector('.user-panel__fixed');
  2498. if (!panel)
  2499. setTimeout(lookForPanel, 100);
  2500. else
  2501. window.addEventListener(
  2502. 'wheel', function(e)
  2503. {
  2504. if (e.deltaY > 0 && !panel.classList.contains('user-panel-up'))
  2505. panel.classList.add('user-panel-up');
  2506. else if (e.deltaY < 0 && panel.classList.contains('user-panel-up'))
  2507. panel.classList.remove('user-panel-up');
  2508. }, false
  2509. );
  2510. })();
  2511. }
  2512. };
  2513.  
  2514. scripts['vk.com'] = () => gardener((
  2515. '#wk_content > #wl_post > div,'+
  2516. '#page_wall_posts > div[id^="post-"],'+
  2517. 'div[class^="feed_row "] > div[id^="post-"],'+
  2518. 'div[class^="feed_row "] > div[id^="feed_repost-"]'
  2519. ), /wall_marked_as_ads/, {root: 'body', observe: true});
  2520.  
  2521. scripts['yap.ru'] = {
  2522. other: ['yaplakal.com'],
  2523. now: () => {
  2524. gardener('form > table[id^="p_row_"]:nth-of-type(2)', /member1438|Administration/);
  2525. gardener('.icon-comments', /member1438|Administration|\/go\/\?http/, {parent:'tr', siblings:-2});
  2526. }
  2527. };
  2528.  
  2529. scripts['rambler.ru'] = {
  2530. other: ['championat.com','gazeta.ru','media.eagleplatform.com','lenta.ru'],
  2531. now: () => scriptLander(
  2532. () => {
  2533. if (location.hostname.endsWith('.media.eagleplatform.com'))
  2534. return;
  2535. let getDomain = (name) => name.replace(/[^:]+:\/\/([^:/]+)[:/].*/, '$1').replace(/[^.]+\./,'');
  2536. let _onload = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'onload');
  2537. let _set = _onload.set;
  2538. _onload.configurable = false;
  2539. _onload.set = function(func)
  2540. {
  2541. _set.call(
  2542. this, function(e)
  2543. {
  2544. let d = e.target.href ? getDomain(e.target.href) : null,
  2545. h = location.hostname;
  2546. if (d && e.target instanceof HTMLLinkElement &&
  2547. (d === 'rambler.ru' || d === h || h.indexOf('.'+d) > -1))
  2548. {
  2549. console.log('Blocked "onload" for', e.target.href);
  2550. return false;
  2551. }
  2552. return func.apply(this, arguments);
  2553. }
  2554. );
  2555. };
  2556. Object.defineProperty(HTMLElement.prototype, 'onload', _onload);
  2557. // fake global Adf object
  2558. let nt = new nullTools();
  2559. nt.define(win, 'Adf', nt.proxy({
  2560. banner: nt.proxy({
  2561. sspScroll: nt.func(),
  2562. ssp: nt.func()
  2563. })
  2564. }));
  2565. // extra script to remove partner news on gazeta.ru
  2566. if (!location.hostname.includes('gazeta.ru'))
  2567. return;
  2568. (new MutationObserver(
  2569. (ms) => {
  2570. let m, node, header;
  2571. for (m of ms) for (node of m.addedNodes)
  2572. if (node instanceof HTMLDivElement && node.matches('.sausage'))
  2573. {
  2574. header = node.querySelector('.sausage-header');
  2575. if (header && /новости\s+партн[её]ров/i.test(header.textContent))
  2576. node.style.display = 'none';
  2577. }
  2578. }
  2579. )).observe(document.documentElement, { childList:true, subtree: true });
  2580. }, nullTools
  2581. ),
  2582. dom: () => {
  2583. // extra script to block video autoplay on Rambler domains
  2584. function unstopper(e, stopper, timeout)
  2585. {
  2586. if (timeout)
  2587. clearTimeout(timeout);
  2588. return setTimeout(
  2589. (e) => e.target.removeEventListener('playing', stopper, false),
  2590. 333, e
  2591. );
  2592. }
  2593. function stopper(e)
  2594. {
  2595. let timeout = unstopper(e, stopper);
  2596. e.target.addEventListener(
  2597. 'pause', function()
  2598. {
  2599. timeout = unstopper(e, stopper, timeout);
  2600. }, false
  2601. );
  2602. let btn = document.querySelector('.eplayer-skin-toggle-playing');
  2603. if (btn)
  2604. btn.click();
  2605. else
  2606. e.target.pause();
  2607. }
  2608. let observer = (new MutationObserver(
  2609. (ms) => {
  2610. for (let m of ms)
  2611. if (!m.target.appliedStopper)
  2612. {
  2613. m.target.appliedStopper = true;
  2614. m.target.addEventListener('playing', stopper, false);
  2615. }
  2616. }
  2617. ));
  2618. observer.observe(document.documentElement, { subtree: true, attributes: true, attributeFilter: ['autoplay'] });
  2619. }
  2620. };
  2621.  
  2622. scripts['reactor.cc'] = {
  2623. other: ['joyreactor.cc', 'pornreactor.cc'],
  2624. now: () => win.open = (function(){ throw new Error('Redirect prevention.'); }).bind(window),
  2625. click: function(e)
  2626. {
  2627. let node = e.target;
  2628. if (node.nodeType === Node.ELEMENT_NODE &&
  2629. node.style.position === 'absolute' &&
  2630. node.style.zIndex > 0)
  2631. node.parentNode.removeChild(node);
  2632. },
  2633. dom: function()
  2634. {
  2635. let words = new RegExp(
  2636. 'блокировщика рекламы'
  2637. .split('')
  2638. .map(function(e){return e+'[\u200b\u200c\u200d]*';})
  2639. .join('')
  2640. .replace(' ', '\\s*')
  2641. .replace(/[аоре]/g, function(e){return ['[аa]','[оo]','[рp]','[еe]']['аоре'.indexOf(e)];}),
  2642. 'i'),
  2643. can;
  2644. function deeper(spider)
  2645. {
  2646. let c, l, n;
  2647. if (words.test(spider.innerText))
  2648. {
  2649. if (spider.nodeType === Node.TEXT_NODE)
  2650. return true;
  2651. c = spider.childNodes;
  2652. l = c.length;
  2653. n = 0;
  2654. while(l--)
  2655. if (deeper(c[l]), can)
  2656. n++;
  2657. if (n > 0 && n === c.length && spider.offsetHeight < 750)
  2658. can.push(spider);
  2659. return false;
  2660. }
  2661. return true;
  2662. }
  2663. function probe()
  2664. {
  2665. if (words.test(document.body.innerText))
  2666. {
  2667. can = [];
  2668. deeper(document.body);
  2669. let i = can.length, spider;
  2670. while(i--) {
  2671. spider = can[i];
  2672. if (spider.offsetHeight > 10 && spider.offsetHeight < 750)
  2673. _setAttribute.call(spider, 'style', 'background:none!important');
  2674. }
  2675. }
  2676. }
  2677. (new MutationObserver(probe))
  2678. .observe(document, { childList:true, subtree:true });
  2679. }
  2680. };
  2681.  
  2682. scripts['auto.ru'] = () => {
  2683. let words = /Реклама|Яндекс.Директ|yandex_ad_/;
  2684. let userAdsListAds = (
  2685. '.listing-list > .listing-item,'+
  2686. '.listing-item_type_fixed.listing-item'
  2687. );
  2688. let catalogAds = (
  2689. 'div[class*="layout_catalog-inline"],'+
  2690. 'div[class$="layout_horizontal"]'
  2691. );
  2692. let otherAds = (
  2693. '.advt_auto,'+
  2694. '.sidebar-block,'+
  2695. '.pager-listing + div[class],'+
  2696. '.card > div[class][style],'+
  2697. '.sidebar > div[class],'+
  2698. '.main-page__section + div[class],'+
  2699. '.listing > tbody'
  2700. );
  2701. gardener(userAdsListAds, words, {root:'.listing-wrap', observe:true});
  2702. gardener(catalogAds, words, {root:'.catalog__page,.content__wrapper', observe:true});
  2703. gardener(otherAds, words);
  2704. };
  2705.  
  2706. scripts['rsload.net'] = {
  2707. load: () => {
  2708. let dis = document.querySelector('label[class*="cb-disable"]');
  2709. if (dis)
  2710. dis.click();
  2711. },
  2712. click: () => {
  2713. let t = e.target;
  2714. if (t && t.href && (/:\/\/\d+\.\d+\.\d+\.\d+\//.test(t.href)))
  2715. t.href = t.href.replace('://','://rsload.net:rsload.net@');
  2716. }
  2717. };
  2718.  
  2719. let domain, name;
  2720. // add alternative domain names if present and wrap functions into objects
  2721. for (name in scripts)
  2722. {
  2723. if (scripts[name] instanceof Function)
  2724. scripts[name] = { now: scripts[name] };
  2725. for (domain of (scripts[name].other||[]))
  2726. {
  2727. if (domain in scripts)
  2728. console.log('Error in scripts list. Script for', name, 'replaced script for', domain);
  2729. scripts[domain] = scripts[name];
  2730. }
  2731. delete scripts[name].other;
  2732. }
  2733. // look for current domain in the list and run appropriate code
  2734. domain = document.domain;
  2735. while (domain.indexOf('.') > -1)
  2736. {
  2737. if (domain in scripts) for (name in scripts[domain])
  2738. switch(name)
  2739. {
  2740. case 'now':
  2741. scripts[domain][name]();
  2742. break;
  2743. case 'load':
  2744. window.addEventListener('load', scripts[domain][name], false);
  2745. break;
  2746. case 'dom':
  2747. document.addEventListener('DOMContentLoaded', scripts[domain][name], false);
  2748. break;
  2749. default:
  2750. document.addEventListener (name, scripts[domain][name], false);
  2751. }
  2752. domain = domain.slice(domain.indexOf('.') + 1);
  2753. }
  2754. })();