RU AdList JS Fixes

try to take over the world!

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

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