RU AdList JS Fixes

try to take over the world!

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

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

QingJ © 2025

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