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. console.log(e);
  1211. res = res|hide(root(node));
  1212. continue;
  1213. }
  1214. label = node.querySelector('.label');
  1215. if (label && (adWords[1].test(label.textContent) || adWords[2].test(label.textContent)))
  1216. res = res|hide(root(node));
  1217. }
  1218. if (res)
  1219. return 'Parsed Yandex ads were hidden.';
  1220. else
  1221. return 'No ads were detected.';
  1222. }
  1223. function removeSearchAdsLog()
  1224. {
  1225. let res = removeSearchAds();
  1226. if (res) console.log(res);
  1227. }
  1228. // News ads
  1229. function removeNewsAds()
  1230. {
  1231. let node, block, item, items, mask, classes,
  1232. masks = [
  1233. { class: '.ads__wrapper', regex: /[^,]*?,[^,]*?\.ads__wrapper/ },
  1234. { class: '.ads__pool', regex: /[^,]*?,[^,]*?\.ads__pool/ }
  1235. ];
  1236. for (node of _querySelectorAll('style[nonce]'))
  1237. {
  1238. classes = node.innerText.replace(/\{[^}]+\}+/ig, '|').split('|');
  1239. for (block of classes) for (mask of masks)
  1240. if (block.includes(mask.class))
  1241. {
  1242. block = block.match(mask.regex)[0];
  1243. items = _querySelectorAll(block);
  1244. for (item of items)
  1245. remove(items[0]);
  1246. }
  1247. }
  1248. }
  1249. // Music ads
  1250. function removeMusicAds()
  1251. {
  1252. for (let node of _querySelectorAll('.ads-block'))
  1253. remove(node);
  1254. }
  1255. // Mail ads
  1256. function removeMailAds()
  1257. {
  1258. let slice = Array.prototype.slice,
  1259. nodes = slice.call(_querySelectorAll('.ns-view-folders')),
  1260. node, len, cls;
  1261.  
  1262. for (node of nodes)
  1263. if (!len || len > node.classList.length)
  1264. len = node.classList.length;
  1265.  
  1266. node = nodes.pop();
  1267. while (node)
  1268. {
  1269. if (node.classList.length > len)
  1270. for (cls of slice.call(node.classList))
  1271. if (cls.indexOf('-') === -1)
  1272. {
  1273. remove(node);
  1274. break;
  1275. }
  1276. node = nodes.pop();
  1277. }
  1278. }
  1279. // News fixes
  1280. function removePageAdsClass()
  1281. {
  1282. if (document.body.classList.contains("b-page_ads_yes"))
  1283. {
  1284. document.body.classList.remove("b-page_ads_yes");
  1285. console.log('Page ads class removed.');
  1286. }
  1287. }
  1288. // TV fixes
  1289. function removeTVAds()
  1290. {
  1291. for (let node of _querySelectorAll('div[class^="_"][data-reactid] > div'))
  1292. if (adWords[0].test(node.textContent) || node.querySelector('iframe:not([src])'))
  1293. {
  1294. if (node.offsetWidth)
  1295. {
  1296. let pad = document.createElement('div');
  1297. _setAttribute.call(pad, 'style', 'width:'+node.offsetWidth+'px');
  1298. node.parentNode.appendChild(pad);
  1299. }
  1300. remove(node);
  1301. }
  1302. }
  1303. // Function to attach an observer to monitor dynamic changes on the page
  1304. function pageUpdateObserver(func, obj, params) {
  1305. if (obj)
  1306. (new MutationObserver(func))
  1307. .observe(obj, (params || { childList:true, subtree:true }));
  1308. }
  1309.  
  1310. if (location.hostname.startsWith('mail.')) {
  1311. pageUpdateObserver(
  1312. function(ms, o)
  1313. {
  1314. let aside = _querySelector('.mail-Layout-Aside');
  1315. if (aside) {
  1316. o.disconnect();
  1317. pageUpdateObserver(removeMailAds, aside);
  1318. }
  1319. }, document.body
  1320. );
  1321. removeMailAds();
  1322. } else if (location.hostname.startsWith('music.')) {
  1323. pageUpdateObserver(removeMusicAds, _querySelector('.sidebar'));
  1324. removeMusicAds();
  1325. } else if (location.hostname.startsWith('news.')) {
  1326. pageUpdateObserver(removeNewsAds, document.body);
  1327. pageUpdateObserver(removePageAdsClass, document.body, { attributes:true, attributesFilter:['class'] });
  1328. removeNewsAds();
  1329. removePageAdsClass();
  1330. } else if (location.hostname.startsWith('tv.')) {
  1331. pageUpdateObserver(removeTVAds, document.body);
  1332. removeTVAds();
  1333. } else {
  1334. pageUpdateObserver(removeSearchAdsLog, _querySelector('.main__content'));
  1335. removeSearchAdsLog();
  1336. }
  1337. }
  1338. );
  1339. }
  1340.  
  1341. // Yandex Link Tracking
  1342. if (/^https?:\/\/([^.]+\.)*yandex\.[^\/]+/i.test(win.location.href))
  1343. {
  1344. let fakeRoot = {
  1345. firstChild: null,
  1346. appendChild: ()=>null,
  1347. querySelector: ()=>null,
  1348. querySelectorAll: ()=>null
  1349. };
  1350. Element.prototype.createShadowRoot = () => fakeRoot;
  1351. Object.defineProperty(Element.prototype, "shadowRoot", {
  1352. value: fakeRoot,
  1353. enumerable: true,
  1354. configurable: false
  1355. });
  1356. // Partially based on https://gf.qytechs.cn/en/scripts/22737-remove-yandex-redirect
  1357. let selectors = (
  1358. 'A[onmousedown*="/jsredir"],'+
  1359. 'A[data-vdir-href],'+
  1360. 'A[data-counter]'
  1361. );
  1362. let removeTrackingAttributes = function(link)
  1363. {
  1364. link.removeAttribute('onmousedown');
  1365. if (link.hasAttribute('data-vdir-href')) {
  1366. link.removeAttribute('data-vdir-href');
  1367. link.removeAttribute('data-orig-href');
  1368. }
  1369. if (link.hasAttribute('data-counter')) {
  1370. link.removeAttribute('data-counter');
  1371. link.removeAttribute('data-bem');
  1372. }
  1373. };
  1374. let removeTracking = function(scope)
  1375. {
  1376. for (let link of scope.querySelectorAll(selectors))
  1377. removeTrackingAttributes(link);
  1378. };
  1379. document.addEventListener('DOMContentLoaded', (e) => removeTracking(e.target));
  1380. (new MutationObserver(
  1381. function(ms)
  1382. {
  1383. let m, node;
  1384. for (m of ms) for (node of m.addedNodes) if (node.nodeType === Node.ELEMENT_NODE)
  1385. if (node.tagName === 'A' && node.matches(selectors)) {
  1386. removeTrackingAttributes(node);
  1387. } else {
  1388. removeTracking(node);
  1389. }
  1390. }
  1391. )).observe(_de, { childList: true, subtree: true });
  1392.  
  1393. //skip fixes for other sites
  1394. return;
  1395. }
  1396.  
  1397. // https://gf.qytechs.cn/en/scripts/21937-moonwalk-hdgo-kodik-fix v0.8 (adapted)
  1398. document.addEventListener(
  1399. 'DOMContentLoaded', function()
  1400. {//createPlayer();
  1401. function log (name) {
  1402. console.log(`Player FIX: Detected ${name} player in ${location.href}`);
  1403. }
  1404. if (win.adv_enabled !== undefined && win.condition_detected !== undefined)
  1405. {
  1406. log('Moonwalk');
  1407. if (win.adv_enabled)
  1408. win.adv_enabled = false;
  1409. win.condition_detected = false;
  1410. if (win.MXoverrollCallback)
  1411. document.addEventListener(
  1412. 'click', function catcher(e)
  1413. {
  1414. e.stopPropagation();
  1415. win.MXoverrollCallback.call(window);
  1416. document.removeEventListener('click', catcher, true);
  1417. }, true
  1418. );
  1419. }
  1420. else if (win.stat_url !== undefined && win.is_html5 !== undefined && win.is_wp8 !== undefined)
  1421. {
  1422. log('HDGo');
  1423. document.body.onclick = null;
  1424. let tmp = document.querySelector('#swtf');
  1425. if (tmp)
  1426. tmp.style.display = 'none';
  1427. if (win.banner_second !== undefined)
  1428. win.banner_second = 0;
  1429. if (win.$banner_ads !== undefined)
  1430. win.$banner_ads = false;
  1431. if (win.$new_ads !== undefined)
  1432. win.$new_ads = false;
  1433. if (win.createCookie !== undefined)
  1434. win.createCookie('popup', 'true', '999');
  1435. if (win.canRunAds !== undefined && win.canRunAds !== true)
  1436. win.canRunAds = true;
  1437. }
  1438. else if (win.MXoverrollCallback && win.iframeSearch !== undefined)
  1439. {
  1440. log('Kodik');
  1441. let tmp = document.querySelector('.play_button');
  1442. if (tmp)
  1443. tmp.onclick = win.MXoverrollCallback.bind(window);
  1444. win.IsAdBlock = false;
  1445. }
  1446. else if (win.getnextepisode && win.uppodEvent)
  1447. {
  1448. log('Share-Serials.net');
  1449. scriptLander(
  1450. function()
  1451. {
  1452. let _setInterval = win.setInterval,
  1453. _setTimeout = win.setTimeout;
  1454. win.setInterval = function(func)
  1455. {
  1456. if (func instanceof Function && func.toString().indexOf('_delay') > -1)
  1457. {
  1458. let intv = _setInterval.call(
  1459. this, function()
  1460. {
  1461. _setTimeout.call(
  1462. this, function(intv)
  1463. {
  1464. clearInterval(intv);
  1465. let timer = document.querySelector('#timer');
  1466. if (timer)
  1467. timer.click();
  1468. }, 100, intv);
  1469. func.call(this);
  1470. }, 5
  1471. );
  1472.  
  1473. return intv;
  1474. }
  1475. return _setInterval.apply(this, arguments);
  1476. };
  1477. win.setTimeout = function(func) {
  1478. if (func instanceof Function && func.toString().indexOf('adv_showed') > -1)
  1479. {
  1480. return _setTimeout.call(this, func, 0);
  1481. }
  1482. return _setTimeout.apply(this, arguments);
  1483. };
  1484. }
  1485. );
  1486. }
  1487. }, false
  1488. );
  1489.  
  1490. // piguiqproxy.com circumvention prevention
  1491. scriptLander(
  1492. function()
  1493. {
  1494. let _open = XMLHttpRequest.prototype.open;
  1495. let blacklist = /[/.@](piguiqproxy\.com|rcdn\.pro)[:/]/i;
  1496. XMLHttpRequest.prototype.open = function(method, url)
  1497. {
  1498. if (method === 'GET' && blacklist.test(url))
  1499. {
  1500. this.send = () => null;
  1501. this.setRequestHeader = () => null;
  1502. console.log('Blocked request: ', url);
  1503. return;
  1504. }
  1505. return _open.apply(this, arguments);
  1506. };
  1507. }
  1508. );
  1509.  
  1510. // === Helper functions ===
  1511.  
  1512. // function to search and remove nodes by content
  1513. // selector - standard CSS selector to define set of nodes to check
  1514. // words - regular expression to check content of the suspicious nodes
  1515. // params - object with multiple extra parameters:
  1516. // .log - display log in the console
  1517. // .hide - set display to none instead of removing from the page
  1518. // .parent - parent node to remove if content is found in the child node
  1519. // .siblings - number of simling nodes to remove (excluding text nodes)
  1520. let scRemove = (node) => node.parentNode.removeChild(node);
  1521. let scHide = function(node)
  1522. {
  1523. let style = _getAttribute.call(node, 'style') || '',
  1524. hide = ';display:none!important;';
  1525. if (style.indexOf(hide) < 0)
  1526. _setAttribute.call(node, 'style', style + hide);
  1527. };
  1528.  
  1529. function scissors (selector, words, scope, params)
  1530. {
  1531. let logger = function() { return params.log ? console.log(...arguments) : null; };
  1532. if (!scope.contains(document.body))
  1533. logger('[s] scope', scope);
  1534. let remFunc = (params.hide ? scHide : scRemove),
  1535. iterFunc = (params.siblings > 0 ? 'nextSibling' : 'previousSibling'),
  1536. toRemove = [],
  1537. siblings;
  1538. for (let node of scope.querySelectorAll(selector))
  1539. {
  1540. // drill up to a parent node if specified, break if not found
  1541. if (params.parent)
  1542. {
  1543. let old = node;
  1544. node = node.closest(params.parent);
  1545. if (node === null || node.contains(scope))
  1546. {
  1547. logger('[s] went out of scope with', old);
  1548. break;
  1549. }
  1550. }
  1551. logger('[s] processing', node);
  1552. if (words.test(node.innerHTML) || !node.childNodes.length)
  1553. {
  1554. // drill across for N sibling nodes
  1555. if (!toRemove.includes(node))
  1556. {
  1557. logger('[s] marked for removal');
  1558. toRemove.push(node);
  1559. // add multiple nodes if defined more than one sibling
  1560. siblings = Math.abs(params.siblings) || 0;
  1561. while (siblings)
  1562. {
  1563. node = node[iterFunc];
  1564. if (node.nodeType === Node.ELEMENT_NODE)
  1565. {
  1566. logger('[s] adding sibling node', node);
  1567. toRemove.push(node);
  1568. siblings -= 1; //count only element nodes
  1569. }
  1570. else if (!params.hide)
  1571. {
  1572. logger('[s] adding sibling node', node);
  1573. toRemove.push(node);
  1574. }
  1575. }
  1576. }
  1577. }
  1578. }
  1579. if (toRemove.length)
  1580. logger(`[s] proceeding with ${params.hide?'hide':'removal'} of`, toRemove);
  1581. for (let node of toRemove)
  1582. remFunc(node);
  1583. }
  1584.  
  1585. // function to perform multiple checks if ads inserted with a delay
  1586. // by default does 30 checks withing a 3 seconds unless nonstop mode specified
  1587. // also does 1 extra check when a page completely loads
  1588. // selector and words - passed dow to scissors
  1589. // params - object with multiple extra parameters:
  1590. // .log - display log in the console
  1591. // .root - selector to narrow down scope to scan;
  1592. // .observe - if true then check will be performed continuously;
  1593. // Other parameters passed down to scissors.
  1594. function gardener(selector, words, params)
  1595. {
  1596. let logger = function() { return params.log ? console.log(...arguments) : null; };
  1597. params = params || {};
  1598. logger(`[gardener] selector: '${selector}' detector: ${words} options: ${JSON.stringify(params)}`);
  1599. let scope = [document];
  1600. function onevent(e)
  1601. {
  1602. logger(`[gardener] cleanup on ${e.constructor.name.replace('Object', 'Event')} "${e.type}"`);
  1603. for (let node of scope)
  1604. scissors(selector, words, node, params);
  1605. }
  1606. document.addEventListener(
  1607. 'DOMContentLoaded', (e) => {
  1608. // narrow down scope to a specific element
  1609. if (params.root)
  1610. {
  1611. scope = document.querySelectorAll(params.root);
  1612. if (!scope) // exit if the root element is not present on the page
  1613. return 0;
  1614. }
  1615. logger('[g] scope', scope);
  1616. // add observe mode if required
  1617. if (params.observe)
  1618. {
  1619. let params = { childList:true, subtree: true };
  1620. let observer = new MutationObserver(
  1621. function(ms)
  1622. {
  1623. for (let m of ms)
  1624. if (m.addedNodes.length)
  1625. onevent(m);
  1626. }
  1627. );
  1628. for (let node of scope)
  1629. observer.observe(node, params);
  1630. logger('[g] observer enabled');
  1631. }
  1632. onevent(e);
  1633. }, false);
  1634. // wait for a full page load to do one extra cut
  1635. win.addEventListener('load', onevent, false);
  1636. }
  1637.  
  1638. // wrap popular methods to open a new tab to catch specific behaviours
  1639. function createWindowOpenWrapper(openFunc, onClickFunc)
  1640. {
  1641. let _createElement = Document.prototype.createElement,
  1642. _appendChild = Element.prototype.appendChild,
  1643. fakeNative = (f) => (f.toString = () => 'function '+f.name+'() { [native code] }');
  1644.  
  1645. let nt = new nullTools();
  1646. fakeNative(openFunc);
  1647. function redefineOpen(obj)
  1648. {
  1649. nt.define(obj, 'open', openFunc);
  1650. nt.define(obj.document, 'open', openFunc);
  1651. nt.define(obj.Document.prototype, 'open', openFunc);
  1652. }
  1653. redefineOpen(win);
  1654.  
  1655. function createElement(name)
  1656. {
  1657. '[native code]';
  1658. // jshint validthis:true
  1659. let el = _createElement.apply(this, arguments);
  1660. // click-dispatch check for Google Chrome and similar browsers
  1661. if (el instanceof HTMLAnchorElement)
  1662. el.addEventListener(
  1663. 'click', onClickFunc, false
  1664. );
  1665. // redefine window.open in first-party frames
  1666. if (el instanceof HTMLIFrameElement || el instanceof HTMLObjectElement)
  1667. el.addEventListener(
  1668. 'load', function(e)
  1669. {
  1670. try {
  1671. redefineOpen(e.target.contentWindow);
  1672. } catch(ignore) {}
  1673. }, false
  1674. );
  1675. return el;
  1676. }
  1677. fakeNative(createElement);
  1678.  
  1679. function redefineCreateElement(obj)
  1680. {
  1681. nt.define(obj.document, 'createElement', createElement);
  1682. nt.define(obj.Document.prototype, 'createElement', createElement);
  1683. }
  1684. redefineCreateElement(win);
  1685.  
  1686. // wrap window.open in newly added first-party frames
  1687. Element.prototype.appendChild = function appendChild()
  1688. {
  1689. '[native code]';
  1690. let el = _appendChild.apply(this, arguments);
  1691. if (el instanceof HTMLIFrameElement) {
  1692. try {
  1693. redefineOpen(el.contentWindow);
  1694. redefineCreateElement(el.contentWindow);
  1695. } catch(ignore) {}
  1696. }
  1697. return el;
  1698. };
  1699. fakeNative(Element.prototype.appendChild);
  1700. }
  1701.  
  1702. // Function to catch and block various methods to open a new window with 3rd-party content.
  1703. // Some advertisement networks went way past simple window.open call to circumvent default popup protection.
  1704. // This funciton blocks window.open, ability to restore original window.open from an IFRAME object,
  1705. // ability to perform an untrusted (not initiated by user) click on a link, click on a link without a parent
  1706. // node or simply a link with piece of javascript code in the HREF attribute.
  1707. function preventPopups()
  1708. {
  1709. if (inIFrame)
  1710. {
  1711. win.top.postMessage({ name: 'sandbox-me', href: win.location.href }, '*');
  1712. return;
  1713. }
  1714.  
  1715. scriptLander(
  1716. function()
  1717. {
  1718. function open()
  1719. {
  1720. '[native code]';
  1721. console.log('Site attempted to open a new window', arguments);
  1722. return {
  1723. document: {
  1724. write: () => {},
  1725. writeln: () => {}
  1726. }
  1727. };
  1728. }
  1729.  
  1730. function clickHandler(e)
  1731. {
  1732. let link = e.target;
  1733. if (!link.parentNode || !e.isTrusted ||
  1734. (link.href && link.href.trim().toLowerCase().indexOf('javascript') === 0))
  1735. {
  1736. e.preventDefault();
  1737. console.log('Blocked suspicious click event', e, 'on', e.target);
  1738. }
  1739. }
  1740.  
  1741. createWindowOpenWrapper(open, clickHandler);
  1742.  
  1743. console.log('Popup prevention enabled.');
  1744. }, [nullTools, createWindowOpenWrapper]
  1745. );
  1746. }
  1747.  
  1748. // Helper function to close background tab if site opens itself in a new tab and then
  1749. // loads a 3rd-party page in the background one (thus performing background redirect).
  1750. function preventPopunders()
  1751. {
  1752. // create "close_me" event to call high-level window.close()
  1753. let eventName = 'close_me_' + Math.random().toString(36).substr(2);
  1754. let callClose = () => (console.log('close call'), window.close());
  1755. window.addEventListener(eventName, callClose, true);
  1756.  
  1757. scriptLander(
  1758. function()
  1759. {
  1760. let _open = window.open,
  1761. parseURL = document.createElement('A');
  1762. // get host of a provided URL with help of an anchor object
  1763. // unfortunately new URL(url, window.location) generates wrong URL in some cases
  1764. let getHost = (url) => (parseURL.href = url, parseURL.host);
  1765. // site went to a new tab and attempts to unload
  1766. // call for high-level close through event
  1767. let closeWindow = () => window.dispatchEvent(new CustomEvent(eventName, {}));
  1768. // check is URL local or goes to different site
  1769. function isLocal(url)
  1770. {
  1771. let loc = window.location;
  1772. if (url === loc.pathname || url === loc.href)
  1773. return true; // URL points to current pathname or full address
  1774. let host = getHost(url),
  1775. site = loc.host;
  1776. if (host === '')
  1777. return false; // URLs with unusual protocol may have empty 'host'
  1778. if (host.length > site.length)
  1779. [site, host] = [host, site];
  1780. return site.includes(host, site.length - host.length);
  1781. }
  1782.  
  1783. function open(url)
  1784. {
  1785. '[native code]';
  1786. if (url && isLocal(url))
  1787. window.addEventListener('unload', closeWindow, true);
  1788. // jshint validthis:true
  1789. return _open.apply(this, arguments);
  1790. }
  1791.  
  1792. function clickHandler(e)
  1793. {
  1794. if (!e.target.parentNode || !e.isTrusted)
  1795. window.addEventListener('unload', closeWindow, true);
  1796. }
  1797.  
  1798. createWindowOpenWrapper(open, clickHandler);
  1799.  
  1800. console.log("Background redirect prevention enabled.");
  1801. }, [nullTools, createWindowOpenWrapper, 'let eventName="'+eventName+'"']
  1802. );
  1803. }
  1804.  
  1805. // Mix between check for popups and popunders
  1806. // Significantly more agressive than both and can't be used as universal solution
  1807. function preventPopMix()
  1808. {
  1809. if (inIFrame)
  1810. {
  1811. win.top.postMessage({ name: 'sandbox-me', href: win.location.href }, '*');
  1812. return;
  1813. }
  1814.  
  1815. // create "close_me" event to call high-level window.close()
  1816. let eventName = 'close_me_' + Math.random().toString(36).substr(2);
  1817. let callClose = () => (console.log('close call'), window.close());
  1818. window.addEventListener(eventName, callClose, true);
  1819.  
  1820. scriptLander(
  1821. function()
  1822. {
  1823. let _open = window.open,
  1824. parseURL = document.createElement('A');
  1825. // get host of a provided URL with help of an anchor object
  1826. // unfortunately new URL(url, window.location) generates wrong URL in some cases
  1827. let getHost = (url) => (parseURL.href = url, parseURL.host);
  1828. // site went to a new tab and attempts to unload
  1829. // call for high-level close through event
  1830. let closeWindow = () => (_open(window.location,'_self'), window.dispatchEvent(new CustomEvent(eventName, {})));
  1831. // check is URL local or goes to different site
  1832. function isLocal(url)
  1833. {
  1834. let loc = window.location;
  1835. if (url === loc.pathname || url === loc.href)
  1836. return true; // URL points to current pathname or full address
  1837. let host = getHost(url),
  1838. site = loc.host;
  1839. if (host === '')
  1840. return false; // URLs with unusual protocol may have empty 'host'
  1841. if (host.length > site.length)
  1842. [site, host] = [host, site];
  1843. return site.includes(host, site.length - host.length);
  1844. }
  1845.  
  1846. // add check for redirect for 5 seconds, then disable it
  1847. function checkRedirect()
  1848. {
  1849. window.addEventListener('unload', closeWindow, true);
  1850. setTimeout(closeWindow=>window.removeEventListener('unload', closeWindow, true), 5000, closeWindow);
  1851. }
  1852.  
  1853. function open(url, name)
  1854. {
  1855. '[native code]';
  1856. if (url && isLocal(url) && (!name || name === '_blank'))
  1857. {
  1858. console.trace('Suspicious local new window', arguments);
  1859. checkRedirect();
  1860. // jshint validthis:true
  1861. return _open.apply(this, arguments);
  1862. }
  1863. console.trace('Blocked attempt to open a new window', arguments);
  1864. return {
  1865. document: {
  1866. write: () => {},
  1867. writeln: () => {}
  1868. }
  1869. };
  1870. }
  1871.  
  1872. function clickHandler(e)
  1873. {
  1874. let link = e.target,
  1875. url = link.href||'';
  1876. if (e.targetParentNode && e.isTrusted || link.target !== '_blank')
  1877. {
  1878. console.log('Link', link, 'were created dinamically, but looks fine.');
  1879. return true;
  1880. }
  1881. if (isLocal(url) && link.target === '_blank')
  1882. {
  1883. console.log('Suspicious local link', link);
  1884. checkRedirect();
  1885. return;
  1886. }
  1887. console.log('Blocked suspicious click on a link', link);
  1888. e.stopPropagation();
  1889. e.preventDefault();
  1890. }
  1891.  
  1892. createWindowOpenWrapper(open, clickHandler);
  1893.  
  1894. console.log("Mixed popups prevention enabled.");
  1895. }, [createWindowOpenWrapper, 'let eventName="'+eventName+'"']
  1896. );
  1897. }
  1898. // External listener for case when site known to open popups were loaded in iframe
  1899. // It will sandbox any iframe which will send message 'forbid.popups' (preventPopups sends it)
  1900. // Some sites replace frame's window.location with data-url to run in clean context
  1901. if (!inIFrame)
  1902. {
  1903. window.addEventListener(
  1904. 'message', function(e)
  1905. {
  1906. if (!e.data || e.data.name !== 'sandbox-me' || !e.data.href)
  1907. return;
  1908. let src = e.data.href;
  1909. for (let frame of document.querySelectorAll('iframe'))
  1910. if (frame.contentWindow === e.source)
  1911. {
  1912. if (frame.hasAttribute('sandbox'))
  1913. {
  1914. if (!frame.sandbox.contains('allow-popups'))
  1915. return; // exit frame since it's already sandboxed and popups are blocked
  1916. // remove allow-popups if frame already sandboxed
  1917. frame.sandbox.remove('allow-popups');
  1918. } else {
  1919. // set sandbox mode for troublesome frame and allow scripts, forms and a few other actions
  1920. // technically allowing both scripts and same-origin allows removal of the sandbox attribute,
  1921. // but to apply content must be reloaded and this script will re-apply it in the result
  1922. frame.setAttribute('sandbox','allow-forms allow-scripts allow-presentation allow-top-navigation allow-same-origin');
  1923. }
  1924. console.log('Disallowed popups from iframe', frame);
  1925.  
  1926. // reload frame content to apply restrictions
  1927. if (!src) {
  1928. src = frame.src;
  1929. console.log('Unable to get current iframe location, reloading from src', src);
  1930. } else
  1931. console.log('Reloading iframe with URL', src);
  1932. frame.src = 'about:blank';
  1933. frame.src = src;
  1934. }
  1935. }, false
  1936. );
  1937. }
  1938.  
  1939. // === Scripts for specific domains ===
  1940.  
  1941. let scripts = {};
  1942. // prevent popups and redirects block
  1943. // Popups
  1944. scripts.preventPopups = {
  1945. other: [
  1946. 'biqle.ru',
  1947. 'chaturbate.com',
  1948. 'dfiles.ru',
  1949. 'hentaiz.org',
  1950. 'mirrorcreator.com',
  1951. 'online-multy.ru',
  1952. 'radikal.ru',
  1953. 'seedoff.cc', 'seedoff.tv',
  1954. 'tapochek.net', 'thepiratebay.org', 'torseed.net',
  1955. 'unionpeer.com',
  1956. 'zippyshare.com'
  1957. ],
  1958. now: preventPopups
  1959. };
  1960. // Popunders (background redirect)
  1961. scripts.preventPopunders = {
  1962. other: [
  1963. 'mediafire.com', 'megapeer.org', 'megapeer.ru',
  1964. 'perfectgirls.net'
  1965. ],
  1966. now: preventPopunders
  1967. };
  1968. // PopMix (both types of popups encountered on site)
  1969. scripts['openload.co'] = {
  1970. other: ['oload.tv', 'oload.info'],
  1971. now: () => {
  1972. let nt = new nullTools();
  1973. nt.define(win, 'CNight', win.CoinHive);
  1974. if (location.pathname.startsWith('/embed/'))
  1975. {
  1976. nt.define(win, 'BetterJsPop', {
  1977. add: ((a, b) => console.trace('BetterJsPop.add', a, b)),
  1978. config: ((o) => console.trace('BetterJsPop.config', o)),
  1979. Browser: { isChrome: true }
  1980. });
  1981. nt.define(win, 'isSandboxed', nt.func(null));
  1982. nt.define(win, 'adblock', false);
  1983. nt.define(win, 'adblock2', false);
  1984. } else
  1985. preventPopMix();
  1986. }
  1987. };
  1988. scripts['turbobit.net'] = preventPopMix;
  1989.  
  1990. // other
  1991. scripts['2picsun.ru'] = {
  1992. other: [
  1993. 'pics2sun.ru', '3pics-img.ru'
  1994. ],
  1995. now: () => {
  1996. Object.defineProperty(navigator, 'userAgent', {value: 'googlebot'});
  1997. }
  1998. };
  1999.  
  2000. scripts['4pda.ru'] = {
  2001. now: () => {
  2002. // https://gf.qytechs.cn/en/scripts/14470-4pda-unbrender
  2003. let hStyle,
  2004. isForum = document.location.href.search('/forum/') !== -1,
  2005. remove = (node) => (node ? node.parentNode.removeChild(node) : null),
  2006. afterClean = () => remove(hStyle);
  2007.  
  2008. function beforeClean()
  2009. {
  2010. // attach styles before document displayed
  2011. hStyle = createStyle([
  2012. 'html { overflow-y: scroll }',
  2013. 'section[id] {'+(
  2014. 'position: absolute;'+
  2015. 'width: 100%'
  2016. )+'}',
  2017. 'article + aside * { display: none !important }',
  2018. '#header + div:after {'+(
  2019. 'content: "";'+
  2020. 'position: fixed;'+
  2021. 'top: 0;'+
  2022. 'left: 0;'+
  2023. 'width: 100%;'+
  2024. 'height: 100%;'+
  2025. 'background-color: #E6E7E9'
  2026. )+'}',
  2027. // http://codepen.io/Beaugust/pen/DByiE
  2028. '@keyframes spin { 100% { transform: rotate(360deg) } }',
  2029. 'article + aside:after {'+(
  2030. 'content: "";'+
  2031. 'position: absolute;'+
  2032. 'width: 150px;'+
  2033. 'height: 150px;'+
  2034. 'top: 150px;'+
  2035. 'left: 50%;'+
  2036. 'margin-top: -75px;'+
  2037. 'margin-left: -75px;'+
  2038. 'box-sizing: border-box;'+
  2039. 'border-radius: 100%;'+
  2040. 'border: 10px solid rgba(0, 0, 0, 0.2);'+
  2041. 'border-top-color: rgba(0, 0, 0, 0.6);'+
  2042. 'animation: spin 2s infinite linear'
  2043. )+'}'
  2044. ], {id:'ubrHider'}, true);
  2045.  
  2046. // display content of a page if time to load a page is more than 2 seconds to avoid
  2047. // blocking access to a page if it is loading for too long or stuck in a loading state
  2048. setTimeout(2000, afterClean);
  2049. }
  2050.  
  2051. createStyle([
  2052. '#nav .use-ad { display: block !important }',
  2053. 'article:not(.post) + article:not(#id),'+
  2054. 'html:not(#id)>body:not(#id) a[target="_blank"] img[height="90"] { display: none !important }'
  2055. ]);
  2056.  
  2057. if (!isForum)
  2058. beforeClean();
  2059.  
  2060. // save links to non-overridden functions to use later
  2061. let protectedElems;
  2062. // protect/hide changed attributes in case site attempt to restore them
  2063. function styleProtector(eventMode)
  2064. {
  2065. let _toLowerCase = String.prototype.toLowerCase,
  2066. isStyleText = (t) => (_toLowerCase.call(t) === 'style'),
  2067. protectedElems = new WeakMap();
  2068. function protoOverride(element, functionName, isStyleCheck, returnIfProtected)
  2069. {
  2070. let originalFunction = element.prototype[functionName];
  2071. element.prototype[functionName] = function wrapper()
  2072. {
  2073. if (protectedElems.has(this) && isStyleCheck(arguments[0]))
  2074. return returnIfProtected(this, arguments);
  2075. return originalFunction.apply(this, arguments);
  2076. };
  2077. }
  2078. protoOverride(Element, 'removeAttribute', isStyleText, () => undefined);
  2079. protoOverride(Element, 'hasAttribute', isStyleText, (_this) => protectedElems.get(_this) !== null);
  2080. protoOverride(Element, 'setAttribute', isStyleText, (_this, args) => protectedElems.set(_this, args[1]));
  2081. protoOverride(Element, 'getAttribute', isStyleText, (_this) => protectedElems.get(_this));
  2082. if (!eventMode)
  2083. return protectedElems;
  2084. else
  2085. {
  2086. let e = document.createEvent('Event');
  2087. e.initEvent('protoOverride', false, false);
  2088. window.protectedElems = protectedElems;
  2089. window.dispatchEvent(e);
  2090. }
  2091. }
  2092. if (!isFirefox)
  2093. protectedElems = styleProtector(false);
  2094. else
  2095. {
  2096. let script = document.createElement('script');
  2097. script.textContent = '(' + styleProtector.toString() + ')(true);';
  2098. window.addEventListener(
  2099. 'protoOverride', function protoOverrideCallback(e)
  2100. {
  2101. if (win.protectedElems) {
  2102. protectedElems = win.protectedElems;
  2103. delete win.protectedElems;
  2104. }
  2105. document.removeEventListener('protoOverride', protoOverrideCallback, true);
  2106. }, true
  2107. );
  2108. _appendChild(script);
  2109. _removeChild(script);
  2110. }
  2111.  
  2112. // clean a page
  2113. window.addEventListener(
  2114. 'DOMContentLoaded', function()
  2115. {
  2116. let width = () => window.innerWidth || _de.clientWidth || document.body.clientWidth || 0;
  2117. let height = () => window.innerHeight || _de.clientHeight || document.body.clientHeight || 0;
  2118.  
  2119. if (isForum)
  2120. {
  2121. let si = document.querySelector('#logostrip');
  2122. if (si)
  2123. remove(si.parentNode.nextSibling);
  2124. }
  2125.  
  2126. if (document.location.href.search('/forum/dl/') !== -1) {
  2127. document.body.setAttribute('style', (document.body.getAttribute('style')||'')+
  2128. ';background-color:black!important');
  2129. for (let itm of document.querySelectorAll('body>div'))
  2130. if (!itm.querySelector('.dw-fdwlink'))
  2131. remove(itm);
  2132. }
  2133.  
  2134. if (isForum) // Do not continue if it's a forum
  2135. return;
  2136.  
  2137. {
  2138. let si = document.querySelector('#header');
  2139. if (si)
  2140. {
  2141. let rem = si.previousSibling;
  2142. while (rem)
  2143. {
  2144. si = rem.previousSibling;
  2145. remove(rem);
  2146. rem = si;
  2147. }
  2148. }
  2149. }
  2150.  
  2151. for (let itm of document.querySelectorAll('#nav li[class]'))
  2152. if (itm && itm.querySelector('a[href^="/tag/"]'))
  2153. remove(itm);
  2154.  
  2155. let style, result,
  2156. fakeStyles = new WeakMap(),
  2157. styleProxy = {
  2158. get: function(target, prop)
  2159. {
  2160. let fakeStyle = fakeStyles.get(target);
  2161. return ((prop in fakeStyle) ? fakeStyle : target)[prop];
  2162. },
  2163. set: function(target, prop, value)
  2164. {
  2165. let fakeStyle = fakeStyles.get(target);
  2166. ((prop in fakeStyle) ? fakeStyle : target)[prop] = value;
  2167. return true;
  2168. }
  2169. };
  2170. for (let itm of document.querySelectorAll('DIV, A'))
  2171. {
  2172. if (itm.tagName ==='DIV' &&
  2173. itm.offsetWidth > 0.95 * width() &&
  2174. itm.offsetHeight > 0.85 * height())
  2175. {
  2176. style = window.getComputedStyle(itm, null);
  2177. result = [];
  2178.  
  2179. if (style.backgroundImage !== 'none')
  2180. result.push('background-image:none!important');
  2181.  
  2182. if (style.backgroundColor !== 'transparent' &&
  2183. style.backgroundColor !== 'rgba(0, 0, 0, 0)')
  2184. result.push('background-color:transparent!important');
  2185.  
  2186. if (result.length)
  2187. {
  2188. if (itm.getAttribute('style'))
  2189. result.unshift(itm.getAttribute('style'));
  2190.  
  2191. fakeStyles.set(itm.style, {
  2192. 'backgroundImage': itm.style.backgroundImage,
  2193. 'backgroundColor': itm.style.backgroundColor
  2194. });
  2195.  
  2196. try {
  2197. Object.defineProperty(itm, 'style', {
  2198. value: new Proxy(itm.style, styleProxy),
  2199. enumerable: true
  2200. });
  2201. } catch (e) {
  2202. console.log('Unable to protect style property.', e);
  2203. }
  2204.  
  2205. if (protectedElems)
  2206. protectedElems.set(itm, _getAttribute.call(itm, 'style'));
  2207.  
  2208. _setAttribute.call(itm, 'style', result.join(';'));
  2209. }
  2210. }
  2211. if (itm.tagName ==='A' &&
  2212. (itm.offsetWidth > 0.95 * width() ||
  2213. itm.offsetHeight > 0.85 * height()))
  2214. {
  2215. if (protectedElems)
  2216. protectedElems.set(itm, _getAttribute.call(itm, 'style'));
  2217.  
  2218. _setAttribute.call(itm, 'style', 'display:none!important');
  2219. }
  2220. }
  2221.  
  2222. for (let itm of document.querySelectorAll('ASIDE>DIV'))
  2223. if ( ((itm.querySelector('script, iframe, a[href*="/ad/www/"]') ||
  2224. itm.querySelector('img[src$=".gif"]:not([height="0"]), img[height="400"]')) &&
  2225. !itm.classList.contains('post') ) || !itm.childNodes.length )
  2226. remove(itm);
  2227.  
  2228. document.body.setAttribute('style', (document.body.getAttribute('style')||'')+';background-color:#E6E7E9!important');
  2229.  
  2230. // display content of the page
  2231. afterClean();
  2232. }
  2233. );
  2234. }
  2235. };
  2236.  
  2237. scripts['allmovie.pro'] = {
  2238. other: ['rufilmtv.org'],
  2239. dom: function()
  2240. {
  2241. // pretend to be Android to make site use different played for ads
  2242. if (isSafari)
  2243. return;
  2244. Object.defineProperty(navigator, 'userAgent', {
  2245. 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'; },
  2246. enumerable: true
  2247. });
  2248. }
  2249. };
  2250.  
  2251. scripts['anidub-online.ru'] = {
  2252. other: ['online.anidub.com'],
  2253. dom: function()
  2254. {
  2255. if (win.ogonekstart1)
  2256. win.ogonekstart1 = () => console.log("Fire in the hole!");
  2257. },
  2258. now: () => createStyle([
  2259. '.background {background: none!important;}',
  2260. '.background > script + div,'+
  2261. '.background > script ~ div:not([id]):not([class]) + div[id][class]'+
  2262. '{display:none!important}'
  2263. ])
  2264. };
  2265.  
  2266. scripts['drive2.ru'] = () => gardener('.c-block:not([data-metrika="recomm"]),.o-grid__item', />Реклама<\//i);
  2267.  
  2268. scripts['fishki.net'] = () => gardener('.drag_list > .drag_element, .list-view > .paddingtop15, .post-wrap', /543769|Новости\sпартнеров|Полезная\sреклама/);
  2269.  
  2270. scripts['gidonline.club'] = () => createStyle('.tray > div[style] {display: none!important}');
  2271.  
  2272. scripts['hdgo.cc'] = {
  2273. other: ['46.30.43.38', 'couber.be'],
  2274. now: () => (new MutationObserver(
  2275. function(ms)
  2276. {
  2277. let m, node;
  2278. for (m of ms) for (node of m.addedNodes)
  2279. if (node.tagName === 'SCRIPT' && _getAttribute.call(node, 'onerror') !== null)
  2280. node.removeAttribute('onerror');
  2281. }
  2282. )).observe(document.documentElement, { childList:true, subtree: true })
  2283. };
  2284.  
  2285. scripts['gismeteo.ru'] = {
  2286. other: ['gismeteo.ua'],
  2287. now: () => gardener('div > script', /AdvManager/i, { root: 'body', observe: true, parent: 'div'})
  2288. };
  2289.  
  2290. scripts['hdrezka.ag'] = () => {
  2291. Object.defineProperty(win, 'ab', { value: false, enumerable: true });
  2292. gardener('div[id][onclick][onmouseup][onmousedown]', /onmouseout/i);
  2293. };
  2294.  
  2295. scripts['imageban.ru'] = {
  2296. now: preventPopunders,
  2297. dom: () => win.addEventListener('unload', () => location.hash = 'x'+Math.random().toString(36).substr(2), true)
  2298. };
  2299.  
  2300. scripts['mail.ru'] = {
  2301. now: () => {
  2302. // Trick to prevent mail.ru from removing 3rd-party styles
  2303. scriptLander(
  2304. () => {
  2305. Object.defineProperty(Object.prototype, 'restoreVisibility', {
  2306. get: () => (() => null),
  2307. set: () => undefined
  2308. });
  2309.  
  2310. if (location.hostname !== 'e.mail.ru')
  2311. return;
  2312. let locator;
  2313. let fishnet = {
  2314. apply: (target, thisArg, args) => {
  2315. console.log(`locator.${target._name}(${JSON.stringify(args).slice(1,-1)})`);
  2316. return target.apply(thisArg, args);
  2317. }
  2318. };
  2319. Object.defineProperty(win, 'locator', {
  2320. set: function(l)
  2321. {
  2322. if ('setup' in l)
  2323. {
  2324. let _setup = l.setup;
  2325. l.setup = function(o)
  2326. {
  2327. for (let name in o)
  2328. switch(name) {
  2329. case 'enable':
  2330. o[name] = false;
  2331. console.log('Disable mimic mode.');
  2332. break;
  2333. case 'links':
  2334. o[name] = [];
  2335. console.log('Call with empty list of sheets.');
  2336. break;
  2337. default:
  2338. console.log(`Skipped unknown setup property '${name}'.`);
  2339. }
  2340. return _setup.call(this, o);
  2341. };
  2342. }
  2343. try {
  2344. for (let name in l)
  2345. if (l[name] instanceof Function) {
  2346. l[name]._name = name;
  2347. l[name] = new Proxy(l[name], fishnet);
  2348. console.log(`wrapped locator.${name}`);
  2349. }
  2350. } catch(e) {
  2351. console.log(e);
  2352. }
  2353. locator = l;
  2354. },
  2355. get: () => locator
  2356. });
  2357. }
  2358. );
  2359. }
  2360. };
  2361.  
  2362. scripts['megogo.net'] = {
  2363. now: () => {
  2364. let nt = new nullTools();
  2365. nt.define(win, 'adBlock', false);
  2366. nt.define(win, 'showAdBlockMessage', nt.func(null));
  2367. }
  2368. };
  2369.  
  2370. scripts['naruto-base.su'] = () => gardener('div[id^="entryID"],.block', /href="http.*?target="_blank"/i);
  2371.  
  2372. scripts['overclockers.ru'] = {
  2373. now: () => {
  2374. createStyle('.fixoldhtml {display:block!important}');
  2375. if (!isChrome && !isOpera)
  2376. return; // Looks like my code works only in Chrome-like browsers
  2377. let noContentYet = true;
  2378. function jWrap()
  2379. {
  2380. win.$ = new Proxy(
  2381. win.$, {
  2382. apply: function(_$, _this, args)
  2383. {
  2384. let _ret = _$.apply(_this, args);
  2385. if (_ret[0] === document.body)
  2386. _ret.html = () => console.log('Anti-adblock prevented.');
  2387. return _ret;
  2388. }
  2389. }
  2390. );
  2391. win.jQuery = win.$;
  2392. }
  2393. (function jReady()
  2394. {
  2395. if (!win.$ && noContentYet)
  2396. setTimeout(jReady, 0);
  2397. else
  2398. jWrap();
  2399. })();
  2400. document.addEventListener ('DOMContentLoaded', () => (noContentYet = false), false);
  2401. }
  2402. };
  2403. scripts['forums.overclockers.ru'] = {
  2404. now: () => {
  2405. createStyle('.needblock {position: fixed; left: -10000px}');
  2406. Object.defineProperty(win, 'adblck', {
  2407. get: () => 'no',
  2408. set: () => undefined,
  2409. enumerable: true
  2410. });
  2411. }
  2412. };
  2413.  
  2414. scripts['pb.wtf'] = {
  2415. other: ['piratbit.org', 'piratbit.ru'],
  2416. now: () => {
  2417. // line above topic content and images in the slider in the header
  2418. gardener(
  2419. 'a[href^="/exit/"], a[href^="/fxt/"], a[href$="=="]',
  2420. /img|Реклама|center/i,
  2421. { root: '.release-navbar,#page_content', observe: true, parent: 'div,tr' }
  2422. );
  2423. // ads in comments
  2424. gardener('img[data-name="PiraBo"]', /./i, {root:'#main_content .table', observe:true, parent:'tr'});
  2425. }
  2426. };
  2427.  
  2428. scripts['pikabu.ru'] = () => gardener('.story', /story__sponsor|story__gag|profile\/ads"/i, {root: '.inner_wrap', observe: true});
  2429.  
  2430. scripts['qrz.ru'] = {
  2431. now: () => {
  2432. let nt = new nullTools();
  2433. nt.define(win, 'ab', false);
  2434. nt.define(win, 'tryMessage', nt.func(null));
  2435. }
  2436. };
  2437.  
  2438. scripts['razlozhi.ru'] = {
  2439. now: () => {
  2440. for (let func of ['createShadowRoot', 'attachShadow'])
  2441. if (func in Element.prototype)
  2442. Element.prototype[func] = function(){ return this.cloneNode(); };
  2443. }
  2444. };
  2445.  
  2446. scripts['rbc.ru'] = {
  2447. dom: () => {
  2448. let _preventDefault = Event.prototype.preventDefault;
  2449. Event.prototype.preventDefault = function preventDefault()
  2450. {
  2451. let t = this.target;
  2452. if (t instanceof HTMLAnchorElement || t.closest('A'))
  2453. throw new Error('an.yandex redirect prevention');
  2454. return _preventDefault.call(this);
  2455. };
  2456.  
  2457. function cleaner(nodes)
  2458. {
  2459. for (let node of nodes)
  2460. {
  2461. if (!node.classList || !node.classList.contains('js-yandex-counter'))
  2462. continue;
  2463. node.classList.remove('js-yandex-counter');
  2464. node.removeAttribute('data-yandex-name');
  2465. node.removeAttribute('data-yandex-params');
  2466. }
  2467. }
  2468. cleaner(_de.querySelectorAll('.js-yandex-counter'));
  2469.  
  2470. (new MutationObserver(
  2471. ms => { for (let m of ms) cleaner(m.addedNodes); }
  2472. )).observe(_de, {childList: true, subtree: true});
  2473. }
  2474. };
  2475.  
  2476. scripts['rp5.ru'] = {
  2477. other: ['rp5.by', 'rp5.kz', 'rp5.ua'],
  2478. dom: () => {
  2479. createStyle('#bannerBottom {display: none!important}');
  2480. let co = document.querySelector('#content');
  2481. if (!co)
  2482. return;
  2483. let nodes = co.children;
  2484. let i = nodes.length;
  2485. while(i--)
  2486. if (nodes[i].querySelector('a[href*="?AdvertMgmt="]'))
  2487. nodes[i].parentNode.removeChild(nodes[i]);
  2488. nodes = co.parentNode.children;
  2489. i = nodes.length;
  2490. while(i--)
  2491. if (nodes[i] !== co)
  2492. nodes[i].parentNode.removeChild(nodes[i]);
  2493. nodes = co.childNodes;
  2494. }
  2495. };
  2496.  
  2497. scripts['rustorka.com'] = {
  2498. other: ['rumedia.ws'],
  2499. now: () => {
  2500. createStyle('.header > div:not(.head-block) a, #sidebar1 img, #logo img {opacity:0!important}', {
  2501. id: 'tempHidingStyles'
  2502. }, true);
  2503. preventPopups();
  2504. },
  2505. dom: () => {
  2506. for (let o of document.querySelectorAll('IMG, A'))
  2507. if ((o.clientWidth === 728 && o.clientHeight === 90) ||
  2508. (o.clientWidth === 300 && o.clientHeight === 250))
  2509. {
  2510. while (o && o.tagName !== 'A')
  2511. o = o.parentNode;
  2512. if (o)
  2513. _setAttribute.call(o, 'style', 'display: none !important');
  2514. }
  2515. let s = document.querySelector('#tempHidingStyles');
  2516. s.parentNode.removeChild(s);
  2517. }
  2518. };
  2519.  
  2520. scripts['sport-express.ru'] = () => gardener('.js-relap__item',/>Реклама\s+<\//, {root:'.container', observe: true});
  2521.  
  2522. scripts['sports.ru'] = {
  2523. now: () => {
  2524. gardener('.aside-news-list__item', /aside-news-list__advert/i, {root:'.columns-layout__left', observe: true});
  2525. gardener('.material-list__item', /Реклама/i, {root:'.columns-layout', observe: true});
  2526. // extra functionality: shows/hides panel at the top depending on scroll direction
  2527. createStyle([
  2528. '.user-panel__fixed { transition: top 0.2s ease-in-out!important; }',
  2529. '.user-panel-up { top: -40px!important }'
  2530. ], {id: 'userPanelSlide'}, false);
  2531. },
  2532. dom: () => {
  2533. (function lookForPanel()
  2534. {
  2535. let panel = document.querySelector('.user-panel__fixed');
  2536. if (!panel)
  2537. setTimeout(lookForPanel, 100);
  2538. else
  2539. window.addEventListener(
  2540. 'wheel', function(e)
  2541. {
  2542. if (e.deltaY > 0 && !panel.classList.contains('user-panel-up'))
  2543. panel.classList.add('user-panel-up');
  2544. else if (e.deltaY < 0 && panel.classList.contains('user-panel-up'))
  2545. panel.classList.remove('user-panel-up');
  2546. }, false
  2547. );
  2548. })();
  2549. }
  2550. };
  2551.  
  2552. scripts['vk.com'] = () => gardener((
  2553. '#wk_content > #wl_post > div,'+
  2554. '#page_wall_posts > div[id^="post-"],'+
  2555. 'div[class^="feed_row "] > div[id^="post-"],'+
  2556. 'div[class^="feed_row "] > div[id^="feed_repost-"]'
  2557. ), /wall_marked_as_ads/, {root: 'body', observe: true});
  2558.  
  2559. scripts['yap.ru'] = {
  2560. other: ['yaplakal.com'],
  2561. now: () => {
  2562. gardener('form > table[id^="p_row_"]:nth-of-type(2)', /member1438|Administration/);
  2563. gardener('.icon-comments', /member1438|Administration|\/go\/\?http/, {parent:'tr', siblings:-2});
  2564. }
  2565. };
  2566.  
  2567. scripts['rambler.ru'] = {
  2568. other: ['championat.com','gazeta.ru','media.eagleplatform.com','lenta.ru'],
  2569. now: () => scriptLander(
  2570. () => {
  2571. if (location.hostname.endsWith('.media.eagleplatform.com'))
  2572. return;
  2573. let _cssText = Object.getOwnPropertyDescriptor(CSSRule.prototype, 'cssText');
  2574. let _cssText_get = _cssText.get;
  2575. _cssText.configurable = false;
  2576. _cssText.get = function()
  2577. {
  2578. let cssText = _cssText_get.call(this);
  2579. if (cssText.includes('content:'))
  2580. {
  2581. console.log('Blocked access to suspicious cssText:', cssText.slice(0,60), '\u2026', cssText.length);
  2582. return null;
  2583. }
  2584. return cssText;
  2585. };
  2586. Object.defineProperty(CSSRule.prototype, 'cssText', _cssText);
  2587. // fake global Adf object
  2588. let nt = new nullTools();
  2589. nt.define(win, 'Adf', nt.proxy({
  2590. banner: nt.proxy({
  2591. sspScroll: nt.func(),
  2592. ssp: nt.func()
  2593. })
  2594. }));
  2595. // extra script to remove partner news on gazeta.ru
  2596. if (!location.hostname.includes('gazeta.ru'))
  2597. return;
  2598. (new MutationObserver(
  2599. (ms) => {
  2600. let m, node, header;
  2601. for (m of ms) for (node of m.addedNodes)
  2602. if (node instanceof HTMLDivElement && node.matches('.sausage'))
  2603. {
  2604. header = node.querySelector('.sausage-header');
  2605. if (header && /новости\s+партн[её]ров/i.test(header.textContent))
  2606. node.style.display = 'none';
  2607. }
  2608. }
  2609. )).observe(document.documentElement, { childList:true, subtree: true });
  2610. }, nullTools
  2611. ),
  2612. dom: () => {
  2613. // extra script to block video autoplay on Rambler domains
  2614. function unstopper(e, stopper, timeout)
  2615. {
  2616. if (timeout)
  2617. clearTimeout(timeout);
  2618. return setTimeout(
  2619. (e) => e.target.removeEventListener('playing', stopper, false),
  2620. 333, e
  2621. );
  2622. }
  2623. function stopper(e)
  2624. {
  2625. let timeout = unstopper(e, stopper);
  2626. e.target.addEventListener(
  2627. 'pause', function()
  2628. {
  2629. timeout = unstopper(e, stopper, timeout);
  2630. }, false
  2631. );
  2632. let btn = document.querySelector('.eplayer-skin-toggle-playing');
  2633. if (btn)
  2634. btn.click();
  2635. else
  2636. e.target.pause();
  2637. }
  2638. let observer = (new MutationObserver(
  2639. (ms) => {
  2640. for (let m of ms)
  2641. if (!m.target.appliedStopper)
  2642. {
  2643. m.target.appliedStopper = true;
  2644. m.target.addEventListener('playing', stopper, false);
  2645. }
  2646. }
  2647. ));
  2648. observer.observe(document.documentElement, { subtree: true, attributes: true, attributeFilter: ['autoplay'] });
  2649. }
  2650. };
  2651.  
  2652. scripts['reactor.cc'] = {
  2653. other: ['joyreactor.cc', 'pornreactor.cc'],
  2654. now: () => win.open = (function(){ throw new Error('Redirect prevention.'); }).bind(window),
  2655. click: function(e)
  2656. {
  2657. let node = e.target;
  2658. if (node.nodeType === Node.ELEMENT_NODE &&
  2659. node.style.position === 'absolute' &&
  2660. node.style.zIndex > 0)
  2661. node.parentNode.removeChild(node);
  2662. },
  2663. dom: function()
  2664. {
  2665. let words = new RegExp(
  2666. 'блокировщика рекламы'
  2667. .split('')
  2668. .map(function(e){return e+'[\u200b\u200c\u200d]*';})
  2669. .join('')
  2670. .replace(' ', '\\s*')
  2671. .replace(/[аоре]/g, function(e){return ['[аa]','[оo]','[рp]','[еe]']['аоре'.indexOf(e)];}),
  2672. 'i'),
  2673. can;
  2674. function deeper(spider)
  2675. {
  2676. let c, l, n;
  2677. if (words.test(spider.innerText))
  2678. {
  2679. if (spider.nodeType === Node.TEXT_NODE)
  2680. return true;
  2681. c = spider.childNodes;
  2682. l = c.length;
  2683. n = 0;
  2684. while(l--)
  2685. if (deeper(c[l]), can)
  2686. n++;
  2687. if (n > 0 && n === c.length && spider.offsetHeight < 750)
  2688. can.push(spider);
  2689. return false;
  2690. }
  2691. return true;
  2692. }
  2693. function probe()
  2694. {
  2695. if (words.test(document.body.innerText))
  2696. {
  2697. can = [];
  2698. deeper(document.body);
  2699. let i = can.length, spider;
  2700. while(i--) {
  2701. spider = can[i];
  2702. if (spider.offsetHeight > 10 && spider.offsetHeight < 750)
  2703. _setAttribute.call(spider, 'style', 'background:none!important');
  2704. }
  2705. }
  2706. }
  2707. (new MutationObserver(probe))
  2708. .observe(document, { childList:true, subtree:true });
  2709. }
  2710. };
  2711.  
  2712. scripts['auto.ru'] = () => {
  2713. let words = /Реклама|Яндекс.Директ|yandex_ad_/;
  2714. let userAdsListAds = (
  2715. '.listing-list > .listing-item,'+
  2716. '.listing-item_type_fixed.listing-item'
  2717. );
  2718. let catalogAds = (
  2719. 'div[class*="layout_catalog-inline"],'+
  2720. 'div[class$="layout_horizontal"]'
  2721. );
  2722. let otherAds = (
  2723. '.advt_auto,'+
  2724. '.sidebar-block,'+
  2725. '.pager-listing + div[class],'+
  2726. '.card > div[class][style],'+
  2727. '.sidebar > div[class],'+
  2728. '.main-page__section + div[class],'+
  2729. '.listing > tbody'
  2730. );
  2731. gardener(userAdsListAds, words, {root:'.listing-wrap', observe:true});
  2732. gardener(catalogAds, words, {root:'.catalog__page,.content__wrapper', observe:true});
  2733. gardener(otherAds, words);
  2734. };
  2735.  
  2736. scripts['rsload.net'] = {
  2737. load: () => {
  2738. let dis = document.querySelector('label[class*="cb-disable"]');
  2739. if (dis)
  2740. dis.click();
  2741. },
  2742. click: () => {
  2743. let t = e.target;
  2744. if (t && t.href && (/:\/\/\d+\.\d+\.\d+\.\d+\//.test(t.href)))
  2745. t.href = t.href.replace('://','://rsload.net:rsload.net@');
  2746. }
  2747. };
  2748.  
  2749. let domain, name;
  2750. // add alternative domain names if present and wrap functions into objects
  2751. for (name in scripts)
  2752. {
  2753. if (scripts[name] instanceof Function)
  2754. scripts[name] = { now: scripts[name] };
  2755. for (domain of (scripts[name].other||[]))
  2756. {
  2757. if (domain in scripts)
  2758. console.log('Error in scripts list. Script for', name, 'replaced script for', domain);
  2759. scripts[domain] = scripts[name];
  2760. }
  2761. delete scripts[name].other;
  2762. }
  2763. // look for current domain in the list and run appropriate code
  2764. domain = document.domain;
  2765. while (domain.indexOf('.') > -1)
  2766. {
  2767. if (domain in scripts) for (name in scripts[domain])
  2768. switch(name)
  2769. {
  2770. case 'now':
  2771. scripts[domain][name]();
  2772. break;
  2773. case 'load':
  2774. window.addEventListener('load', scripts[domain][name], false);
  2775. break;
  2776. case 'dom':
  2777. document.addEventListener('DOMContentLoaded', scripts[domain][name], false);
  2778. break;
  2779. default:
  2780. document.addEventListener (name, scripts[domain][name], false);
  2781. }
  2782. domain = domain.slice(domain.indexOf('.') + 1);
  2783. }
  2784. })();

QingJ © 2025

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