RU AdList JS Fixes

try to take over the world!

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

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

QingJ © 2025

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