RU AdList JS Fixes

try to take over the world!

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

  1. // ==UserScript==
  2. // @name RU AdList JS Fixes
  3. // @namespace ruadlist_js_fixes
  4. // @version 20170920.4
  5. // @description try to take over the world!
  6. // @author lainverse & dimisa
  7. // @match *://*/*
  8. // @grant unsafeWindow
  9. // @grant window.close
  10. // @grant GM_getValue
  11. // @grant GM_setValue
  12. // @run-at document-start
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17. let win = (unsafeWindow || window),
  18. // http://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser
  19. isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0,
  20. isChrome = !!window.chrome && !!window.chrome.webstore,
  21. isSafari = (Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0 ||
  22. (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window.safari || safari.pushNotification)),
  23. isFirefox = typeof InstallTrigger !== 'undefined',
  24. inIFrame = (win.self !== win.top),
  25. _getAttribute = Element.prototype.getAttribute,
  26. _setAttribute = Element.prototype.setAttribute,
  27. _de = document.documentElement,
  28. _appendChild = Document.prototype.appendChild.bind(_de),
  29. _removeChild = Document.prototype.removeChild.bind(_de),
  30. _createElement = Document.prototype.createElement.bind(document);
  31.  
  32. if (isFirefox && // Exit on image pages in Fx
  33. document.constructor.prototype.toString() === '[object ImageDocumentPrototype]')
  34. return;
  35.  
  36. // dTree 2.05 in some cases replaces Node object before my script kicks in :(
  37. if (!Node.prototype)
  38. {
  39. let ifr = _createElement('iframe');
  40. _appendChild(ifr);
  41. try {
  42. window.Node = ifr.contentWindow.Node;
  43. console.log('Node object restored. -_-');
  44. } catch(e) {
  45. console.log('Unable to restore Node object.', e);
  46. }
  47. _removeChild(ifr);
  48. }
  49.  
  50. // NodeList iterator polyfill (mostly for Safari)
  51. // https://jakearchibald.com/2014/iterators-gonna-iterate/
  52. if (!NodeList.prototype[Symbol.iterator]) {
  53. NodeList.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
  54. }
  55.  
  56. // Options
  57. let opts = {
  58. 'useWSIFunc': useWSI
  59. };
  60.  
  61. {
  62. let optsCall = function(callback)
  63. {
  64. // Register event listener
  65. let key = "optsCallEvent_" + Math.random().toString(36).substr(2),
  66. cb = callback.func.bind(callback.name);
  67. window.addEventListener(key, cb, false);
  68. // Generate and dispatch synthetic event
  69. let ev = document.createEvent("HTMLEvents");
  70. ev.initEvent(key, true, false);
  71. window.dispatchEvent(ev);
  72. // Remove listener
  73. window.removeEventListener(key, cb, false);
  74. };
  75.  
  76. let initOptsHandler = function()
  77. {
  78. opts[this] = GM_getValue(this, true);
  79. if (opts[this])
  80. opts[this+'Func']();
  81. };
  82.  
  83. optsCall({
  84. func: initOptsHandler,
  85. name: 'useWSI'
  86. });
  87.  
  88. // show options page
  89. let openOptions = function()
  90. {
  91. let ovl = _createElement('div'),
  92. inner = _createElement('div');
  93. ovl.style = (
  94. 'position: fixed;'+
  95. 'top:0; left:0;'+
  96. 'bottom: 0; right: 0;'+
  97. 'background: rgba(0,0,0,0.85);'+
  98. 'z-index: 2147483647;'+
  99. 'padding: 5em'
  100. );
  101. inner.style = (
  102. 'background: whitesmoke;'+
  103. 'font-size: 10pt;'+
  104. 'color: black;'+
  105. 'padding: 1em'
  106. );
  107. inner.textContent = 'JS Fixes Options: (reload page to apply)';
  108. inner.appendChild(_createElement('br'));
  109. inner.appendChild(_createElement('br'));
  110. ovl.addEventListener(
  111. 'click', function(e)
  112. {
  113. if (e.target === ovl) {
  114. ovl.parentNode.removeChild(ovl);
  115. e.preventDefault();
  116. }
  117. e.stopPropagation();
  118. }, false
  119. );
  120. // append checkbox with label function
  121. function addCheckbox(optName, optLabel)
  122. {
  123. let c = _createElement('input'),
  124. l = _createElement('label');
  125. c.type = 'checkbox';
  126. c.id = optName;
  127. optsCall({
  128. func: function()
  129. {
  130. c.checked = GM_getValue(this);
  131. },
  132. name: optName
  133. });
  134. c.addEventListener(
  135. 'click', function(e)
  136. {
  137. optsCall({
  138. func:function(){
  139. GM_setValue(this, e.target.checked);
  140. opts[this] = e.target.checked;
  141. },
  142. name:optName
  143. });
  144. }, true
  145. );
  146. l.textContent = optLabel;
  147. l.setAttribute('for', optName);
  148. inner.appendChild(c);
  149. inner.appendChild(l);
  150. inner.appendChild(_createElement('br'));
  151. }
  152. // append checkboxes
  153. addCheckbox('useWSI', 'Use WebSocket filter. Disable if experience problems with WebSocket connections.');
  154. document.body.appendChild(ovl);
  155. ovl.appendChild(inner);
  156. };
  157.  
  158. // monitor keys pressed for Ctrl+Alt+Shift+J > s > f code
  159. let opPos = 0, opKey = ['KeyJ','KeyS','KeyF'];
  160. document.addEventListener(
  161. 'keydown', function(e)
  162. {
  163. if ((e.code === opKey[opPos] || e.location) &&
  164. (!!opPos || e.altKey && e.ctrlKey && e.shiftKey))
  165. {
  166. opPos += e.location ? 0 : 1;
  167. e.stopPropagation();
  168. e.preventDefault();
  169. } else {
  170. opPos = 0;
  171. }
  172. if (opPos === opKey.length)
  173. {
  174. opPos = 0;
  175. openOptions();
  176. }
  177. }, false
  178. );
  179. }
  180.  
  181. // Special wrapper script to run scripts designed to override standard DOM functions
  182. // In Firefox appends supplied script to a page to make it run in page context and let
  183. // page content access overridden functions. In other browsers just run it as-is.
  184. function scriptLander(func, prepend)
  185. {
  186. if (!isFirefox)
  187. {
  188. func();
  189. return;
  190. }
  191. let script = _createElement('script');
  192. let inline = ['string', 'function'];
  193. script.textContent = '!function(){let win=window;' + (
  194. inline.includes(typeof prepend) && prepend ||
  195. prepend instanceof Array && prepend.join(';') || ''
  196. ) + ';!' + func + '();}();';
  197. _appendChild(script);
  198. _removeChild(script);
  199. }
  200.  
  201. function nullTools(log) {
  202. // jshint validthis:true
  203. let nt = this;
  204. function trace() { if (log) console.trace.apply(this, arguments); }
  205.  
  206. nt.define = function(obj, prop, val)
  207. {
  208. Object.defineProperty(
  209. obj, prop, {
  210. get: () => (trace('get', prop, 'of', obj, 'which is', val), val),
  211. set: (v) => (trace('set', prop, 'of', obj, 'to', v), 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://greasyfork.org/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://greasyfork.org/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://greasyfork.org/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://greasyfork.org/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://greasyfork.org/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. // narrow down scope to a specific element
  1560. if (params.root)
  1561. {
  1562. scope = scope.querySelector(params.root);
  1563. if (!scope) // exit if the root element is not present on the page
  1564. return 0;
  1565. if (params.log)
  1566. console.log('[g] scope', scope);
  1567. }
  1568. // add observe mode if required
  1569. if (params.observe)
  1570. {
  1571. if (typeof MutationObserver === 'function')
  1572. {
  1573. (new MutationObserver(
  1574. function(ms)
  1575. {
  1576. for (let m of ms) if (m.addedNodes.length)
  1577. scissors(selector, words, scope, params);
  1578. }
  1579. )).observe(scope, { childList:true, subtree: true });
  1580. if (params.log)
  1581. console.log('[g] observer enabled');
  1582. } else {
  1583. nonstop = true;
  1584. if (params.log)
  1585. console.log('[g] nonstop mode enabled');
  1586. }
  1587. }
  1588. // wait for a full page load to do one extra cut
  1589. win.addEventListener(
  1590. 'load', function()
  1591. {
  1592. if (params.log)
  1593. console.log('[g] onload cleanup');
  1594. scissors(selector, words, scope, params);
  1595. }
  1596. );
  1597. // do multiple cuts during page load until ads removed
  1598. function cut(sci, s, w, sc, p, i)
  1599. {
  1600. if (i > 0)
  1601. i -= 1;
  1602. if (i && !sci(s, w, sc, p))
  1603. setTimeout(cut, 100, sci, s, w, sc, p, i);
  1604. }
  1605. cut(scissors, selector, words, scope, params, (nonstop ? -1 : 30));
  1606. }
  1607.  
  1608. // wrap popular methods to open a new tab to catch specific behaviours
  1609. function createWindowOpenWrapper(openFunc, onClickFunc)
  1610. {
  1611. let _createElement = Document.prototype.createElement,
  1612. _appendChild = Element.prototype.appendChild;
  1613.  
  1614. function redefineOpen(obj)
  1615. {
  1616. Object.defineProperty(obj, 'open', {
  1617. get: () => openFunc,
  1618. set: (val) => val,
  1619. enumerable: true
  1620. });
  1621. }
  1622. redefineOpen(win);
  1623.  
  1624. Document.prototype.createElement = function createElement(name)
  1625. {
  1626. let el = _createElement.apply(this, arguments);
  1627. // click-dispatch check for Google Chrome and similar browsers
  1628. if (el instanceof HTMLAnchorElement)
  1629. el.addEventListener(
  1630. 'click', onClickFunc, false
  1631. );
  1632. // redefine window.open in first-party frames
  1633. if (el instanceof HTMLIFrameElement)
  1634. el.addEventListener(
  1635. 'load', function(e)
  1636. {
  1637. try {
  1638. redefineOpen(e.target.contentWindow);
  1639. } catch(ignore) {}
  1640. }, false
  1641. );
  1642. return el;
  1643. };
  1644.  
  1645. // wrap window.open in newly added first-party frames
  1646. Element.prototype.appendChild = function appendChild()
  1647. {
  1648. let el = _appendChild.apply(this, arguments);
  1649. if (el instanceof HTMLIFrameElement) {
  1650. try {
  1651. redefineOpen(el.contentWindow);
  1652. } catch(ignore) {}
  1653. }
  1654. return el;
  1655. };
  1656. }
  1657.  
  1658. // Function to catch and block various methods to open a new window with 3rd-party content.
  1659. // Some advertisement networks went way past simple window.open call to circumvent default popup protection.
  1660. // This funciton blocks window.open, ability to restore original window.open from an IFRAME object,
  1661. // ability to perform an untrusted (not initiated by user) click on a link, click on a link without a parent
  1662. // node or simply a link with piece of javascript code in the HREF attribute.
  1663. function preventPopups()
  1664. {
  1665. if (inIFrame)
  1666. {
  1667. win.top.postMessage({ name: 'sandbox-me', href: win.location.href }, '*');
  1668. return;
  1669. }
  1670.  
  1671. scriptLander(
  1672. function()
  1673. {
  1674. function open()
  1675. {
  1676. '[native code]';
  1677. console.log('Site attempted to open a new window', arguments);
  1678. return {
  1679. document: {
  1680. write: () => {},
  1681. writeln: () => {}
  1682. }
  1683. };
  1684. }
  1685.  
  1686. function clickHandler(e)
  1687. {
  1688. let link = e.target;
  1689. if (!link.parentNode || !e.isTrusted ||
  1690. (link.href && link.href.trim().toLowerCase().indexOf('javascript') === 0))
  1691. {
  1692. e.preventDefault();
  1693. console.log('Blocked suspicious click event', e, 'on', e.target);
  1694. }
  1695. }
  1696.  
  1697. createWindowOpenWrapper(open, clickHandler);
  1698.  
  1699. console.log('Popup prevention enabled.');
  1700. }, createWindowOpenWrapper
  1701. );
  1702. }
  1703.  
  1704. // Helper function to close background tab if site opens itself in a new tab and then
  1705. // loads a 3rd-party page in the background one (thus performing background redirect).
  1706. function preventPopunders()
  1707. {
  1708. // create "close_me" event to call high-level window.close()
  1709. let eventName = 'close_me_' + Math.random().toString(36).substr(2);
  1710. let callClose = () => (console.log('close call'), window.close());
  1711. window.addEventListener(eventName, callClose, true);
  1712.  
  1713. scriptLander(
  1714. function()
  1715. {
  1716. let _open = window.open,
  1717. parseURL = document.createElement('A');
  1718. // get host of a provided URL with help of an anchor object
  1719. // unfortunately new URL(url, window.location) generates wrong URL in some cases
  1720. let getHost = (url) => (parseURL.href = url, parseURL.host);
  1721. // site went to a new tab and attempts to unload
  1722. // call for high-level close through event
  1723. let closeWindow = () => window.dispatchEvent(new CustomEvent(eventName, {}));
  1724. // check is URL local or goes to different site
  1725. function isLocal(url)
  1726. {
  1727. let loc = window.location;
  1728. if (url === loc.pathname || url === loc.href)
  1729. return true; // URL points to current pathname or full address
  1730. let host = getHost(url),
  1731. site = loc.host;
  1732. if (host === '')
  1733. return false; // URLs with unusual protocol may have empty 'host'
  1734. if (host.length > site.length)
  1735. [site, host] = [host, site];
  1736. return site.includes(host, site.length - host.length);
  1737. }
  1738.  
  1739. function open(url)
  1740. {
  1741. '[native code]';
  1742. if (url && isLocal(url))
  1743. window.addEventListener('unload', closeWindow, true);
  1744. // jshint validthis:true
  1745. return _open.apply(this, arguments);
  1746. }
  1747.  
  1748. function clickHandler(e)
  1749. {
  1750. if (!e.target.parentNode || !e.isTrusted)
  1751. window.addEventListener('unload', closeWindow, true);
  1752. }
  1753.  
  1754. createWindowOpenWrapper(open, clickHandler);
  1755.  
  1756. console.log("Background redirect prevention enabled.");
  1757. }, [createWindowOpenWrapper, 'let eventName="'+eventName+'"']
  1758. );
  1759. }
  1760.  
  1761. // Mix between check for popups and popunders
  1762. // Significantly more agressive than both and can't be used as universal solution
  1763. function preventPopMix()
  1764. {
  1765. if (inIFrame)
  1766. {
  1767. win.top.postMessage({ name: 'sandbox-me', href: win.location.href }, '*');
  1768. return;
  1769. }
  1770.  
  1771. // create "close_me" event to call high-level window.close()
  1772. let eventName = 'close_me_' + Math.random().toString(36).substr(2);
  1773. let callClose = () => (console.log('close call'), window.close());
  1774. window.addEventListener(eventName, callClose, true);
  1775.  
  1776. scriptLander(
  1777. function()
  1778. {
  1779. let _open = window.open,
  1780. parseURL = document.createElement('A');
  1781. // get host of a provided URL with help of an anchor object
  1782. // unfortunately new URL(url, window.location) generates wrong URL in some cases
  1783. let getHost = (url) => (parseURL.href = url, parseURL.host);
  1784. // site went to a new tab and attempts to unload
  1785. // call for high-level close through event
  1786. let closeWindow = () => (_open(window.location,'_self'), window.dispatchEvent(new CustomEvent(eventName, {})));
  1787. // check is URL local or goes to different site
  1788. function isLocal(url)
  1789. {
  1790. let loc = window.location;
  1791. if (url === loc.pathname || url === loc.href)
  1792. return true; // URL points to current pathname or full address
  1793. let host = getHost(url),
  1794. site = loc.host;
  1795. if (host === '')
  1796. return false; // URLs with unusual protocol may have empty 'host'
  1797. if (host.length > site.length)
  1798. [site, host] = [host, site];
  1799. return site.includes(host, site.length - host.length);
  1800. }
  1801.  
  1802. // add check for redirect for 5 seconds, then disable it
  1803. function checkRedirect()
  1804. {
  1805. window.addEventListener('unload', closeWindow, true);
  1806. setTimeout(closeWindow=>window.removeEventListener('unload', closeWindow, true), 5000, closeWindow);
  1807. }
  1808.  
  1809. function open(url, name)
  1810. {
  1811. '[native code]';
  1812. if (url && isLocal(url) && (!name || name === '_blank'))
  1813. {
  1814. console.log('Suspicious local new window', arguments);
  1815. checkRedirect();
  1816. // jshint validthis:true
  1817. return _open.apply(this, arguments);
  1818. }
  1819. console.log('Blocked attempt to open a new window', arguments);
  1820. return {
  1821. document: {
  1822. write: () => {},
  1823. writeln: () => {}
  1824. }
  1825. };
  1826. }
  1827.  
  1828. function clickHandler(e)
  1829. {
  1830. let link = e.target,
  1831. url = link.href||'';
  1832. if (e.targetParentNode && e.isTrusted || link.target !== '_blank')
  1833. {
  1834. console.log('Link', link, 'were created dinamically, but looks fine.');
  1835. return true;
  1836. }
  1837. if (isLocal(url) && link.target === '_blank')
  1838. {
  1839. console.log('Suspicious local link', link);
  1840. checkRedirect();
  1841. return;
  1842. }
  1843. console.log('Blocked suspicious click on a link', link);
  1844. e.stopPropagation();
  1845. e.preventDefault();
  1846. }
  1847.  
  1848. createWindowOpenWrapper(open, clickHandler);
  1849.  
  1850. console.log("Mixed popups prevention enabled.");
  1851. }, [createWindowOpenWrapper, 'let eventName="'+eventName+'"']
  1852. );
  1853. }
  1854. // External listener for case when site known to open popups were loaded in iframe
  1855. // It will sandbox any iframe which will send message 'forbid.popups' (preventPopups sends it)
  1856. // Some sites replace frame's window.location with data-url to run in clean context
  1857. if (!inIFrame)
  1858. {
  1859. window.addEventListener(
  1860. 'message', function(e)
  1861. {
  1862. if (!e.data || e.data.name !== 'sandbox-me' || !e.data.href)
  1863. return;
  1864. let src = e.data.href;
  1865. for (let frame of document.querySelectorAll('iframe'))
  1866. if (frame.contentWindow === e.source)
  1867. {
  1868. if (frame.hasAttribute('sandbox'))
  1869. {
  1870. if (!frame.sandbox.has('allow-popups'))
  1871. return; // exit frame since it's already sandboxed and popups are blocked
  1872. // remove allow-popups if frame already sandboxed
  1873. frame.sandbox.remove('allow-popups');
  1874. } else {
  1875. // set sandbox mode for troublesome frame and allow scripts, forms and a few other actions
  1876. // technically allowing both scripts and same-origin allows removal of the sandbox attribute,
  1877. // but to apply content must be reloaded and this script will re-apply it in the result
  1878. frame.setAttribute('sandbox','allow-forms allow-scripts allow-presentation allow-top-navigation allow-same-origin');
  1879. }
  1880. console.log('Disallowed popups from iframe', frame);
  1881.  
  1882. // reload frame content to apply restrictions
  1883. if (!src) {
  1884. src = frame.src;
  1885. console.log('Unable to get current iframe location, reloading from src', src);
  1886. } else
  1887. console.log('Reloading iframe with URL', src);
  1888. frame.src = 'about:blank';
  1889. frame.src = src;
  1890. }
  1891. }, false
  1892. );
  1893. }
  1894.  
  1895. // === Scripts for specific domains ===
  1896.  
  1897. let scripts = {};
  1898. // prevent popups and redirects block
  1899. // Popups
  1900. scripts.preventPopups = {
  1901. other: [
  1902. 'biqle.ru',
  1903. 'chaturbate.com',
  1904. 'dfiles.ru',
  1905. 'hentaiz.org',
  1906. 'mirrorcreator.com',
  1907. 'online-multy.ru',
  1908. 'radikal.ru',
  1909. 'seedoff.cc', 'seedoff.tv',
  1910. 'tapochek.net', 'thepiratebay.org', 'torseed.net',
  1911. 'unionpeer.com',
  1912. 'zippyshare.com'
  1913. ],
  1914. now: preventPopups
  1915. };
  1916. // Popunders (background redirect)
  1917. scripts.preventPopunders = {
  1918. other: [
  1919. 'mediafire.com', 'megapeer.org', 'megapeer.ru',
  1920. 'perfectgirls.net'
  1921. ],
  1922. now: preventPopunders
  1923. };
  1924. // PopMix (both types of popups encountered on site)
  1925. scripts.preventPopMix = {
  1926. other: [
  1927. 'openload.co',
  1928. 'turbobit.net'
  1929. ],
  1930. now: preventPopMix
  1931. };
  1932.  
  1933. // other
  1934. scripts['2picsun.ru'] = {
  1935. other: [
  1936. 'pics2sun.ru', '3pics-img.ru'
  1937. ],
  1938. now: function() {
  1939. Object.defineProperty(navigator, 'userAgent', {value: 'googlebot'});
  1940. }
  1941. };
  1942.  
  1943. scripts['4pda.ru'] = {
  1944. now: function()
  1945. {
  1946. // https://greasyfork.org/en/scripts/14470-4pda-unbrender
  1947. let hStyle,
  1948. isForum = document.location.href.search('/forum/') !== -1,
  1949. remove = (node) => (node ? node.parentNode.removeChild(node) : null),
  1950. afterClean = () => remove(hStyle);
  1951.  
  1952. function beforeClean()
  1953. {
  1954. // attach styles before document displayed
  1955. hStyle = createStyle([
  1956. 'html { overflow-y: scroll }',
  1957. 'section[id] {'+(
  1958. 'position: absolute;'+
  1959. 'width: 100%'
  1960. )+'}',
  1961. 'article + aside * { display: none !important }',
  1962. '#header + div:after {'+(
  1963. 'content: "";'+
  1964. 'position: fixed;'+
  1965. 'top: 0;'+
  1966. 'left: 0;'+
  1967. 'width: 100%;'+
  1968. 'height: 100%;'+
  1969. 'background-color: #E6E7E9'
  1970. )+'}',
  1971. // http://codepen.io/Beaugust/pen/DByiE
  1972. '@keyframes spin { 100% { transform: rotate(360deg) } }',
  1973. 'article + aside:after {'+(
  1974. 'content: "";'+
  1975. 'position: absolute;'+
  1976. 'width: 150px;'+
  1977. 'height: 150px;'+
  1978. 'top: 150px;'+
  1979. 'left: 50%;'+
  1980. 'margin-top: -75px;'+
  1981. 'margin-left: -75px;'+
  1982. 'box-sizing: border-box;'+
  1983. 'border-radius: 100%;'+
  1984. 'border: 10px solid rgba(0, 0, 0, 0.2);'+
  1985. 'border-top-color: rgba(0, 0, 0, 0.6);'+
  1986. 'animation: spin 2s infinite linear'
  1987. )+'}'
  1988. ], {id:'ubrHider'}, true);
  1989.  
  1990. // display content of a page if time to load a page is more than 2 seconds to avoid
  1991. // blocking access to a page if it is loading for too long or stuck in a loading state
  1992. setTimeout(2000, afterClean);
  1993. }
  1994.  
  1995. createStyle([
  1996. '#nav .use-ad { display: block !important }',
  1997. 'article:not(.post) + article:not(#id),'+
  1998. 'html:not(#id)>body:not(#id) a[target="_blank"] img[height="90"] { display: none !important }'
  1999. ]);
  2000.  
  2001. if (!isForum)
  2002. beforeClean();
  2003.  
  2004. // save links to non-overridden functions to use later
  2005. let protectedElems;
  2006. // protect/hide changed attributes in case site attempt to restore them
  2007. function styleProtector(eventMode)
  2008. {
  2009. let _toLowerCase = String.prototype.toLowerCase,
  2010. isStyleText = (t) => (_toLowerCase.call(t) === 'style'),
  2011. protectedElems = new WeakMap();
  2012. function protoOverride(element, functionName, isStyleCheck, returnIfProtected)
  2013. {
  2014. let originalFunction = element.prototype[functionName];
  2015. element.prototype[functionName] = function wrapper()
  2016. {
  2017. if (protectedElems.has(this) && isStyleCheck(arguments[0]))
  2018. return returnIfProtected(this, arguments);
  2019. return originalFunction.apply(this, arguments);
  2020. };
  2021. }
  2022. protoOverride(Element, 'removeAttribute', isStyleText, () => undefined);
  2023. protoOverride(Element, 'hasAttribute', isStyleText, (_this) => protectedElems.get(_this) !== null);
  2024. protoOverride(Element, 'setAttribute', isStyleText, (_this, args) => protectedElems.set(_this, args[1]));
  2025. protoOverride(Element, 'getAttribute', isStyleText, (_this) => protectedElems.get(_this));
  2026. if (!eventMode)
  2027. return protectedElems;
  2028. else
  2029. {
  2030. let e = document.createEvent('Event');
  2031. e.initEvent('protoOverride', false, false);
  2032. window.protectedElems = protectedElems;
  2033. window.dispatchEvent(e);
  2034. }
  2035. }
  2036. if (!isFirefox)
  2037. protectedElems = styleProtector(false);
  2038. else
  2039. {
  2040. let script = document.createElement('script');
  2041. script.textContent = '(' + styleProtector.toString() + ')(true);';
  2042. window.addEventListener(
  2043. 'protoOverride', function protoOverrideCallback(e)
  2044. {
  2045. if (win.protectedElems) {
  2046. protectedElems = win.protectedElems;
  2047. delete win.protectedElems;
  2048. }
  2049. document.removeEventListener('protoOverride', protoOverrideCallback, true);
  2050. }, true
  2051. );
  2052. _appendChild(script);
  2053. _removeChild(script);
  2054. }
  2055.  
  2056. // clean a page
  2057. window.addEventListener(
  2058. 'DOMContentLoaded', function()
  2059. {
  2060. let width = () => window.innerWidth || _de.clientWidth || document.body.clientWidth || 0;
  2061. let height = () => window.innerHeight || _de.clientHeight || document.body.clientHeight || 0;
  2062.  
  2063. if (isForum)
  2064. {
  2065. let si = document.querySelector('#logostrip');
  2066. if (si)
  2067. remove(si.parentNode.nextSibling);
  2068. }
  2069.  
  2070. if (document.location.href.search('/forum/dl/') !== -1) {
  2071. document.body.setAttribute('style', (document.body.getAttribute('style')||'')+
  2072. ';background-color:black!important');
  2073. for (let itm of document.querySelectorAll('body>div'))
  2074. if (!itm.querySelector('.dw-fdwlink'))
  2075. remove(itm);
  2076. }
  2077.  
  2078. if (isForum) // Do not continue if it's a forum
  2079. return;
  2080.  
  2081. {
  2082. let si = document.querySelector('#header');
  2083. if (si)
  2084. {
  2085. let rem = si.previousSibling;
  2086. while (rem)
  2087. {
  2088. si = rem.previousSibling;
  2089. remove(rem);
  2090. rem = si;
  2091. }
  2092. }
  2093. }
  2094.  
  2095. for (let itm of document.querySelectorAll('#nav li[class]'))
  2096. if (itm && itm.querySelector('a[href^="/tag/"]'))
  2097. remove(itm);
  2098.  
  2099. let style, result,
  2100. fakeStyles = new WeakMap(),
  2101. styleProxy = {
  2102. get: function(target, prop)
  2103. {
  2104. let fakeStyle = fakeStyles.get(target);
  2105. return ((prop in fakeStyle) ? fakeStyle : target)[prop];
  2106. },
  2107. set: function(target, prop, value)
  2108. {
  2109. let fakeStyle = fakeStyles.get(target);
  2110. ((prop in fakeStyle) ? fakeStyle : target)[prop] = value;
  2111. return value;
  2112. }
  2113. };
  2114. for (let itm of document.querySelectorAll('DIV, A'))
  2115. {
  2116. if (itm.tagName ==='DIV' &&
  2117. itm.offsetWidth > 0.95 * width() &&
  2118. itm.offsetHeight > 0.85 * height())
  2119. {
  2120. style = window.getComputedStyle(itm, null);
  2121. result = [];
  2122.  
  2123. if (style.backgroundImage !== 'none')
  2124. result.push('background-image:none!important');
  2125.  
  2126. if (style.backgroundColor !== 'transparent' &&
  2127. style.backgroundColor !== 'rgba(0, 0, 0, 0)')
  2128. result.push('background-color:transparent!important');
  2129.  
  2130. if (result.length)
  2131. {
  2132. if (itm.getAttribute('style'))
  2133. result.unshift(itm.getAttribute('style'));
  2134.  
  2135. fakeStyles.set(itm.style, {
  2136. 'backgroundImage': itm.style.backgroundImage,
  2137. 'backgroundColor': itm.style.backgroundColor
  2138. });
  2139.  
  2140. try {
  2141. Object.defineProperty(itm, 'style', {
  2142. value: new Proxy(itm.style, styleProxy),
  2143. enumerable: true
  2144. });
  2145. } catch (e) {
  2146. console.log('Unable to protect style property.', e);
  2147. }
  2148.  
  2149. if (protectedElems)
  2150. protectedElems.set(itm, _getAttribute.call(itm, 'style'));
  2151.  
  2152. _setAttribute.call(itm, 'style', result.join(';'));
  2153. }
  2154. }
  2155. if (itm.tagName ==='A' &&
  2156. (itm.offsetWidth > 0.95 * width() ||
  2157. itm.offsetHeight > 0.85 * height()))
  2158. {
  2159. if (protectedElems)
  2160. protectedElems.set(itm, _getAttribute.call(itm, 'style'));
  2161.  
  2162. _setAttribute.call(itm, 'style', 'display:none!important');
  2163. }
  2164. }
  2165.  
  2166. for (let itm of document.querySelectorAll('ASIDE>DIV'))
  2167. if ( ((itm.querySelector('script, iframe, a[href*="/ad/www/"]') ||
  2168. itm.querySelector('img[src$=".gif"]:not([height="0"]), img[height="400"]')) &&
  2169. !itm.classList.contains('post') ) || !itm.childNodes.length )
  2170. remove(itm);
  2171.  
  2172. document.body.setAttribute('style', (document.body.getAttribute('style')||'')+';background-color:#E6E7E9!important');
  2173.  
  2174. // display content of the page
  2175. afterClean();
  2176. }
  2177. );
  2178. }
  2179. };
  2180.  
  2181. scripts['allmovie.pro'] = {
  2182. other: ['rufilmtv.org'],
  2183. dom: function()
  2184. {
  2185. // pretend to be Android to make site use different played for ads
  2186. if (isSafari)
  2187. return;
  2188. Object.defineProperty(navigator, 'userAgent', {
  2189. 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'; },
  2190. enumerable: true
  2191. });
  2192. }
  2193. };
  2194.  
  2195. scripts['anidub-online.ru'] = {
  2196. other: ['online.anidub.com'],
  2197. dom: function()
  2198. {
  2199. if (win.ogonekstart1)
  2200. win.ogonekstart1 = () => console.log("Fire in the hole!");
  2201. },
  2202. now: () => createStyle([
  2203. '.background {background: none!important;}',
  2204. '.background > script + div,'+
  2205. '.background > script ~ div:not([id]):not([class]) + div[id][class]'+
  2206. '{display:none!important}'
  2207. ])
  2208. };
  2209.  
  2210. scripts['drive2.ru'] = () => gardener('.c-block:not([data-metrika="recomm"]),.o-grid__item', />Реклама<\//i);
  2211.  
  2212. scripts['fishki.net'] = () => gardener('.drag_list > .drag_element, .list-view > .paddingtop15, .post-wrap', /543769|Новости\sпартнеров|Полезная\sреклама/);
  2213.  
  2214. scripts['gidonline.club'] = {
  2215. now: () => createStyle('.tray > div[style] {display: none!important}')
  2216. };
  2217.  
  2218. scripts['hdgo.cc'] = {
  2219. other: ['46.30.43.38', 'couber.be'],
  2220. now: () => (new MutationObserver(
  2221. function(ms)
  2222. {
  2223. let m, node;
  2224. for (m of ms) for (node of m.addedNodes)
  2225. if (node.tagName === 'SCRIPT' && _getAttribute.call(node, 'onerror') !== null)
  2226. node.removeAttribute('onerror');
  2227. }
  2228. )).observe(document.documentElement, { childList:true, subtree: true })
  2229. };
  2230.  
  2231. scripts['gismeteo.ru'] = {
  2232. other: ['gismeteo.ua'],
  2233. dom: () => gardener('div > a[target^="_"]', /Яндекс\.Директ/i, { root: 'body', observe: true, parent: 'div[class*="frame"]'})
  2234. };
  2235.  
  2236. scripts['hdrezka.me'] = {
  2237. now: function()
  2238. {
  2239. Object.defineProperty(win, 'ab', {
  2240. value: false,
  2241. enumerable: true
  2242. });
  2243. },
  2244. dom: () => gardener('div[id][onclick][onmouseup][onmousedown]', /onmouseout/i)
  2245. };
  2246.  
  2247. scripts['imageban.ru'] = {
  2248. now: preventPopunders,
  2249. dom: () => win.addEventListener(
  2250. 'unload', function()
  2251. {
  2252. window.location.hash = 'x'+Math.random().toString(36).substr(2);
  2253. }, true
  2254. )
  2255. };
  2256.  
  2257. scripts['mail.ru'] = {
  2258. now: function()
  2259. {
  2260. // Trick to prevent mail.ru from removing 3rd-party styles
  2261. scriptLander(
  2262. () => Object.defineProperty(Object.prototype, 'restoreVisibility', {
  2263. get: () => (() => null),
  2264. set: () => null
  2265. })
  2266. );
  2267. /* Experimental code, disabled for end users for now
  2268. // Ads removal on e.mail.ru
  2269. if (window.location.hostname === 'e.mail.ru')
  2270. {
  2271. let selector = (
  2272. '.b-datalist div[class]:not([id]) > div[class]:not([class*="js-"]),'+
  2273. '.b-letter div[class]:not([id]) > div[class]:not([class*="js-"]):not([class*="drop"]):not([class*="letter"]):not([style]):not([id]),'+
  2274. 'div[id]:not([class]) > div[id][class]:not([class*="js-"]):not([class*="drop"]):not([style])'
  2275. );
  2276. let janitor = function(nodes)
  2277. {
  2278. let color;
  2279. for (let node of nodes)
  2280. {
  2281. if (node.nodeType !== Node.ELEMENT_NODE)
  2282. continue;
  2283. color = window.getComputedStyle(node).backgroundColor;
  2284. if (/^rgb\(/.test(color) && color !== 'rgb(255, 255, 255)')
  2285. {
  2286. node.style.display = 'none';
  2287. console.log('Hide node:', node);
  2288. }
  2289. }
  2290. };
  2291. janitor(document.querySelectorAll(selector));
  2292. (new MutationObserver(
  2293. function(ms)
  2294. {
  2295. for (let m of ms)
  2296. janitor(m.addedNodes);
  2297. }
  2298. )).observe(
  2299. document.documentElement, {
  2300. childList: true,
  2301. subtree: true
  2302. }
  2303. );
  2304. }
  2305. /**/
  2306. }
  2307. };
  2308.  
  2309. scripts['megogo.net'] = {
  2310. now: function()
  2311. {
  2312. Object.defineProperty(win, "adBlock", {
  2313. get: () => false,
  2314. set: () => null,
  2315. enumerable : true
  2316. });
  2317. Object.defineProperty(win, "showAdBlockMessage", {
  2318. get: () => (() => null),
  2319. set: () => null,
  2320. enumerable: true
  2321. });
  2322. }
  2323. };
  2324.  
  2325. scripts['naruto-base.su'] = () => gardener('div[id^="entryID"],.block', /href="http.*?target="_blank"/i);
  2326.  
  2327. scripts['overclockers.ru'] = {
  2328. now: function()
  2329. {
  2330. createStyle('.fixoldhtml {display:block!important}');
  2331. if (!isChrome && !isOpera)
  2332. return; // Looks like my code works only in Chrome-like browsers
  2333. let noContentYet = true;
  2334. function jWrap()
  2335. {
  2336. win.$ = new Proxy(
  2337. win.$, {
  2338. apply: function(_$, _this, args)
  2339. {
  2340. let _ret = _$.apply(_this, args);
  2341. if (_ret[0] === document.body)
  2342. _ret.html = () => console.log('Anti-adblock prevented.');
  2343. return _ret;
  2344. }
  2345. }
  2346. );
  2347. win.jQuery = win.$;
  2348. }
  2349. (function jReady()
  2350. {
  2351. if (!win.$ && noContentYet)
  2352. setTimeout(jReady, 0);
  2353. else
  2354. jWrap();
  2355. })();
  2356. document.addEventListener ('DOMContentLoaded', () => (noContentYet = false), false);
  2357. }
  2358. };
  2359. scripts['forums.overclockers.ru'] = {
  2360. now: function()
  2361. {
  2362. createStyle('.needblock {position: fixed; left: -10000px}');
  2363. Object.defineProperty(win, 'adblck', {
  2364. get: () => 'no',
  2365. set: () => null,
  2366. enumerable: true
  2367. });
  2368. }
  2369. };
  2370.  
  2371. scripts['pb.wtf'] = {
  2372. other: ['piratbit.org', 'piratbit.ru'],
  2373. dom: function()
  2374. {
  2375. createStyle('.reques,#result,tbody.row1:not([id]) {display: none !important}');
  2376. // image in the slider in the header
  2377. gardener('a[href^="/ex"],a[href$="=="]', /img/i, {root:'.release-navbar', observe:true, parent:'div'});
  2378. // ads in blocks on the page
  2379. gardener('a[href^="/topic/234257"]', /Как\sразместить/i, {siblings:-1, root:'#main_content', observe:true, parent:'span[style]'});
  2380. // line above topic content
  2381. gardener('.re_top1', /./, {root:'#main_content', parent:'.hidden-sm'});
  2382. }
  2383. };
  2384.  
  2385. scripts['pikabu.ru'] = () => gardener('.story', /story__sponsor|story__gag|profile\/ads"/i, {root: '.inner_wrap', observe: true});
  2386.  
  2387. scripts['qrz.ru'] = {
  2388. now: function()
  2389. {
  2390. Object.defineProperty(win, 'ab', {
  2391. get:()=>false,
  2392. set:()=>null
  2393. });
  2394. Object.defineProperty(win, 'tryMessage', {
  2395. get:()=>(()=>null),
  2396. set:()=>null
  2397. });
  2398. }
  2399. };
  2400.  
  2401. scripts['razlozhi.ru'] = {
  2402. now: function()
  2403. {
  2404. for (let func of ['createShadowRoot', 'attachShadow'])
  2405. if (func in Element.prototype)
  2406. Element.prototype[func] = function(){ return this.cloneNode(); };
  2407. }
  2408. };
  2409.  
  2410. scripts['rbc.ru'] = {
  2411. dom: function()
  2412. {
  2413. let _preventDefault = Event.prototype.preventDefault;
  2414. Event.prototype.preventDefault = function preventDefault()
  2415. {
  2416. let t = this.target;
  2417. if (t instanceof HTMLAnchorElement || t.closest('A'))
  2418. throw new Error('an.yandex redirect prevention');
  2419. return _preventDefault.call(this);
  2420. };
  2421.  
  2422. function cleaner(nodes)
  2423. {
  2424. for (let node of nodes)
  2425. {
  2426. if (!node.classList || !node.classList.contains('js-yandex-counter'))
  2427. continue;
  2428. node.classList.remove('js-yandex-counter');
  2429. node.removeAttribute('data-yandex-name');
  2430. node.removeAttribute('data-yandex-params');
  2431. }
  2432. }
  2433. cleaner(_de.querySelectorAll('.js-yandex-counter'));
  2434.  
  2435. (new MutationObserver(
  2436. ms => { for (let m of ms) cleaner(m.addedNodes); }
  2437. )).observe(_de, {childList: true, subtree: true});
  2438. }
  2439. };
  2440.  
  2441. scripts['rp5.ru'] = {
  2442. other: ['rp5.by', 'rp5.kz', 'rp5.ua'],
  2443. dom: function()
  2444. {
  2445. createStyle('#bannerBottom {display: none!important}');
  2446. let co = document.querySelector('#content');
  2447. if (!co)
  2448. return;
  2449. let nodes = co.parentNode.childNodes,
  2450. i = nodes.length;
  2451. while (i--)
  2452. if (nodes[i] !== co)
  2453. nodes[i].parentNode.removeChild(nodes[i]);
  2454. }
  2455. };
  2456.  
  2457. scripts['rustorka.com'] = {
  2458. other: ['rumedia.ws'],
  2459. now: function()
  2460. {
  2461. createStyle('.header > div:not(.head-block) a, #sidebar1 img, #logo img {opacity:0!important}', {
  2462. id: 'tempHidingStyles'
  2463. }, true);
  2464. preventPopups();
  2465. },
  2466. dom: function()
  2467. {
  2468. for (let o of document.querySelectorAll('IMG, A'))
  2469. if ((o.clientWidth === 728 && o.clientHeight === 90) ||
  2470. (o.clientWidth === 300 && o.clientHeight === 250))
  2471. {
  2472. while (o && o.tagName !== 'A')
  2473. o = o.parentNode;
  2474. if (o)
  2475. _setAttribute.call(o, 'style', 'display: none !important');
  2476. }
  2477. let s = document.querySelector('#tempHidingStyles');
  2478. s.parentNode.removeChild(s);
  2479. }
  2480. };
  2481.  
  2482. scripts['sport-express.ru'] = () => gardener('.js-relap__item',/>Реклама\s+<\//, {root:'.container', observe: true});
  2483.  
  2484. scripts['sports.ru'] = function()
  2485. {
  2486. gardener('.aside-news-list__item', /aside-news-list__advert/i, {root:'.columns-layout__left', observe: true});
  2487. gardener('.material-list__item', /Реклама/i, {root:'.columns-layout', observe: true});
  2488. // extra functionality: shows/hides panel at the top depending on scroll direction
  2489. createStyle([
  2490. '.user-panel__fixed { transition: top 0.2s ease-in-out!important; }',
  2491. '.user-panel-up { top: -40px!important }'
  2492. ], {id: 'userPanelSlide'}, false);
  2493. (function lookForPanel()
  2494. {
  2495. let panel = document.querySelector('.user-panel__fixed');
  2496. if (!panel)
  2497. setTimeout(lookForPanel, 100);
  2498. else
  2499. window.addEventListener(
  2500. 'wheel', function(e)
  2501. {
  2502. if (e.deltaY > 0 && !panel.classList.contains('user-panel-up'))
  2503. panel.classList.add('user-panel-up');
  2504. else if (e.deltaY < 0 && panel.classList.contains('user-panel-up'))
  2505. panel.classList.remove('user-panel-up');
  2506. }, false
  2507. );
  2508. })();
  2509. };
  2510.  
  2511. scripts['vk.com'] = () => gardener((
  2512. '#wk_content > #wl_post > div,'+
  2513. '#page_wall_posts > div[id^="post-"],'+
  2514. 'div[class^="feed_row "] > div[id^="post-"],'+
  2515. 'div[class^="feed_row "] > div[id^="feed_repost-"]'
  2516. ), /wall_marked_as_ads/, {root: 'body', observe: true});
  2517.  
  2518. scripts['yap.ru'] = {
  2519. other: ['yaplakal.com'],
  2520. dom: function()
  2521. {
  2522. gardener('form > table[id^="p_row_"]:nth-of-type(2)', /member1438|Administration/);
  2523. gardener('.icon-comments', /member1438|Administration|\/go\/\?http/, {parent:'tr', siblings:-2});
  2524. }
  2525. };
  2526.  
  2527. scripts['rambler.ru'] = {
  2528. other: ['championat.com','gazeta.ru','media.eagleplatform.com','lenta.ru'],
  2529. now: () => scriptLander(
  2530. function()
  2531. {
  2532. if (location.hostname.endsWith('.media.eagleplatform.com'))
  2533. return;
  2534. let getDomain = (name) => name.replace(/[^:]+:\/\/([^:/]+)[:/].*/, '$1').replace(/[^.]+\./,'');
  2535. let _onload = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'onload');
  2536. let _set = _onload.set;
  2537. _onload.configurable = false;
  2538. _onload.set = function(func)
  2539. {
  2540. _set.call(
  2541. this, function(e)
  2542. {
  2543. let d = e.target.href ? getDomain(e.target.href) : null,
  2544. h = location.hostname;
  2545. if (d && e.target instanceof HTMLLinkElement &&
  2546. (d === 'rambler.ru' || d === h || h.indexOf('.'+d) > -1))
  2547. {
  2548. console.log('Blocked "onload" for', e.target.href);
  2549. return false;
  2550. }
  2551. return func.apply(this, arguments);
  2552. }
  2553. );
  2554. };
  2555. Object.defineProperty(HTMLElement.prototype, 'onload', _onload);
  2556. // fake global Adf object
  2557. let nt = new nullTools();
  2558. nt.define(win, 'Adf', nt.proxy({
  2559. banner: nt.proxy({
  2560. sspScroll: nt.func(),
  2561. ssp: nt.func()
  2562. })
  2563. }));
  2564. // extra script to remove partner news on gazeta.ru
  2565. if (!location.hostname.includes('gazeta.ru'))
  2566. return;
  2567. (new MutationObserver(
  2568. (ms) => {
  2569. let m, node, header;
  2570. for (m of ms) for (node of m.addedNodes)
  2571. if (node instanceof HTMLDivElement && node.matches('.sausage'))
  2572. {
  2573. header = node.querySelector('.sausage-header');
  2574. if (header && /новости\s+партн[её]ров/i.test(header.textContent))
  2575. node.style.display = 'none';
  2576. }
  2577. }
  2578. )).observe(document.documentElement, { childList:true, subtree: true });
  2579. }, nullTools
  2580. ),
  2581. dom: () => {
  2582. // extra script to block video autoplay on Rambler domains
  2583. let stopper = (e) => {
  2584. let btn = document.querySelector('.eplayer-skin-toggle-playing');
  2585. if (btn)
  2586. btn.click();
  2587. else
  2588. e.target.pause();
  2589. e.target.removeEventListener('playing', stopper, false);
  2590. };
  2591. (new MutationObserver(
  2592. (ms) => {
  2593. for (let m of ms)
  2594. if (m.target.hasAttribute('autoplay'))
  2595. m.target.addEventListener('playing', stopper, false);
  2596. }
  2597. )).observe(document.documentElement, { subtree: true, attributes: true, attributeFilter: ['autoplay'] });
  2598. }
  2599. };
  2600.  
  2601. scripts['reactor.cc'] = {
  2602. other: ['joyreactor.cc', 'pornreactor.cc'],
  2603. now: function()
  2604. {
  2605. win.open = (function(){ throw new Error('Redirect prevention.'); }).bind(window);
  2606. },
  2607. click: function(e)
  2608. {
  2609. let node = e.target;
  2610. if (node.nodeType === Node.ELEMENT_NODE &&
  2611. node.style.position === 'absolute' &&
  2612. node.style.zIndex > 0)
  2613. node.parentNode.removeChild(node);
  2614. },
  2615. dom: function()
  2616. {
  2617. let words = new RegExp(
  2618. 'блокировщика рекламы'
  2619. .split('')
  2620. .map(function(e){return e+'[\u200b\u200c\u200d]*';})
  2621. .join('')
  2622. .replace(' ', '\\s*')
  2623. .replace(/[аоре]/g, function(e){return ['[аa]','[оo]','[рp]','[еe]']['аоре'.indexOf(e)];}),
  2624. 'i'),
  2625. can;
  2626. function deeper(spider)
  2627. {
  2628. let c, l, n;
  2629. if (words.test(spider.innerText))
  2630. {
  2631. if (spider.nodeType === Node.TEXT_NODE)
  2632. return true;
  2633. c = spider.childNodes;
  2634. l = c.length;
  2635. n = 0;
  2636. while(l--)
  2637. if (deeper(c[l]), can)
  2638. n++;
  2639. if (n > 0 && n === c.length && spider.offsetHeight < 750)
  2640. can.push(spider);
  2641. return false;
  2642. }
  2643. return true;
  2644. }
  2645. function probe()
  2646. {
  2647. if (words.test(document.body.innerText))
  2648. {
  2649. can = [];
  2650. deeper(document.body);
  2651. let i = can.length, spider;
  2652. while(i--) {
  2653. spider = can[i];
  2654. if (spider.offsetHeight > 10 && spider.offsetHeight < 750)
  2655. _setAttribute.call(spider, 'style', 'background:none!important');
  2656. }
  2657. }
  2658. }
  2659. (new MutationObserver(probe))
  2660. .observe(document, { childList:true, subtree:true });
  2661. }
  2662. };
  2663.  
  2664. scripts['auto.ru'] = function()
  2665. {
  2666. let words = /Реклама|Яндекс.Директ|yandex_ad_/;
  2667. let userAdsListAds = (
  2668. '.listing-list > .listing-item,'+
  2669. '.listing-item_type_fixed.listing-item'
  2670. );
  2671. let catalogAds = (
  2672. 'div[class*="layout_catalog-inline"],'+
  2673. 'div[class$="layout_horizontal"]'
  2674. );
  2675. let otherAds = (
  2676. '.advt_auto,'+
  2677. '.sidebar-block,'+
  2678. '.pager-listing + div[class],'+
  2679. '.card > div[class][style],'+
  2680. '.sidebar > div[class],'+
  2681. '.main-page__section + div[class],'+
  2682. '.listing > tbody'
  2683. );
  2684. gardener(userAdsListAds, words, {root:'.listing-wrap', observe:true});
  2685. gardener(catalogAds, words, {root:'.catalog__page,.content__wrapper', observe:true});
  2686. gardener(otherAds, words);
  2687. };
  2688.  
  2689. scripts['rsload.net'] = {
  2690. load: function()
  2691. {
  2692. let dis = document.querySelector('label[class*="cb-disable"]');
  2693. if (dis)
  2694. dis.click();
  2695. },
  2696. click: function(e)
  2697. {
  2698. let t = e.target;
  2699. if (t && t.href && (/:\/\/\d+\.\d+\.\d+\.\d+\//.test(t.href)))
  2700. t.href = t.href.replace('://','://rsload.net:rsload.net@');
  2701. }
  2702. };
  2703.  
  2704. let domain, name;
  2705. // add alternative domain names if present and wrap functions into objects
  2706. for (name in scripts)
  2707. {
  2708. if (scripts[name] instanceof Function)
  2709. scripts[name] = { dom: scripts[name] };
  2710. for (domain of (scripts[name].other||[]))
  2711. {
  2712. if (domain in scripts)
  2713. console.log('Error in scripts list. Script for', name, 'replaced script for', domain);
  2714. scripts[domain] = scripts[name];
  2715. }
  2716. delete scripts[name].other;
  2717. }
  2718. // look for current domain in the list and run appropriate code
  2719. domain = document.domain;
  2720. while (domain.indexOf('.') > -1)
  2721. {
  2722. if (domain in scripts) for (name in scripts[domain])
  2723. switch(name)
  2724. {
  2725. case 'now':
  2726. scripts[domain][name]();
  2727. break;
  2728. case 'load':
  2729. window.addEventListener('load', scripts[domain][name], false);
  2730. break;
  2731. case 'dom':
  2732. document.addEventListener('DOMContentLoaded', scripts[domain][name], false);
  2733. break;
  2734. default:
  2735. document.addEventListener (name, scripts[domain][name], false);
  2736. }
  2737. domain = domain.slice(domain.indexOf('.') + 1);
  2738. }
  2739. })();