RU AdList JS Fixes

try to take over the world!

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

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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址