RU AdList JS Fixes

try to take over the world!

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

  1. // ==UserScript==
  2. // @name RU AdList JS Fixes
  3. // @namespace ruadlist_js_fixes
  4. // @version 20170620.1
  5. // @description try to take over the world!
  6. // @author lainverse & dimisa
  7. // @match *://*/*
  8. // @grant unsafeWindow
  9. // @grant window.close
  10. // @grant GM_getValue
  11. // @grant GM_setValue
  12. // @grant GM_deleteValue
  13. // @run-at document-start
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. 'use strict';
  18. var win = (unsafeWindow || window),
  19. // http://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser
  20. isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0,
  21. isChrome = !!window.chrome && !!window.chrome.webstore,
  22. isSafari = (Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0 ||
  23. (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window.safari || safari.pushNotification)),
  24. isFirefox = typeof InstallTrigger !== 'undefined',
  25. inIFrame = (win.self !== win.top),
  26. _getAttribute = Element.prototype.getAttribute,
  27. _setAttribute = Element.prototype.setAttribute,
  28. _de = document.documentElement,
  29. _appendChild = Document.prototype.appendChild.bind(_de),
  30. _removeChild = Document.prototype.removeChild.bind(_de),
  31. _createElement = Document.prototype.createElement.bind(document);
  32.  
  33. // NodeList iterator polyfill (mostly for Safari)
  34. // https://jakearchibald.com/2014/iterators-gonna-iterate/
  35. if (!NodeList.prototype[Symbol.iterator]) {
  36. NodeList.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
  37. }
  38.  
  39. // Options
  40. let opts = {
  41. 'useWSIFunc': useWSI
  42. };
  43.  
  44. {
  45. let optsCall = function(callback)
  46. {
  47. // Register event listener
  48. let key = "optsCallEvent_" + Math.random().toString(36).substr(2),
  49. cb = callback.func.bind(callback.name);
  50. window.addEventListener(key, cb, false);
  51. // Generate and dispatch synthetic event
  52. let ev = document.createEvent("HTMLEvents");
  53. ev.initEvent(key, true, false);
  54. window.dispatchEvent(ev);
  55. // Remove listener
  56. window.removeEventListener(key, cb, false);
  57. };
  58.  
  59. let initOptsHandler = function()
  60. {
  61. /*jshint validthis:true */
  62. opts[this] = GM_getValue(this, true);
  63. if (opts[this])
  64. opts[this+'Func']();
  65. };
  66.  
  67. optsCall({
  68. func: initOptsHandler,
  69. name: 'useWSI'
  70. });
  71.  
  72. // show options page
  73. let openOptions = function()
  74. {
  75. let ovl = _createElement('div'),
  76. inner = _createElement('div');
  77. ovl.style = (
  78. 'position: fixed;'+
  79. 'top:0; left:0;'+
  80. 'bottom: 0; right: 0;'+
  81. 'background: rgba(0,0,0,0.85);'+
  82. 'z-index: 2147483647;'+
  83. 'padding: 5em'
  84. );
  85. inner.style = (
  86. 'background: whitesmoke;'+
  87. 'font-size: 10pt;'+
  88. 'color: black;'+
  89. 'padding: 1em'
  90. );
  91. inner.textContent = 'JS Fixes Options: (reload page to apply)';
  92. inner.appendChild(_createElement('br'));
  93. inner.appendChild(_createElement('br'));
  94. ovl.addEventListener(
  95. 'click', function(e)
  96. {
  97. if (e.target === ovl) {
  98. ovl.parentNode.removeChild(ovl);
  99. e.preventDefault();
  100. }
  101. e.stopPropagation();
  102. }, false
  103. );
  104. // append checkbox with label function
  105. function addCheckbox(optName, optLabel)
  106. {
  107. let c = _createElement('input'),
  108. l = _createElement('label');
  109. c.type = 'checkbox';
  110. c.id = optName;
  111. optsCall({
  112. func: function()
  113. {
  114. c.checked = GM_getValue(this);
  115. },
  116. name: optName
  117. });
  118. c.addEventListener(
  119. 'click', function(e)
  120. {
  121. optsCall({
  122. func:function(){
  123. GM_setValue(this, e.target.checked);
  124. opts[this] = e.target.checked;
  125. },
  126. name:optName
  127. });
  128. }, true
  129. );
  130. l.textContent = optLabel;
  131. l.setAttribute('for', optName);
  132. inner.appendChild(c);
  133. inner.appendChild(l);
  134. inner.appendChild(_createElement('br'));
  135. }
  136. // append checkboxes
  137. addCheckbox('useWSI', 'Use WebSocket filter. Disable if experience problems with WebSocket connections.');
  138. document.body.appendChild(ovl);
  139. ovl.appendChild(inner);
  140. };
  141.  
  142. // monitor keys pressed for Ctrl+Alt+Shift+J > s > f code
  143. let opPos = 0, opKey = ['KeyJ','KeyS','KeyF'];
  144. document.addEventListener(
  145. 'keydown', function(e)
  146. {
  147. if ((e.code === opKey[opPos] || e.location) &&
  148. (!!opPos || e.altKey && e.ctrlKey && e.shiftKey))
  149. {
  150. opPos += e.location ? 0 : 1;
  151. e.stopPropagation();
  152. e.preventDefault();
  153. } else {
  154. opPos = 0;
  155. }
  156. if (opPos === opKey.length)
  157. {
  158. opPos = 0;
  159. openOptions();
  160. }
  161. }, false
  162. );
  163. }
  164.  
  165. // Special wrapper script to run scripts designed to override standard DOM functions
  166. // In Firefox appends supplied script to a page to make it run in page context and let
  167. // page content access overridden functions. In other browsers just run it as-is.
  168. function scriptLander(func, prepend)
  169. {
  170. if (!isFirefox)
  171. {
  172. func();
  173. return;
  174. }
  175. let script = _createElement('script');
  176. script.textContent = '(function(){var win=window;' + (
  177. prepend && prepend.join('') || ''
  178. ) + '!' + func + '();})();';
  179. _appendChild(script);
  180. _removeChild(script);
  181. }
  182.  
  183. // Creates and return protected style (unless protection is manually disabled).
  184. // Protected style will re-add itself on removal and remaind enabled on attempt to disable it.
  185. function createStyle(rules, props, skip_protect)
  186. {
  187. props = props || {};
  188. props.type = 'text/css';
  189.  
  190. function _protect(style)
  191. {
  192. if (skip_protect)
  193. return;
  194.  
  195. Object.defineProperty(style, 'sheet', {
  196. value: null,
  197. enumerable: true
  198. });
  199. Object.defineProperty(style, 'disabled', {
  200. get: () => true, //pretend to be disabled
  201. set: () => null,
  202. enumerable: true
  203. });
  204. (new MutationObserver(
  205. (ms) => _removeChild(ms[0].target)
  206. )).observe(style, { childList: true });
  207. }
  208.  
  209.  
  210. function _create()
  211. {
  212. let style = _appendChild(_createElement('style'));
  213. Object.assign(style, props);
  214.  
  215. function insertRules(rule)
  216. {
  217. if (rule.forEach)
  218. rule.forEach(insertRules);
  219. else try {
  220. style.sheet.insertRule(rule, 0);
  221. } catch (e) {
  222. console.error(e);
  223. }
  224. }
  225.  
  226. insertRules(rules);
  227. _protect(style);
  228.  
  229. return style;
  230. }
  231.  
  232. let style = _create();
  233. if (skip_protect)
  234. return style;
  235.  
  236. function resolveInANewContext(resolve)
  237. {
  238. setTimeout(
  239. (resolve) => resolve(_create()),
  240. 0, resolve
  241. );
  242. }
  243.  
  244. (new MutationObserver(
  245. function(ms)
  246. {
  247. let m, node;
  248. for (m of ms) for (node of m.removedNodes)
  249. if (node === style)
  250. (new Promise(resolveInANewContext))
  251. .then((st) => (style = st));
  252. }
  253. )).observe(_de, { childList: true });
  254.  
  255. return style;
  256. }
  257.  
  258. // https://greasyfork.org/scripts/19144-websuckit/
  259. function useWSI()
  260. {
  261. // check does browser support Proxy and WebSocket
  262. if (typeof Proxy !== 'function' ||
  263. typeof WebSocket !== 'function')
  264. return;
  265.  
  266. function getWrappedCode(removeSelf)
  267. {
  268. let text = getWrappedCode.toString() + WSI.toString();
  269. text = (
  270. '(function(){"use strict";'+
  271. text.replace(/\/\/[^\r\n]*/g,'').replace(/[\s\r\n]+/g,' ')+
  272. '(new WSI(self||window)).init();'+
  273. '})();\n'+
  274. (removeSelf?'let s = document.currentScript; if (s) {s.parentNode.removeChild(s);}':'')
  275. );
  276. return text;
  277. }
  278.  
  279. function WSI(win, safeWin)
  280. {
  281. safeWin = safeWin || win;
  282. let masks = [], filter;
  283. for (filter of [// blacklist
  284. '||185.87.50.147^',
  285. '||10root25.website^', '||24video.xxx^',
  286. '||adlabs.ru^', '||adspayformymortgage.win^', '||aviabay.ru^',
  287. '||bgrndi.com^', '||brokeloy.com^',
  288. '||cnamerutor.ru^',
  289. '||docfilms.info^', '||dreadfula.ru^',
  290. '||et-code.ru^',
  291. '||franecki.net^', '||film-doma.ru^',
  292. '||free-torrent.org^', '||free-torrent.pw^',
  293. '||free-torrents.org^', '||free-torrents.pw^',
  294. '||game-torrent.info^', '||gocdn.ru^',
  295. '||hdkinoshka.com^', '||hghit.com^', '||hindcine.net^',
  296. '||kiev.ua^', '||kinotochka.net^',
  297. '||kinott.com^', '||kinott.ru^', '||kuveres.com^',
  298. '||lepubs.com^', '||luxadv.com^', '||luxup.ru^', '||luxupcdna.com^',
  299. '||mail.ru^', '||marketgid.com^', '||mixadvert.com^', '||mxtads.com^',
  300. '||nickhel.com^',
  301. '||oconner.biz^', '||oconner.link^', '||octoclick.net^', '||octozoon.org^',
  302. '||pkpojhc.com^',
  303. '||psma01.com^', '||psma02.com^', '||psma03.com^',
  304. '||recreativ.ru^', '||redtram.com^', '||regpole.com^', '||rootmedia.ws^', '||ruttwind.com^',
  305. '||skidl.ru^',
  306. '||torvind.com^', '||traffic-media.co^', '||trafmag.com^',
  307. '||webadvert-gid.ru^', '||webadvertgid.ru^',
  308. '||xxuhter.ru^',
  309. '||yuiout.online^',
  310. '||zoom-film.ru^'])
  311. masks.push(new RegExp(
  312. filter.replace(/([\\\/\[\].*+?(){}$])/g, '\\$1')
  313. .replace(/\^(?!$)/g,'\\.?[^\\w%._-]')
  314. .replace(/\^$/,'\\.?([^\\w%._-]|$)')
  315. .replace(/^\|\|/,'^(ws|http)s?:\\/+([^\/.]+\\.)*'),
  316. 'i'));
  317.  
  318. function isBlocked(url) {
  319. for (let mask of masks)
  320. if (mask.test(url))
  321. return true;
  322. return false;
  323. }
  324.  
  325. let realWebSocket = win.WebSocket;
  326. function wsGetter(target, name)
  327. {
  328. try {
  329. if (typeof realWebSocket.prototype[name] === 'function')
  330. {
  331. if (name === 'close' || name === 'send') // send also closes connection
  332. target.readyState = realWebSocket.CLOSED;
  333. return (
  334. function fake() {
  335. console.log('[WSI] Invoked function "'+name+'"', '| Tracing', (new Error()));
  336. return;
  337. }
  338. );
  339. }
  340. if (typeof realWebSocket.prototype[name] === 'number')
  341. return realWebSocket[name];
  342. } catch(ignore) {}
  343. return target[name];
  344. }
  345.  
  346. function createWebSocketWrapper(target)
  347. {
  348. return new Proxy(realWebSocket, {
  349. construct: function (target, args)
  350. {
  351. let url = args[0];
  352. console.log('[WSI] Opening socket on ' + url + ' \u2026');
  353. if (isBlocked(url))
  354. {
  355. console.log("[WSI] Blocked.");
  356. return new Proxy({
  357. url: url,
  358. readyState: realWebSocket.OPEN
  359. }, {
  360. get: wsGetter,
  361. set: (val) => val
  362. });
  363. }
  364. return new target(args[0], args[1]);
  365. }
  366. });
  367. }
  368.  
  369. function WorkerWrapper()
  370. {
  371. let realWorker = win.Worker;
  372. win.Worker = function Worker() {
  373. let isBlobURL = /^blob:/i,
  374. resourceURI = arguments[0],
  375. deepLogMode = false,
  376. xhr = null,
  377. _callbacks = new WeakMap(),
  378. _worker = null,
  379. _onevs = { names: ['onmessage', 'onerror'] },
  380. _actions = [],
  381. /*jshint validthis:true */
  382. _self = this;
  383.  
  384. function log()
  385. {
  386. if (deepLogMode)
  387. console.log.apply(this, arguments);
  388. }
  389.  
  390. function callbackWrapper(func)
  391. {
  392. if (typeof func !== 'function')
  393. return undefined;
  394.  
  395. return function callback()
  396. {
  397. return func.apply(_self, arguments);
  398. };
  399. }
  400.  
  401. function updateWorker()
  402. {
  403. for (let [action, name, args] of _actions) {
  404. log(_worker, action, name, args);
  405. if (action === 'set')
  406. _worker[name] = callbackWrapper(args);
  407. if (action === 'call')
  408. _worker[name].apply(_worker, args);
  409. }
  410. _actions.length = 0;
  411. log('Applied buffered actions.');
  412. }
  413.  
  414. for (let prop of _onevs.names)
  415. Object.defineProperty(_self, prop, {
  416. set: function(val) {
  417. _onevs[prop] = val;
  418. if (_worker)
  419. _worker[prop] = callbackWrapper(val);
  420. else {
  421. _actions.push(['set', prop, val]);
  422. log('Stored into buffer:', arguments);
  423. }
  424. return val;
  425. },
  426. get: () => _onevs[prop],
  427. enumerable: true
  428. });
  429.  
  430. _self.postMessage = function()
  431. {
  432. if (_worker)
  433. _worker.postMessage.apply(_worker, arguments);
  434. else {
  435. _actions.push(['call', 'postMessage', arguments]);
  436. log('Stored into buffer:', arguments);
  437. }
  438. };
  439. _self.terminate = function()
  440. {
  441. if (_worker)
  442. _worker.terminate();
  443. else {
  444. _actions.push(['call','terminate', arguments]);
  445. log('Stored into buffer:', arguments);
  446. }
  447. };
  448. _self.addEventListener = function(event, callback, other)
  449. {
  450. if (typeof callback !== 'function')
  451. return;
  452.  
  453. if (!_callbacks.has(callback))
  454. _callbacks.set(callback, callbackWrapper(callback));
  455.  
  456. arguments[1] = _callbacks.get(callback);
  457. if (_worker)
  458. _worker.addEventListener.apply(_worker, arguments);
  459. else {
  460. _actions.push(['call', 'addEventListener', arguments]);
  461. log('Stored into buffer:', arguments);
  462. }
  463. };
  464. _self.removeEventListener = function(event, callback, other)
  465. {
  466. if (typeof callback !== 'function' || !_callbacks.has(callback))
  467. return;
  468.  
  469. arguments[1] = _callbacks.get(callback);
  470. _callbacks.delete(callback);
  471. if (_worker)
  472. _worker.removeEventListener.apply(_worker, arguments);
  473. else {
  474. _actions.push(['call', 'removeEventListener', arguments]);
  475. log('Stored into buffer:', arguments);
  476. }
  477. };
  478.  
  479. if (!isBlobURL.test(resourceURI))
  480. {
  481. _worker = new realWorker(resourceURI);
  482. return; // not a blob, no need to wrap
  483. }
  484.  
  485. xhr = new XMLHttpRequest();
  486. xhr.responseType = 'blob';
  487. try {
  488. xhr.open('GET', resourceURI, true);
  489. } catch(ignore) {
  490. _worker = new realWorker(resourceURI);
  491. return; // failed to open connection, unable to continue wrapping procedure
  492. }
  493.  
  494. (new Promise(
  495. function(resolve, reject)
  496. {
  497. if (xhr.readyState !== XMLHttpRequest.OPENED) {
  498. // connection wasn't opened, unable to continue wrapping procedure
  499. return reject();
  500. }
  501. xhr.onload = function()
  502. {
  503. if (this.status === 200)
  504. {
  505. let reader = new FileReader();
  506. reader.addEventListener(
  507. 'loadend', function()
  508. {
  509. resolve(
  510. new realWorker(URL.createObjectURL(
  511. new Blob([getWrappedCode(false) + this.result])
  512. ))
  513. );
  514. }
  515. );
  516. reader.readAsText(this.response);
  517. }
  518. };
  519. xhr.onerror = (e) => reject(e);
  520. xhr.send();
  521. }
  522. )).then(
  523. function(val)
  524. {
  525. _worker = val;
  526. updateWorker();
  527. }
  528. ).catch(
  529. function(e)
  530. {
  531. // connection were blocked by CSP or something else triggered error event on xhr object
  532. // it should be safe to create worker with original URI now and let it dispatch error event
  533. _worker = new realWorker(resourceURI);
  534. updateWorker();
  535. }
  536. );
  537.  
  538. if (deepLogMode)
  539. {
  540. return new Proxy(_self, {
  541. get: function(target, prop) {
  542. console.log('Worker _get_', prop);
  543. return target[prop];
  544. },
  545. set: function(target, prop, val) {
  546. console.log('Worker _set_', prop, '_to_', val);
  547. target[prop] = val;
  548. return val;
  549. }
  550. });
  551. }
  552. }.bind(safeWin);
  553. }
  554.  
  555. function CreateElementWrapper()
  556. {
  557. let _createElement = Document.prototype.createElement,
  558. _addEventListener = Element.prototype.addEventListener,
  559. code = encodeURIComponent('<scr'+'ipt>'+getWrappedCode(true)+'</scr'+'ipt>\n'),
  560. isDataURL = /^data:/i,
  561. isBlobURL = /^blob:/i;
  562.  
  563. function frameRewrite(e)
  564. {
  565. let f = e.target,
  566. w = f.contentWindow;
  567. if (!f.src || (w && isBlobURL.test(f.src)))
  568. w.WebSocket = createWebSocketWrapper();
  569. if (isDataURL.test(f.src) && f.src.indexOf(code) < 0)
  570. f.src = f.src.replace(',',',' + code);
  571. }
  572.  
  573. let scriptMap = new WeakMap();
  574. scriptMap.isBlocked = isBlocked;
  575. let onErrorWrapper = {
  576. set: function(val)
  577. {
  578. if (scriptMap.has(this))
  579. {
  580. this.removeEventListener('error', scriptMap.get(this).wrp, false);
  581. scriptMap.delete(this);
  582. }
  583. if (!val || typeof val !== 'function')
  584. return val;
  585.  
  586. scriptMap.set(this, {
  587. org: val,
  588. wrp: function()
  589. {
  590. if (scriptMap.isBlocked(this.src))
  591. console.log('[WSI] Blocked "onerror" callback from', this);
  592. else
  593. scriptMap.get(this).org.apply(this, arguments);
  594. }
  595. });
  596. this.addEventListener('error', scriptMap.get(this).wrp, false);
  597.  
  598. return val;
  599. },
  600. get: function()
  601. {
  602. return scriptMap.has(this) ? scriptMap.get(this).org : null;
  603. },
  604. enumerable: true
  605. };
  606. Document.prototype.createElement = function createElement(name) {
  607. /*jshint validthis:true */
  608. let el = _createElement.apply(this, arguments);
  609.  
  610. if (el.tagName === 'IFRAME')
  611. _addEventListener.call(el, 'load', frameRewrite, false);
  612. if (el.tagName === 'SCRIPT')
  613. Object.defineProperty(el, 'onerror', onErrorWrapper);
  614.  
  615. return el;
  616. };
  617.  
  618. document.addEventListener(
  619. 'DOMContentLoaded', function()
  620. {
  621. for (let ifr of document.querySelectorAll('IFRAME'))
  622. _addEventListener.call(ifr, 'load', frameRewrite, false);
  623. }, false
  624. );
  625. }
  626.  
  627. this.init = function()
  628. {
  629. win.WebSocket = createWebSocketWrapper();
  630. if (!(/firefox/i.test(navigator.userAgent)))
  631. WorkerWrapper(); // skip WorkerWrapper in Firefox
  632. if (typeof document !== 'undefined')
  633. CreateElementWrapper();
  634. };
  635. }
  636.  
  637. if (isFirefox)
  638. {
  639. let script = _createElement('script');
  640. script.textContent = getWrappedCode(true);
  641. _appendChild(script);
  642. _removeChild(script);
  643. return; //we don't want to call functions on page from here in Fx, so exit
  644. }
  645.  
  646. (new WSI((unsafeWindow||self||window),(self||window))).init();
  647. }
  648.  
  649. if (!isFirefox)
  650. { // scripts for non-Firefox browsers
  651.  
  652. // https://greasyfork.org/scripts/14720-it-s-not-important
  653. {
  654. let imptt = /((display|(margin|padding)(-top|-bottom)?)\s*:[^;!]*)!\s*important/ig,
  655. ret_b = (a,b) => b,
  656. _toLowerCase = String.prototype.toLowerCase,
  657. protectedNodes = new WeakSet(),
  658. log = false;
  659.  
  660. let logger = function()
  661. {
  662. if (log)
  663. console.log('Some page elements became a bit less important.');
  664. log = false;
  665. };
  666.  
  667. let unimportanter = function(node)
  668. {
  669. let style = (node.nodeType === Node.ELEMENT_NODE) ?
  670. _getAttribute.call(node, 'style') : null;
  671.  
  672. if (!style || !imptt.test(style) || node.style.display === 'none' ||
  673. (node.src && node.src.slice(0,17) === 'chrome-extension:')) // Web of Trust IFRAME and similar
  674. return false; // get out if we have nothing to do here
  675.  
  676. protectedNodes.add(node);
  677. _setAttribute.call(node, 'style',
  678. style.replace(imptt, ret_b));
  679. log = true;
  680. };
  681.  
  682. (new MutationObserver(
  683. function(mutations)
  684. {
  685. setTimeout(
  686. function(ms)
  687. {
  688. let m, node;
  689. for (m of ms) for (node of m.addedNodes)
  690. unimportanter(node);
  691. logger();
  692. }, 0, mutations
  693. );
  694. }
  695. )).observe(document, {
  696. childList : true,
  697. subtree : true
  698. });
  699.  
  700. Element.prototype.setAttribute = function setAttribute(name, value)
  701. {
  702. "[native code]";
  703. let replaced = value;
  704. if (_toLowerCase.call(name) === 'style' && protectedNodes.has(this))
  705. replaced = value.replace(imptt, ret_b);
  706. log = (replaced !== value);
  707. logger();
  708. return _setAttribute.call(this, name, replaced);
  709. };
  710.  
  711. win.addEventListener (
  712. 'load', function()
  713. {
  714. for (let imp of document.querySelectorAll('[style*="!"]'))
  715. unimportanter(imp);
  716. logger();
  717. }, false
  718. );
  719. }
  720.  
  721. }
  722.  
  723. if (/^https?:\/\/(mail\.yandex\.|music\.yandex\.|news\.yandex\.|(www\.)?yandex\.[^\/]+\/(yand)?search[\/?])/i.test(win.location.href))
  724. // https://greasyfork.org/en/scripts/809-no-yandex-ads
  725. document.addEventListener(
  726. 'DOMContentLoaded', function()
  727. {
  728. let adWords = ['Яндекс.Директ', 'Реклама', 'Ad'],
  729. genericAdSelectors = (
  730. '.serp-adv__head + .serp-item,'+
  731. '#adbanner,'+
  732. '.serp-adv,'+
  733. '.b-spec-adv,'+
  734. 'div[class*="serp-adv__"]:not(.serp-adv__found):not(.serp-adv__displayed)'
  735. );
  736. // Generic ads removal and fixes
  737. {
  738. let node = document.querySelector('.serp-header');
  739. if (node)
  740. node.style.marginTop = '0';
  741. for (node of document.querySelectorAll(genericAdSelectors))
  742. remove(node);
  743. }
  744. // Short name for parentNode.removeChild
  745. function remove(node) {
  746. node.parentNode.removeChild(node);
  747. }
  748. // Search ads
  749. function removeSearchAds()
  750. {
  751. let node, subNode, content;
  752. for (node of document.querySelectorAll('.t-construct-adapter__legacy'))
  753. {
  754. subNode = node.querySelector('.organic__subtitle');
  755. if (subNode)
  756. content = window.getComputedStyle(subNode, ':after').content;
  757. if (subNode && content && adWords.indexOf(content.replace(/"/g,'')) > -1)
  758. {
  759. remove(node);
  760. console.log('Ads removed.');
  761. }
  762. }
  763. }
  764. // News ads
  765. function removeNewsAds()
  766. {
  767. for (let node of document.querySelectorAll(
  768. '.page-content__left > *,'+
  769. '.page-content__right > *:not(.page-content__col),'+
  770. '.page-content__right > .page-content__col > *'
  771. ))
  772. if (node.textContent.indexOf(adWords[0]) > -1 ||
  773. (node.clientHeight < 15 && s.classList.contains('rubric')))
  774. {
  775. remove(node);
  776. console.log('Ads removed.');
  777. }
  778. }
  779. // Music ads
  780. function removeMusicAds()
  781. {
  782. for (let node of document.querySelectorAll('.ads-block'))
  783. remove(node);
  784. }
  785. // Mail ads
  786. function removeMailAds()
  787. {
  788. let slice = Array.prototype.slice,
  789. nodes = slice.call(document.querySelectorAll('.ns-view-folders')),
  790. node, len, cls;
  791.  
  792. for (node of nodes)
  793. if (!len || len > node.classList.length)
  794. len = node.classList.length;
  795.  
  796. node = nodes.pop();
  797. while (node)
  798. {
  799. if (node.classList.length > len)
  800. for (cls of slice.call(node.classList))
  801. if (cls.indexOf('-') === -1)
  802. {
  803. remove(node);
  804. break;
  805. }
  806. node = nodes.pop();
  807. }
  808. }
  809. // News fixes
  810. function removePageAdsClass()
  811. {
  812. if (document.body.classList.contains("b-page_ads_yes"))
  813. {
  814. document.body.classList.remove("b-page_ads_yes");
  815. console.log('Page ads class removed.');
  816. }
  817. }
  818. // Function to attach an observer to monitor dynamic changes on the page
  819. function pageUpdateObserver(func, obj, params) {
  820. if (obj)
  821. (new MutationObserver(func))
  822. .observe(obj, (params || { childList:true, subtree:true }));
  823. }
  824.  
  825. if (win.location.hostname.search(/^mail\./i) === 0) {
  826. pageUpdateObserver(
  827. function(ms, o)
  828. {
  829. let aside = document.querySelector('.mail-Layout-Aside');
  830. if (aside) {
  831. o.disconnect();
  832. pageUpdateObserver(removeMailAds, aside);
  833. }
  834. }, document.body
  835. );
  836. removeMailAds();
  837. } else if (win.location.hostname.search(/^music\./i) === 0) {
  838. pageUpdateObserver(removeMusicAds, document.querySelector('.sidebar'));
  839. removeMusicAds();
  840. } else if (win.location.hostname.search(/^news\./i) === 0) {
  841. pageUpdateObserver(removeNewsAds, document.body);
  842. pageUpdateObserver(removePageAdsClass, document.body, { attributes:true, attributesFilter:['class'] });
  843. removeNewsAds();
  844. removePageAdsClass();
  845. } else {
  846. pageUpdateObserver(removeSearchAds, document.querySelector('.main__content'));
  847. removeSearchAds();
  848. }
  849. }
  850. );
  851. // Yandex Link Tracking
  852. if (/^https?:\/\/([^.]+\.)*yandex\.[^\/]+/i.test(win.location.href))
  853. {
  854. // Partially based on https://greasyfork.org/en/scripts/22737-remove-yandex-redirect
  855. let selectors = (
  856. 'A[onmousedown*="/jsredir"],'+
  857. 'A[data-vdir-href],'+
  858. 'A[data-counter]'
  859. );
  860. let removeTrackingAttributes = function(link)
  861. {
  862. link.removeAttribute('onmousedown');
  863. if (link.hasAttribute('data-vdir-href')) {
  864. link.removeAttribute('data-vdir-href');
  865. link.removeAttribute('data-orig-href');
  866. }
  867. if (link.hasAttribute('data-counter')) {
  868. link.removeAttribute('data-counter');
  869. link.removeAttribute('data-bem');
  870. }
  871. };
  872. let removeTracking = function(scope)
  873. {
  874. for (let link of scope.querySelectorAll(selectors))
  875. removeTrackingAttributes(link);
  876. };
  877. document.addEventListener('DOMContentLoaded', (e) => removeTracking(e.target));
  878. (new MutationObserver(
  879. function(ms)
  880. {
  881. let m, node;
  882. for (m of ms) for (node of m.addedNodes) if (node.nodeType === Node.ELEMENT_NODE)
  883. if (node.tagName === 'A' && node.matches(selectors)) {
  884. removeTrackingAttributes(node);
  885. } else {
  886. removeTracking(node);
  887. }
  888. }
  889. )).observe(_de, { childList: true, subtree: true });
  890.  
  891. //skip fixes for other sites
  892. return;
  893. }
  894.  
  895. // https://greasyfork.org/en/scripts/21937-moonwalk-hdgo-kodik-fix v0.8 (adapted)
  896. document.addEventListener(
  897. 'DOMContentLoaded', function()
  898. {
  899. function log (e) {
  900. console.log('Moonwalk&HDGo&Kodik FIX: ' + e + ' player in ' + win.location.href);
  901. }
  902. if (win.adv_enabled !== undefined && win.condition_detected !== undefined)
  903. {
  904. log('Moonwalk');
  905. if (win.adv_enabled)
  906. win.adv_enabled = false;
  907. win.condition_detected = false;
  908. if (win.MXoverrollCallback)
  909. document.addEventListener(
  910. 'click', function catcher(e)
  911. {
  912. e.stopPropagation();
  913. win.MXoverrollCallback.call(window);
  914. document.removeEventListener('click', catcher, true);
  915. }, true
  916. );
  917. }
  918. else if (win.stat_url !== undefined && win.is_html5 !== undefined && win.is_wp8 !== undefined)
  919. {
  920. log('HDGo');
  921. document.body.onclick = null;
  922. let tmp = document.querySelector('#swtf');
  923. if (tmp)
  924. tmp.style.display = 'none';
  925. if (win.banner_second !== undefined)
  926. win.banner_second = 0;
  927. if (win.$banner_ads !== undefined)
  928. win.$banner_ads = false;
  929. if (win.$new_ads !== undefined)
  930. win.$new_ads = false;
  931. if (win.createCookie !== undefined)
  932. win.createCookie('popup', 'true', '999');
  933. if (win.canRunAds !== undefined && win.canRunAds !== true)
  934. win.canRunAds = true;
  935. }
  936. else if (win.MXoverrollCallback && win.iframeSearch !== undefined)
  937. {
  938. log('Kodik');
  939. let tmp = document.querySelector('.play_button');
  940. if (tmp)
  941. tmp.onclick = win.MXoverrollCallback.bind(window);
  942. win.IsAdBlock = false;
  943. }
  944. }, false
  945. );
  946.  
  947. // Automated protection against specific circumvention method based on unwrapping various functions,
  948. // hiding ads in the Shadow DOM and injecting iFrames with ads. Previously this code were known as
  949. // apiBreaker since it were breaking Shadow DOM and onerror/onload API on specific domains. This
  950. // version should be safe enough to run on majority of sites without actually breaking them.
  951. scriptLander(
  952. function()
  953. {
  954. let blacklist = new WeakMap();
  955. /* Wrap functions used to attach shadow root to a node */
  956. for (let func of ['createShadowRoot', 'attachShadow'])
  957. if (func in Element.prototype)
  958. Element.prototype[func] = (
  959. (func) => function()
  960. {
  961. blacklist.set(this, true);
  962. return func.apply(this, arguments);
  963. }
  964. )(Element.prototype[func]);
  965.  
  966. /* Wrap functions used to insert/append elements to check for IFRAME objects */
  967. for (let func of [/*'appendChild', */'insertBefore'])
  968. Object.defineProperty(
  969. Element.prototype, func, {
  970. enumerable: true,
  971. value: (
  972. (func) => function(el, par)
  973. {
  974. if (el.tagName === 'IFRAME' &&
  975. (typeof par === 'object' && blacklist.get(par)))
  976. {
  977. console.log('Blocked suspicious', func.name, arguments);
  978. return null;
  979. }
  980. return func.apply(this, arguments);
  981. }
  982. )(Element.prototype[func])
  983. }
  984. );
  985. }
  986. );
  987.  
  988. // === Helper functions ===
  989.  
  990. // function to search and remove nodes by content
  991. // selector - standard CSS selector to define set of nodes to check
  992. // words - regular expression to check content of the suspicious nodes
  993. // params - object with multiple extra parameters:
  994. // .log - display log in the console
  995. // .hide - set display to none instead of removing from the page
  996. // .parent - parent node to remove if content is found in the child node
  997. // .siblings - number of simling nodes to remove (excluding text nodes)
  998. let scRemove = (node) => node.parentNode.removeChild(node);
  999. let scHide = function(node)
  1000. {
  1001. let style = _getAttribute.call(node, 'style') || '',
  1002. hide = ';display:none!important;';
  1003. if (style.indexOf(hide) < 0)
  1004. _setAttribute.call(node, 'style', style + hide);
  1005. };
  1006. function scissors (selector, words, scope, params)
  1007. {
  1008. if (params.log)
  1009. console.log('[s] starting with', selector, words, scope, JSON.stringify(params));
  1010. let remFunc = (params.hide ? scHide : scRemove),
  1011. iterFunc = (params.siblings > 0 ? 'nextSibling' : 'previousSibling'),
  1012. toRemove = [],
  1013. siblings;
  1014. for (let node of scope.querySelectorAll(selector))
  1015. {
  1016. if (params.log)
  1017. console.log('[s] found node', node);
  1018. if (params.parent)
  1019. {
  1020. while(node !== scope && !(node.matches(params.parent)))
  1021. node = node.parentNode;
  1022. if (params.log)
  1023. console.log('[s] moving to parent node', node);
  1024. if (node === scope)
  1025. {
  1026. if (params.log)
  1027. console.log('[s] reached scope node, nothing to remove here.');
  1028. break;
  1029. }
  1030. }
  1031. if (words.test(node.innerHTML) || !node.childNodes.length)
  1032. {
  1033. // drill up to the specified parent node if required
  1034. if (toRemove.indexOf(node) === -1)
  1035. {
  1036. if (params.log)
  1037. console.log('[s] adding node into list for removal');
  1038. toRemove.push(node);
  1039. // add multiple nodes if defined more than one sibling
  1040. siblings = Math.abs(params.siblings) || 0;
  1041. while (siblings)
  1042. {
  1043. node = node[iterFunc];
  1044. if (node.nodeType === Node.ELEMENT_NODE)
  1045. {
  1046. if (params.log)
  1047. console.log('[s] adding sibling node', node);
  1048. toRemove.push(node);
  1049. siblings -= 1; //count only element nodes
  1050. }
  1051. else if (!params.hide)
  1052. {
  1053. if (params.log)
  1054. console.log('[s] adding sibling node', node);
  1055. toRemove.push(node);
  1056. }
  1057. }
  1058. } else {
  1059. if (params.log)
  1060. console.log('[s] node already marked for removal');
  1061. }
  1062. } else {
  1063. if (params.log)
  1064. console.log('[s] word test failed, proceed to the next node');
  1065. }
  1066. }
  1067. if (params.log)
  1068. console.log('[s] proceeding with', (params.hide?'hide':'removal'), 'of', toRemove);
  1069. for (let node of toRemove)
  1070. remFunc(node);
  1071.  
  1072. return toRemove.length;
  1073. }
  1074.  
  1075. // function to perform multiple checks if ads inserted with a delay
  1076. // by default does 30 checks withing a 3 seconds unless nonstop mode specified
  1077. // also does 1 extra check when a page completely loads
  1078. // selector and words - passed dow to scissors
  1079. // params - object with multiple extra parameters:
  1080. // .log - display log in the console
  1081. // .root - selector to narrow down scope to scan;
  1082. // .observe - if true then check will be performed continuously;
  1083. // Other parameters passed down to scissors.
  1084. function gardener(selector, words, params)
  1085. {
  1086. params = params || {};
  1087. if (params.log)
  1088. console.log('[g] starting with', selector, words, JSON.stringify(params));
  1089. let scope = document,
  1090. nonstop = false;
  1091. // narrow down scope to a specific element
  1092. if (params.root)
  1093. {
  1094. scope = scope.querySelector(params.root);
  1095. if (!scope) // exit if the root element is not present on the page
  1096. return 0;
  1097. if (params.log)
  1098. console.log('[g] scope', scope);
  1099. }
  1100. // add observe mode if required
  1101. if (params.observe)
  1102. {
  1103. if (typeof MutationObserver === 'function')
  1104. {
  1105. (new MutationObserver(
  1106. function(ms)
  1107. {
  1108. for (let m of ms) if (m.addedNodes.length)
  1109. scissors(selector, words, scope, params);
  1110. }
  1111. )).observe(scope, { childList:true, subtree: true });
  1112. if (params.log)
  1113. console.log('[g] observer enabled');
  1114. } else {
  1115. nonstop = true;
  1116. if (params.log)
  1117. console.log('[g] nonstop mode enabled');
  1118. }
  1119. }
  1120. // wait for a full page load to do one extra cut
  1121. win.addEventListener(
  1122. 'load', function()
  1123. {
  1124. if (params.log)
  1125. console.log('[g] onload cleanup');
  1126. scissors(selector, words, scope, params);
  1127. }
  1128. );
  1129. // do multiple cuts during page load until ads removed
  1130. function cut(sci, s, w, sc, p, i)
  1131. {
  1132. if (i > 0)
  1133. i -= 1;
  1134. if (i && !sci(s, w, sc, p))
  1135. setTimeout(cut, 100, sci, s, w, sc, p, i);
  1136. }
  1137. cut(scissors, selector, words, scope, params, (nonstop ? -1 : 30));
  1138. }
  1139.  
  1140. // Helper function to close background tab if site opens itself in a new tab and then
  1141. // loads a 3rd-party page in the background one (thus performing background redirect).
  1142. function preventBackgroundRedirect()
  1143. {
  1144. // create "cose_me" event to call high-level window.close()
  1145. let key = Math.random().toString(36).substr(2);
  1146. window.addEventListener('close_me_' + key, () => window.close());
  1147.  
  1148. // window.open wrapper
  1149. function pbrLander()
  1150. {
  1151. let _open = window.open,
  1152. idx = String.prototype.indexOf,
  1153. event = new CustomEvent("close_me_%key%", {});
  1154. // site went to a new tab and attempts to unload
  1155. // call for high-level close through event
  1156. let closeWindow = () => window.dispatchEvent(event);
  1157.  
  1158. // window.open wrapper
  1159. window.open = function open()
  1160. {
  1161. console.log(arguments, window.location.host);
  1162. if (arguments[0] &&
  1163. (idx.call(arguments[0], window.location.host) > -1 ||
  1164. idx.call(arguments[0], '://') === -1))
  1165. window.addEventListener('unload', closeWindow, true);
  1166. _open.apply(window, arguments);
  1167. }.bind(window);
  1168.  
  1169. // Node.createElement wrapper to prevent click-dispatch in Google Chrome and similar browsers
  1170. let _createElement = Document.prototype.createElement;
  1171. Document.prototype.createElement = function createElement(name)
  1172. {
  1173. /*jshint validthis:true */
  1174. let el = _createElement.apply(this, arguments);
  1175. if (el.tagName === 'A')
  1176. el.addEventListener(
  1177. 'click', function(e)
  1178. {
  1179. if (!e.target.parentNode || !e.isTrusted)
  1180. window.addEventListener('unload', closeWindow, true);
  1181. }, false
  1182. );
  1183. return el;
  1184. };
  1185. console.log("Background redirect prevention enabled.");
  1186. }
  1187.  
  1188. // land wrapper on the page
  1189. let script = document.createElement('script');
  1190. script.textContent = '('+pbrLander.toString().replace(/%key%/g,key)+')();';
  1191. _appendChild(script);
  1192. _removeChild(script);
  1193. }
  1194.  
  1195. // Function to catch and block various methods to open a new window with 3rd-party content.
  1196. // Some advertisement networks went way past simple window.open call to circumvent default popup protection.
  1197. // This funciton blocks window.open, ability to restore original window.open from an IFRAME object,
  1198. // ability to perform an untrusted (not initiated by user) click on a link, click on a link without a parent
  1199. // node or simply a link with piece of javascript code in the HREF attribute.
  1200. function preventPopups()
  1201. {
  1202. if (inIFrame)
  1203. {
  1204. let i = -1, val;
  1205. do {
  1206. i++;
  1207. val = GM_getValue('forbid.popups.' + i);
  1208. } while(val & val !== win.location.href);
  1209. GM_setValue('forbid.popups.' + i, win.location.href);
  1210. win.top.postMessage('forbid.popups.' + i, '*');
  1211. return;
  1212. }
  1213.  
  1214. scriptLander(
  1215. function()
  1216. {
  1217. let _createElement = Document.prototype.createElement,
  1218. _appendChild = Element.prototype.appendChild;
  1219.  
  1220. function open()
  1221. {
  1222. '[native code]';
  1223. console.log('Site attempted to open a new window', arguments);
  1224. return {
  1225. document: {
  1226. write: () => {},
  1227. writeln: () => {}
  1228. }
  1229. };
  1230. }
  1231.  
  1232. function redefineOpen(obj)
  1233. {
  1234. Object.defineProperty(obj, 'open', {
  1235. get: () => open,
  1236. set: (val) => val,
  1237. enumerable: true
  1238. });
  1239. }
  1240. redefineOpen(win);
  1241.  
  1242. Document.prototype.createElement = function createElement(name)
  1243. {
  1244. /*jshint validthis:true */
  1245. let el = _createElement.apply(this, arguments);
  1246. if (el.tagName === 'A')
  1247. el.addEventListener(
  1248. 'click', function(e)
  1249. {
  1250. if (!e.target.parentNode || !e.isTrusted ||
  1251. (e.target.href && e.target.href.toLowerCase().indexOf('javascript') > -1))
  1252. {
  1253. e.preventDefault();
  1254. console.log('Blocked suspicious click event', e, 'on', e.target);
  1255. }
  1256. }, false
  1257. );
  1258. if (el.tagName === 'IFRAME')
  1259. el.addEventListener(
  1260. 'load', function(e)
  1261. {
  1262. try {
  1263. redefineOpen(e.target.contentWindow);
  1264. } catch(ignore) {}
  1265. }, false
  1266. );
  1267. return el;
  1268. };
  1269.  
  1270. Element.prototype.appendChild = function appendChild()
  1271. {
  1272. /*jshint validthis:true */
  1273. let el = _appendChild.apply(this, arguments);
  1274. if (el && el.nodeType === Node.ELEMENT_NODE && el.tagName === 'IFRAME') {
  1275. try {
  1276. redefineOpen(el.contentWindow);
  1277. } catch(ignore) {}
  1278. }
  1279. return el;
  1280. };
  1281. console.log('Popup prevention enabled.');
  1282. }
  1283. );
  1284. }
  1285. // External listener for case when site known to open popups were loaded in iframe
  1286. // It will sandbox any iframe which will send message 'forbid.popups' (preventPopups sends it)
  1287. // Some sites replace frame's window.location with data-url to run in clean context
  1288. if (!inIFrame)
  1289. {
  1290. let popWindows = new WeakSet();
  1291. window.addEventListener(
  1292. 'message', function(e)
  1293. {
  1294. if (e.data.slice(0,13) === 'forbid.popups' && !popWindows.has(e.source))
  1295. {
  1296. let src = GM_getValue(e.data);
  1297. if (src)
  1298. GM_deleteValue(e.data);
  1299. popWindows.add(e.source); // remember window of iframe with suspected domain
  1300. for (let frame of document.querySelectorAll('iframe'))
  1301. if (frame.contentWindow === e.source)
  1302. {
  1303. if (frame.hasAttribute('sandbox'))
  1304. // remove allow-popups if frame already sandboxed
  1305. frame.sandbox.remove('allow-popups');
  1306. else
  1307. // set sandbox mode for troublesome frame and allow scripts and forms
  1308. frame.setAttribute('sandbox','allow-forms allow-scripts');
  1309. console.log('Disallowed popups from iframe', frame);
  1310.  
  1311. // reload frame content to apply restrictions
  1312. if (!src) {
  1313. src = frame.src;
  1314. console.log('Unable to get current iframe location, reloading from src', src);
  1315. } else
  1316. console.log('Reloading iframe with URL', src);
  1317. frame.src = 'about:blank';
  1318. frame.src = src;
  1319. }
  1320. }
  1321. }, false
  1322. );
  1323. }
  1324.  
  1325. // Currently unused piece of code developed to prevent site from registering serviceWorker
  1326. // and uninstall any existing instances of serivceWorker in case there is one already.
  1327. /* Commented out since not used
  1328. function forbidServiceWorker()
  1329. {
  1330. if (!("serviceWorker" in navigator))
  1331. return;
  1332. let svr = navigator.serviceWorker.ready;
  1333. Object.defineProperty(navigator, 'serviceWorker', {
  1334. value: {
  1335. register: function()
  1336. {
  1337. console.log('Registration of serviceWorker ' + arguments[0] + ' blocked.');
  1338. return new Promise(function(){});
  1339. },
  1340. ready: new Promise(() => null),
  1341. addEventListener: () => null
  1342. }
  1343. });
  1344. document.addEventListener(
  1345. 'DOMContentLoaded', function()
  1346. {
  1347. if (!svr)
  1348. return;
  1349. svr.then(
  1350. function(sw)
  1351. {
  1352. console.log('Found existing serviceWorker:', sw);
  1353. console.log('Attempting to unregister...');
  1354. sw.unregister().then(
  1355. () => console.log('Done.')
  1356. ).catch(
  1357. function(err)
  1358. {
  1359. console.log('Unregistration failed. :(', err);
  1360. console.log('Try to remove it manually:');
  1361. console.log(' 1. Open: chrome://serviceworker-internals/ (Google Chrome and alike) or about:serviceworkers (Mozilla Firefox) in a new tab.');
  1362. console.log(' 2. Search there for one with "'+document.domain+'" in the name.');
  1363. console.log(' 3. Use buttons in the same block with service you found to stop it and uninstall/unregister.');
  1364. }
  1365. );
  1366. }
  1367. ).catch(
  1368. (e) => console.log("LOL, existing serviceWorker failed on it's own! -_-", e)
  1369. );
  1370. }, false
  1371. );
  1372. }
  1373. /**/
  1374.  
  1375. // Currently obsolete code developed to prevent error and load calls on objects supposed to load resources
  1376. // from the internet like IMG or IFRAME, but missing SRC/HREF attribute. Usually tricks like this are used
  1377. // to unwrap wrapped functions to be able to load ads.
  1378. /* Commented out since not used
  1379. function errorAndLoadEventsFilter()
  1380. {
  1381. let toString = Function.prototype.toString,
  1382. _addEventListener = Element.prototype.addEventListener,
  1383. _removeEventListener = Element.prototype.removeEventListener,
  1384. hasAttribute = Element.prototype.hasAttribute,
  1385. evtMap = new WeakMap();
  1386. Element.prototype.addEventListener = function addEventListener(evt, func, capt) {
  1387. if ((evt === 'error' || evt === 'load') && !evtMap.get(func))
  1388. {
  1389. evtMap.set(
  1390. func, function()
  1391. {
  1392. if (hasAttribute.call(this, 'src') ||
  1393. hasAttribute.call(this, 'href'))
  1394. func.apply(this, arguments);
  1395. else
  1396. console.log('Blocked', evt, 'handler', toString.call(func), 'on', this);
  1397. }
  1398. );
  1399. }
  1400. _addEventListener.call(this, evt, (evtMap.get(func) || func), capt);
  1401. };
  1402. Element.prototype.removeEventListener = function removeEventListener(evt, func, capt) {
  1403. _removeEventListener.call(this, evt, (evtMap.get(func) || func), capt);
  1404. };
  1405. Object.defineProperty(HTMLElement.prototype, 'onload', {
  1406. set: function(func)
  1407. {
  1408. if(evtMap.has(this)) {
  1409. if (evtMap.get(this).onload)
  1410. _removeEventListener.call(this, 'load', evtMap.get(this).onload, false);
  1411. evtMap.get(this).onload = func;
  1412. } else
  1413. evtMap.set(this, { onload: func });
  1414.  
  1415. if (func)
  1416. _addEventListener.call(this, 'load', func, false);
  1417.  
  1418. return func;
  1419. },
  1420. get: function()
  1421. {
  1422. return evtMap.has(this) ? evtMap.get(this).onload : null;
  1423. }
  1424. });
  1425. Object.defineProperty(HTMLElement.prototype, 'onerror', {
  1426. set: function(func)
  1427. {
  1428. if (evtMap.has(this))
  1429. evtMap.get(this).onerror = func;
  1430. else
  1431. evtMap.set(this, { onerror: func });
  1432.  
  1433. if (func)
  1434. console.log('Blocked error handler', toString.call(func), 'on', this);
  1435.  
  1436. return func;
  1437. },
  1438. get: function()
  1439. {
  1440. return evtMap.has(this) ? evtMap.get(this).onerror : null;
  1441. }
  1442. });
  1443. }
  1444. /**/
  1445.  
  1446. // === Scripts for specific domains ===
  1447.  
  1448. let scripts = {};
  1449. // prevent popups and redirects block
  1450. // Popups
  1451. scripts.preventPopups = {
  1452. other: [
  1453. 'biqle.ru',
  1454. 'chaturbate.com',
  1455. 'dfiles.ru',
  1456. 'hentaiz.org',
  1457. 'mirrorcreator.com',
  1458. 'online-multy.ru', 'openload.co',
  1459. 'radikal.ru',
  1460. 'seedoff.cc', 'seedoff.tv',
  1461. 'tapochek.net', 'thepiratebay.org', 'torseed.net',
  1462. 'unionpeer.com',
  1463. 'zippyshare.com'
  1464. ],
  1465. now: preventPopups
  1466. };
  1467. // Background redirects
  1468. scripts.preventBackgroundRedirect = {
  1469. other: [
  1470. 'mediafire.com', 'megapeer.org', 'megapeer.ru',
  1471. 'perfectgirls.net',
  1472. 'turbobit.net'
  1473. ],
  1474. now: preventBackgroundRedirect
  1475. };
  1476.  
  1477. // other
  1478. scripts['4pda.ru'] = {
  1479. now: function()
  1480. {
  1481. // https://greasyfork.org/en/scripts/14470-4pda-unbrender
  1482. let hStyle,
  1483. isForum = document.location.href.search('/forum/') !== -1,
  1484. remove = (node) => (node ? node.parentNode.removeChild(node) : null),
  1485. afterClean = () => remove(hStyle);
  1486.  
  1487. function beforeClean()
  1488. {
  1489. // attach styles before document displayed
  1490. hStyle = createStyle([
  1491. 'html { overflow-y: scroll }',
  1492. 'section[id] {'+(
  1493. 'position: absolute;'+
  1494. 'width: 100%'
  1495. )+'}',
  1496. 'article + aside * { display: none !important }',
  1497. '#header + div:after {'+(
  1498. 'content: "";'+
  1499. 'position: fixed;'+
  1500. 'top: 0;'+
  1501. 'left: 0;'+
  1502. 'width: 100%;'+
  1503. 'height: 100%;'+
  1504. 'background-color: #E6E7E9'
  1505. )+'}',
  1506. // http://codepen.io/Beaugust/pen/DByiE
  1507. '@keyframes spin { 100% { transform: rotate(360deg) } }',
  1508. 'article + aside:after {'+(
  1509. 'content: "";'+
  1510. 'position: absolute;'+
  1511. 'width: 150px;'+
  1512. 'height: 150px;'+
  1513. 'top: 150px;'+
  1514. 'left: 50%;'+
  1515. 'margin-top: -75px;'+
  1516. 'margin-left: -75px;'+
  1517. 'box-sizing: border-box;'+
  1518. 'border-radius: 100%;'+
  1519. 'border: 10px solid rgba(0, 0, 0, 0.2);'+
  1520. 'border-top-color: rgba(0, 0, 0, 0.6);'+
  1521. 'animation: spin 2s infinite linear'
  1522. )+'}'
  1523. ], {id:'ubrHider'}, true);
  1524.  
  1525. // display content of a page if time to load a page is more than 2 seconds to avoid
  1526. // blocking access to a page if it is loading for too long or stuck in a loading state
  1527. setTimeout(2000, afterClean);
  1528. }
  1529.  
  1530. createStyle([
  1531. '#nav .use-ad { display: block !important }',
  1532. 'article:not(.post) + article:not(#id),'+
  1533. 'html:not(#id)>body:not(#id) a[target="_blank"] img[height="90"] { display: none !important }'
  1534. ]);
  1535.  
  1536. if (!isForum)
  1537. beforeClean();
  1538.  
  1539. // save links to non-overridden functions to use later
  1540. let protectedElems;
  1541. // protect/hide changed attributes in case site attempt to restore them
  1542. function styleProtector(eventMode)
  1543. {
  1544. let _toLowerCase = String.prototype.toLowerCase,
  1545. isStyleText = (t) => (_toLowerCase.call(t) === 'style'),
  1546. protectedElems = new WeakMap();
  1547. function protoOverride(element, functionName, isStyleCheck, returnIfProtected)
  1548. {
  1549. let originalFunction = element.prototype[functionName];
  1550. element.prototype[functionName] = function wrapper()
  1551. {
  1552. if (protectedElems.has(this) && isStyleCheck(arguments[0]))
  1553. return returnIfProtected(this, arguments);
  1554. return originalFunction.apply(this, arguments);
  1555. };
  1556. }
  1557. protoOverride(Element, 'removeAttribute', isStyleText, () => undefined);
  1558. protoOverride(Element, 'hasAttribute', isStyleText, (_this) => protectedElems.get(_this) !== null);
  1559. protoOverride(Element, 'setAttribute', isStyleText, (_this, args) => protectedElems.set(_this, args[1]));
  1560. protoOverride(Element, 'getAttribute', isStyleText, (_this) => protectedElems.get(_this));
  1561. if (!eventMode)
  1562. return protectedElems;
  1563. else
  1564. {
  1565. let e = document.createEvent('Event');
  1566. e.initEvent('protoOverride', false, false);
  1567. window.protectedElems = protectedElems;
  1568. window.dispatchEvent(e);
  1569. }
  1570. }
  1571. if (!isFirefox)
  1572. protectedElems = styleProtector(false);
  1573. else
  1574. {
  1575. let script = document.createElement('script');
  1576. script.textContent = '(' + styleProtector.toString() + ')(true);';
  1577. window.addEventListener(
  1578. 'protoOverride', function protoOverrideCallback(e)
  1579. {
  1580. if (win.protectedElems) {
  1581. protectedElems = win.protectedElems;
  1582. delete win.protectedElems;
  1583. }
  1584. document.removeEventListener('protoOverride', protoOverrideCallback, true);
  1585. }, true
  1586. );
  1587. _appendChild(script);
  1588. _removeChild(script);
  1589. }
  1590.  
  1591. // clean a page
  1592. window.addEventListener(
  1593. 'DOMContentLoaded', function()
  1594. {
  1595. let width = () => window.innerWidth || _de.clientWidth || document.body.clientWidth || 0;
  1596. let height = () => window.innerHeight || _de.clientHeight || document.body.clientHeight || 0;
  1597.  
  1598. if (isForum)
  1599. {
  1600. let si = document.querySelector('#logostrip');
  1601. if (si)
  1602. remove(si.parentNode.nextSibling);
  1603. }
  1604.  
  1605. if (document.location.href.search('/forum/dl/') !== -1) {
  1606. document.body.setAttribute('style', (document.body.getAttribute('style')||'')+
  1607. ';background-color:black!important');
  1608. for (let itm of document.querySelectorAll('body>div'))
  1609. if (!itm.querySelector('.dw-fdwlink'))
  1610. remove(itm);
  1611. }
  1612.  
  1613. if (isForum) // Do not continue if it's a forum
  1614. return;
  1615.  
  1616. {
  1617. let si = document.querySelector('#header');
  1618. if (si)
  1619. {
  1620. let rem = si.previousSibling;
  1621. while (rem)
  1622. {
  1623. si = rem.previousSibling;
  1624. remove(rem);
  1625. rem = si;
  1626. }
  1627. }
  1628. }
  1629.  
  1630. for (let itm of document.querySelectorAll('#nav li[class]'))
  1631. if (itm && itm.querySelector('a[href^="/tag/"]'))
  1632. remove(itm);
  1633.  
  1634. let style, result,
  1635. fakeStyles = new WeakMap(),
  1636. styleProxy = {
  1637. get: function(target, prop)
  1638. {
  1639. let fakeStyle = fakeStyles.get(target);
  1640. return ((prop in fakeStyle) ? fakeStyle : target)[prop];
  1641. },
  1642. set: function(target, prop, value)
  1643. {
  1644. let fakeStyle = fakeStyles.get(target);
  1645. ((prop in fakeStyle) ? fakeStyle : target)[prop] = value;
  1646. return value;
  1647. }
  1648. };
  1649. for (let itm of document.querySelectorAll('DIV, A'))
  1650. {
  1651. if (itm.tagName ==='DIV' &&
  1652. itm.offsetWidth > 0.95 * width() &&
  1653. itm.offsetHeight > 0.85 * height())
  1654. {
  1655. style = window.getComputedStyle(itm, null);
  1656. result = [];
  1657.  
  1658. if (style.backgroundImage !== 'none')
  1659. result.push('background-image:none!important');
  1660.  
  1661. if (style.backgroundColor !== 'transparent' &&
  1662. style.backgroundColor !== 'rgba(0, 0, 0, 0)')
  1663. result.push('background-color:transparent!important');
  1664.  
  1665. if (result.length)
  1666. {
  1667. if (itm.getAttribute('style'))
  1668. result.unshift(itm.getAttribute('style'));
  1669.  
  1670. fakeStyles.set(itm.style, {
  1671. 'backgroundImage': itm.style.backgroundImage,
  1672. 'backgroundColor': itm.style.backgroundColor
  1673. });
  1674.  
  1675. try {
  1676. Object.defineProperty(itm, 'style', {
  1677. value: new Proxy(itm.style, styleProxy),
  1678. enumerable: true
  1679. });
  1680. } catch (e) {
  1681. console.log('Unable to protect style property.', e);
  1682. }
  1683.  
  1684. if (protectedElems)
  1685. protectedElems.set(itm, _getAttribute.call(itm, 'style'));
  1686.  
  1687. _setAttribute.call(itm, 'style', result.join(';'));
  1688. }
  1689. }
  1690. if (itm.tagName ==='A' &&
  1691. (itm.offsetWidth > 0.95 * width() ||
  1692. itm.offsetHeight > 0.85 * height()))
  1693. {
  1694. if (protectedElems)
  1695. protectedElems.set(itm, _getAttribute.call(itm, 'style'));
  1696.  
  1697. _setAttribute.call(itm, 'style', 'display:none!important');
  1698. }
  1699. }
  1700.  
  1701. for (let itm of document.querySelectorAll('ASIDE>DIV'))
  1702. if ( ((itm.querySelector('script, iframe, a[href*="/ad/www/"]') ||
  1703. itm.querySelector('img[src$=".gif"]:not([height="0"]), img[height="400"]')) &&
  1704. !itm.classList.contains('post') ) || !itm.childNodes.length )
  1705. remove(itm);
  1706.  
  1707. document.body.setAttribute('style', (document.body.getAttribute('style')||'')+';background-color:#E6E7E9!important');
  1708.  
  1709. // display content of the page
  1710. afterClean();
  1711. }
  1712. );
  1713. }
  1714. };
  1715.  
  1716. scripts['allmovie.pro'] = {
  1717. other: ['rufilmtv.org'],
  1718. dom: function()
  1719. {
  1720. // pretend to be Android to make site use different played for ads
  1721. if (isSafari)
  1722. return;
  1723. Object.defineProperty(navigator, 'userAgent', {
  1724. 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'; },
  1725. enumerable: true
  1726. });
  1727. }
  1728. };
  1729.  
  1730. scripts['anidub-online.ru'] = {
  1731. other: ['online.anidub.com'],
  1732. dom: function()
  1733. {
  1734. if (win.ogonekstart1)
  1735. win.ogonekstart1 = () => console.log("Fire in the hole!");
  1736. },
  1737. now: () => createStyle([
  1738. '.background {background: none!important;}',
  1739. '.background > script + div,'+
  1740. '.background > script ~ div:not([id]):not([class]) + div[id][class]'+
  1741. '{display:none!important}'
  1742. ])
  1743. };
  1744.  
  1745. scripts['drive2.ru'] = () => gardener('.c-block:not([data-metrika="recomm"]),.o-grid__item', />Реклама<\//i);
  1746.  
  1747. scripts['fishki.net'] = () => gardener('.drag_list > .drag_element, .list-view > .paddingtop15, .post-wrap', /543769|Новости\sпартнеров/);
  1748.  
  1749. scripts['gidonline.club'] = {
  1750. now: () => createStyle('.tray > div[style] {display: none!important}')
  1751. };
  1752.  
  1753. scripts['hdgo.cc'] = {
  1754. other: ['46.30.43.38', 'couber.be'],
  1755. now: () => (new MutationObserver(
  1756. function(ms)
  1757. {
  1758. var m, node;
  1759. for (m of ms) for (node of m.addedNodes)
  1760. if (node.tagName === 'SCRIPT' && _getAttribute.call(node, 'onerror') !== null)
  1761. node.removeAttribute('onerror');
  1762. }
  1763. )).observe(document, { childList:true, subtree: true })
  1764. };
  1765.  
  1766. scripts['gismeteo.ru'] = {
  1767. other: ['gismeteo.ua'],
  1768. dom: () => gardener('div > a[target^="_"]', /Яндекс\.Директ/i, { root: 'body', observe: true, parent: 'div[class*="frame"]'})
  1769. };
  1770.  
  1771. scripts['hdrezka.me'] = {
  1772. now: function()
  1773. {
  1774. Object.defineProperty(win, 'fuckAdBlock', {
  1775. value: { onDetected: () => console.log('Pretending to be an ABP detector.') },
  1776. enumerable: true
  1777. });
  1778. Object.defineProperty(win, 'ab', {
  1779. value: false,
  1780. enumerable: true
  1781. });
  1782. },
  1783. dom: () => gardener('div[id][onclick][onmouseup][onmousedown]', /onmouseout/i)
  1784. };
  1785.  
  1786. scripts['imageban.ru'] = {
  1787. now: preventBackgroundRedirect,
  1788. dom: () => win.addEventListener(
  1789. 'unload', function()
  1790. {
  1791. window.location.hash = 'x'+Math.random().toString(36).substr(2);
  1792. }, true
  1793. )
  1794. };
  1795.  
  1796. scripts['mail.ru'] = {
  1797. // Trick to prevent mail.ru from removing 3rd-party styles
  1798. now: () => scriptLander(
  1799. () => Object.defineProperty(Object.prototype, 'restoreVisibility', {
  1800. get: () => (() => null),
  1801. set: () => null
  1802. })
  1803. )
  1804. };
  1805.  
  1806. scripts['megogo.net'] = {
  1807. now: function()
  1808. {
  1809. Object.defineProperty(win, "adBlock", {
  1810. get: () => false,
  1811. set: () => null,
  1812. enumerable : true
  1813. });
  1814. Object.defineProperty(win, "showAdBlockMessage", {
  1815. get: () => (() => null),
  1816. set: () => null,
  1817. enumerable: true
  1818. });
  1819. }
  1820. };
  1821.  
  1822. scripts['naruto-base.su'] = () => gardener('div[id^="entryID"],.block', /href="http.*?target="_blank"/i);
  1823.  
  1824. scripts['overclockers.ru'] = {
  1825. now: function()
  1826. {
  1827. createStyle('.fixoldhtml {display:block!important}');
  1828. if (!isChrome && !isOpera)
  1829. return; // Looks like my code works only in Chrome-like browsers
  1830. let noContentYet = true;
  1831. function jWrap()
  1832. {
  1833. let _$ = win.$, _e = _$.extend;
  1834. win.$ = function()
  1835. {
  1836. let _ret = _$.apply(window, arguments);
  1837. if (_ret[0] === document.body)
  1838. _ret.html = () => console.log('Anti-adblock prevented.');
  1839. return _ret;
  1840. };
  1841. win.$.extend = function()
  1842. {
  1843. return _e.apply(_$, arguments);
  1844. };
  1845. win.jQuery = win.$;
  1846. }
  1847. (function jReady()
  1848. {
  1849. if (!win.$ && noContentYet)
  1850. setTimeout(jReady, 0);
  1851. else
  1852. jWrap();
  1853. })();
  1854. document.addEventListener ('DOMContentLoaded', () => (noContentYet = false), false);
  1855. }
  1856. };
  1857. scripts['forums.overclockers.ru'] = {
  1858. now: function()
  1859. {
  1860. createStyle('.needblock {position: fixed; left: -10000px}');
  1861. Object.defineProperty(win, 'adblck', {
  1862. get: () => 'no',
  1863. set: () => null,
  1864. enumerable: true
  1865. });
  1866. }
  1867. };
  1868.  
  1869. scripts['pb.wtf'] = {
  1870. other: ['piratbit.org', 'piratbit.ru'],
  1871. dom: function()
  1872. {
  1873. createStyle('.reques,#result,tbody.row1:not([id]) {display: none !important}');
  1874. // image in the slider in the header
  1875. gardener('a[href^="/ex"],a[href$="=="]', /img/i, {root:'.release-navbar', observe:true, parent:'div'});
  1876. // ads in blocks on the page
  1877. gardener('a[href^="/topic/234257"]', /Как\sразместить/i, {siblings:-1, root:'#main_content', observe:true, parent:'span[style]'});
  1878. // line above topic content
  1879. gardener('.re_top1', /./, {root:'#main_content', parent:'.hidden-sm'});
  1880. }
  1881. };
  1882.  
  1883. scripts['pikabu.ru'] = () => gardener('.story', /story__sponsor|story__gag|profile\/ads"/i, {root: '.inner_wrap', observe: true});
  1884.  
  1885. scripts['razlozhi.ru'] = {
  1886. 'now': function()
  1887. {
  1888. for (let func of ['createShadowRoot', 'attachShadow'])
  1889. if (func in Element.prototype)
  1890. Element.prototype[func] = function(){ return this.cloneNode(); };
  1891. }
  1892. };
  1893.  
  1894. scripts['rp5.ru'] = {
  1895. other: ['rp5.by', 'rp5.kz', 'rp5.ua'],
  1896. dom: function()
  1897. {
  1898. createStyle('#bannerBottom {display: none!important}');
  1899. let co = document.querySelector('#content');
  1900. if (!co)
  1901. return;
  1902. let nodes = co.parentNode.childNodes,
  1903. i = nodes.length;
  1904. while (i--)
  1905. if (nodes[i] !== co)
  1906. nodes[i].parentNode.removeChild(nodes[i]);
  1907. }
  1908. };
  1909.  
  1910. scripts['rustorka.com'] = {
  1911. other: ['rumedia.ws'],
  1912. now: function()
  1913. {
  1914. createStyle('.header > div:not(.head-block) a, #sidebar1 img, #logo img {opacity:0!important}', {
  1915. id: 'tempHidingStyles'
  1916. }, true);
  1917. preventPopups();
  1918. },
  1919. dom: function()
  1920. {
  1921. for (let o of document.querySelectorAll('IMG, A'))
  1922. if ((o.clientWidth === 728 && o.clientHeight === 90) ||
  1923. (o.clientWidth === 300 && o.clientHeight === 250))
  1924. {
  1925. while (o && o.tagName !== 'A')
  1926. o = o.parentNode;
  1927. if (o)
  1928. _setAttribute.call(o, 'style', 'display: none !important');
  1929. }
  1930. let s = document.querySelector('#tempHidingStyles');
  1931. s.parentNode.removeChild(s);
  1932. }
  1933. };
  1934.  
  1935. scripts['sport-express.ru'] = () => gardener('.js-relap__item',/>Реклама\s+<\//, {root:'.container', observe: true});
  1936.  
  1937. scripts['sports.ru'] = function()
  1938. {
  1939. gardener('.aside-news-list__item', /aside-news-list__advert/i, {root:'.columns-layout__left', observe: true});
  1940. gardener('.material-list__item', /Реклама/i, {root:'.columns-layout', observe: true});
  1941. // extra functionality: shows/hides panel at the top depending on scroll direction
  1942. createStyle([
  1943. '.user-panel__fixed { transition: top 0.2s ease-in-out!important; }',
  1944. '.user-panel-up { top: -40px!important }'
  1945. ], {id: 'userPanelSlide'}, false);
  1946. (function lookForPanel()
  1947. {
  1948. let panel = document.querySelector('.user-panel__fixed');
  1949. if (!panel)
  1950. setTimeout(lookForPanel, 100);
  1951. else
  1952. window.addEventListener(
  1953. 'wheel', function(e)
  1954. {
  1955. if (e.deltaY > 0 && !panel.classList.contains('user-panel-up'))
  1956. panel.classList.add('user-panel-up');
  1957. else if (e.deltaY < 0 && panel.classList.contains('user-panel-up'))
  1958. panel.classList.remove('user-panel-up');
  1959. }, false
  1960. );
  1961. })();
  1962. };
  1963.  
  1964. scripts['vk.com'] = () => gardener('div[data-post-id]', /wall_marked_as_ads/, {root: '#page_wall_posts', observe: true});
  1965.  
  1966. scripts['yap.ru'] = {
  1967. other: ['yaplakal.com'],
  1968. dom: function()
  1969. {
  1970. gardener('form > table[id^="p_row_"]:nth-of-type(2)', /member1438|Administration/);
  1971. gardener('.icon-comments', /member1438|Administration|\/go\/\?http/, {parent:'tr', siblings:-2});
  1972. }
  1973. };
  1974.  
  1975. scripts['rambler.ru'] = {
  1976. now: () => scriptLander(
  1977. function()
  1978. {
  1979. let _createElement = Document.prototype.createElement,
  1980. loadMap = new WeakMap();
  1981. Document.prototype.createElement = function createElement(name) {
  1982. /*jshint validthis:true */
  1983. var el = _createElement.apply(this, arguments);
  1984. if (el.tagName !== 'LINK')
  1985. return el;
  1986. Object.defineProperty(el, 'onload', {
  1987. get: function() {
  1988. return loadMap.get(loadMap.get(this));
  1989. },
  1990. set: function(func) {
  1991. let wrap = loadMap.get(this),
  1992. isContent = /\{\s*content\s*:\s*"[^"]+"/i;
  1993. if (wrap)
  1994. {
  1995. this.removeEventListener('load', wrap, false);
  1996. loadMap.remove(wrap);
  1997. loadMap.remove(this);
  1998. }
  1999. wrap = function(e)
  2000. {
  2001. if (e.target && e.target.sheet && e.target.sheet.cssRules &&
  2002. e.target.sheet.cssRules[0] && e.target.sheet.cssRules[0].cssText &&
  2003. isContent.test(e.target.sheet.cssRules[0].cssText))
  2004. {
  2005. console.log('Blocked "onload" for', e.target.href);
  2006. return false;
  2007. }
  2008. return func.apply(this, arguments);
  2009. };
  2010. loadMap.set(this, wrap);
  2011. loadMap.set(wrap, func);
  2012. this.addEventListener('load', wrap, false);
  2013. },
  2014. enumberable: true
  2015. });
  2016. return el;
  2017. };
  2018. }
  2019. )
  2020. };
  2021.  
  2022. scripts['reactor.cc'] = {
  2023. other: ['joyreactor.cc', 'pornreactor.cc'],
  2024. now: function()
  2025. {
  2026. win.open = (function(){ throw new Error('Redirect prevention.'); }).bind(window);
  2027. },
  2028. click: function(e)
  2029. {
  2030. let node = e.target;
  2031. if (node.nodeType === Node.ELEMENT_NODE &&
  2032. node.style.position === 'absolute' &&
  2033. node.style.zIndex > 0)
  2034. node.parentNode.removeChild(node);
  2035. },
  2036. dom: function()
  2037. {
  2038. let words = new RegExp(
  2039. 'блокировщика рекламы'
  2040. .split('')
  2041. .map(function(e){return e+'[\u200b\u200c\u200d]*';})
  2042. .join('')
  2043. .replace(' ', '\\s*')
  2044. .replace(/[аоре]/g, function(e){return ['[аa]','[оo]','[рp]','[еe]']['аоре'.indexOf(e)];}),
  2045. 'i'),
  2046. can;
  2047. function deeper(spider)
  2048. {
  2049. let c, l, n;
  2050. if (words.test(spider.innerText))
  2051. {
  2052. if (spider.nodeType === Node.TEXT_NODE)
  2053. return true;
  2054. c = spider.childNodes;
  2055. l = c.length;
  2056. n = 0;
  2057. while(l--)
  2058. if (deeper(c[l]), can)
  2059. n++;
  2060. if (n > 0 && n === c.length && spider.offsetHeight < 750)
  2061. can.push(spider);
  2062. return false;
  2063. }
  2064. return true;
  2065. }
  2066. function probe()
  2067. {
  2068. if (words.test(document.body.innerText))
  2069. {
  2070. can = [];
  2071. deeper(document.body);
  2072. let i = can.length, spider;
  2073. while(i--) {
  2074. spider = can[i];
  2075. if (spider.offsetHeight > 10 && spider.offsetHeight < 750)
  2076. _setAttribute.call(spider, 'style', 'background:none!important');
  2077. }
  2078. }
  2079. }
  2080. (new MutationObserver(probe))
  2081. .observe(document, { childList:true, subtree:true });
  2082. }
  2083. };
  2084.  
  2085. scripts['auto.ru'] = function()
  2086. {
  2087. let words = /Реклама|Яндекс.Директ|yandex_ad_/;
  2088. let userAdsListAds = (
  2089. '.listing-list > .listing-item,'+
  2090. '.listing-item_type_fixed.listing-item'
  2091. );
  2092. let catalogAds = (
  2093. 'div[class*="layout_catalog-inline"],'+
  2094. 'div[class$="layout_horizontal"]'
  2095. );
  2096. let otherAds = (
  2097. '.advt_auto,'+
  2098. '.sidebar-block,'+
  2099. '.pager-listing + div[class],'+
  2100. '.card > div[class][style],'+
  2101. '.sidebar > div[class],'+
  2102. '.main-page__section + div[class],'+
  2103. '.listing > tbody'
  2104. );
  2105. gardener(userAdsListAds, words, {root:'.listing-wrap', observe:true});
  2106. gardener(catalogAds, words, {root:'.catalog__page,.content__wrapper', observe:true});
  2107. gardener(otherAds, words);
  2108. };
  2109.  
  2110. scripts['rsload.net'] = {
  2111. load: function()
  2112. {
  2113. let dis = document.querySelector('label[class*="cb-disable"]');
  2114. if (dis)
  2115. dis.click();
  2116. },
  2117. click: function(e)
  2118. {
  2119. let t = e.target;
  2120. if (t && t.href && (/:\/\/\d+\.\d+\.\d+\.\d+\//.test(t.href)))
  2121. t.href = t.href.replace('://','://rsload.net:rsload.net@');
  2122. }
  2123. };
  2124.  
  2125. let domain, name;
  2126. // add alternate domain names if present
  2127. for (name in scripts) if (scripts[name].other)
  2128. for (domain of scripts[name].other) if (!(domain in scripts))
  2129. scripts[domain] = scripts[name];
  2130. // look for current domain in the list and run appropriate code
  2131. domain = document.domain;
  2132. while (domain.indexOf('.') > -1)
  2133. {
  2134. if (domain in scripts)
  2135. {
  2136. if (typeof scripts[domain] === 'function')
  2137. {
  2138. document.addEventListener ('DOMContentLoaded', scripts[domain], false);
  2139. break;
  2140. }
  2141. for (name in scripts[domain])
  2142. switch(name)
  2143. {
  2144. case 'other':
  2145. break;
  2146. case 'now':
  2147. scripts[domain][name]();
  2148. break;
  2149. case 'load':
  2150. window.addEventListener('load', scripts[domain][name], false);
  2151. break;
  2152. case 'dom':
  2153. document.addEventListener('DOMContentLoaded', scripts[domain][name], false);
  2154. break;
  2155. default:
  2156. document.addEventListener (name, scripts[domain][name], false);
  2157. }
  2158. }
  2159. domain = domain.slice(domain.indexOf('.') + 1);
  2160. }
  2161. })();