RU AdList JS Fixes

try to take over the world!

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

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