RU AdList JS Fixes

try to take over the world!

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

  1. // ==UserScript==
  2. // @name RU AdList JS Fixes
  3. // @namespace ruadlist_js_fixes
  4. // @version 20170630.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. let 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(){let 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://gf.qytechs.cn/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. (removeSelf?'let s = document.currentScript; if (s) {s.parentNode.removeChild(s);}':'')+
  274. '})();\n'
  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://gf.qytechs.cn/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://gf.qytechs.cn/en/scripts/809-no-yandex-ads
  725. document.addEventListener(
  726. 'DOMContentLoaded', function()
  727. {
  728. let adWords = [/Яндекс.Директ/i, /Реклама/i, /Ad/i],
  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.replace(/"/g,'');
  757. if (subNode && content && adWords.map((expr)=>expr.test(content)).indexOf(true) > -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 (adWords[0].test(node.textContent) ||
  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. let fakeRoot = {
  855. appendChild: ()=>null,
  856. firstChild: null
  857. }
  858. Element.prototype.createShadowRoot = () => fakeRoot;
  859. Object.defineProperty(Element.prototype, "shadowRoot", {
  860. value: fakeRoot,
  861. enumerable: true,
  862. configurable: false
  863. });
  864. // Partially based on https://gf.qytechs.cn/en/scripts/22737-remove-yandex-redirect
  865. let selectors = (
  866. 'A[onmousedown*="/jsredir"],'+
  867. 'A[data-vdir-href],'+
  868. 'A[data-counter]'
  869. );
  870. let removeTrackingAttributes = function(link)
  871. {
  872. link.removeAttribute('onmousedown');
  873. if (link.hasAttribute('data-vdir-href')) {
  874. link.removeAttribute('data-vdir-href');
  875. link.removeAttribute('data-orig-href');
  876. }
  877. if (link.hasAttribute('data-counter')) {
  878. link.removeAttribute('data-counter');
  879. link.removeAttribute('data-bem');
  880. }
  881. };
  882. let removeTracking = function(scope)
  883. {
  884. for (let link of scope.querySelectorAll(selectors))
  885. removeTrackingAttributes(link);
  886. };
  887. document.addEventListener('DOMContentLoaded', (e) => removeTracking(e.target));
  888. (new MutationObserver(
  889. function(ms)
  890. {
  891. let m, node;
  892. for (m of ms) for (node of m.addedNodes) if (node.nodeType === Node.ELEMENT_NODE)
  893. if (node.tagName === 'A' && node.matches(selectors)) {
  894. removeTrackingAttributes(node);
  895. } else {
  896. removeTracking(node);
  897. }
  898. }
  899. )).observe(_de, { childList: true, subtree: true });
  900.  
  901. //skip fixes for other sites
  902. return;
  903. }
  904.  
  905. // https://gf.qytechs.cn/en/scripts/21937-moonwalk-hdgo-kodik-fix v0.8 (adapted)
  906. document.addEventListener(
  907. 'DOMContentLoaded', function()
  908. {
  909. function log (e) {
  910. console.log('Moonwalk&HDGo&Kodik FIX: ' + e + ' player in ' + win.location.href);
  911. }
  912. if (win.adv_enabled !== undefined && win.condition_detected !== undefined)
  913. {
  914. log('Moonwalk');
  915. if (win.adv_enabled)
  916. win.adv_enabled = false;
  917. win.condition_detected = false;
  918. if (win.MXoverrollCallback)
  919. document.addEventListener(
  920. 'click', function catcher(e)
  921. {
  922. e.stopPropagation();
  923. win.MXoverrollCallback.call(window);
  924. document.removeEventListener('click', catcher, true);
  925. }, true
  926. );
  927. }
  928. else if (win.stat_url !== undefined && win.is_html5 !== undefined && win.is_wp8 !== undefined)
  929. {
  930. log('HDGo');
  931. document.body.onclick = null;
  932. let tmp = document.querySelector('#swtf');
  933. if (tmp)
  934. tmp.style.display = 'none';
  935. if (win.banner_second !== undefined)
  936. win.banner_second = 0;
  937. if (win.$banner_ads !== undefined)
  938. win.$banner_ads = false;
  939. if (win.$new_ads !== undefined)
  940. win.$new_ads = false;
  941. if (win.createCookie !== undefined)
  942. win.createCookie('popup', 'true', '999');
  943. if (win.canRunAds !== undefined && win.canRunAds !== true)
  944. win.canRunAds = true;
  945. }
  946. else if (win.MXoverrollCallback && win.iframeSearch !== undefined)
  947. {
  948. log('Kodik');
  949. let tmp = document.querySelector('.play_button');
  950. if (tmp)
  951. tmp.onclick = win.MXoverrollCallback.bind(window);
  952. win.IsAdBlock = false;
  953. }
  954. }, false
  955. );
  956.  
  957. // Automated protection against specific circumvention method based on unwrapping various functions,
  958. // hiding ads in the Shadow DOM and injecting iFrames with ads. Previously this code were known as
  959. // apiBreaker since it were breaking Shadow DOM and onerror/onload API on specific domains. This
  960. // version should be safe enough to run on majority of sites without actually breaking them.
  961. scriptLander(
  962. function()
  963. {
  964. let blacklist = new WeakMap();
  965. /* Wrap functions used to attach shadow root to a node */
  966. for (let func of ['createShadowRoot', 'attachShadow'])
  967. if (func in Element.prototype)
  968. Element.prototype[func] = (
  969. (func) => function()
  970. {
  971. blacklist.set(this, true);
  972. return func.apply(this, arguments);
  973. }
  974. )(Element.prototype[func]);
  975.  
  976. /* Wrap functions used to insert/append elements to check for IFRAME objects */
  977. for (let func of [/*'appendChild', */'insertBefore'])
  978. Object.defineProperty(
  979. Element.prototype, func, {
  980. enumerable: true,
  981. value: (
  982. (func) => function(el, par)
  983. {
  984. if (el.tagName === 'IFRAME' &&
  985. (typeof par === 'object' && blacklist.get(par)))
  986. {
  987. console.log('Blocked suspicious', func.name, arguments);
  988. return null;
  989. }
  990. return func.apply(this, arguments);
  991. }
  992. )(Element.prototype[func])
  993. }
  994. );
  995. }
  996. );
  997.  
  998. // === Helper functions ===
  999.  
  1000. // function to search and remove nodes by content
  1001. // selector - standard CSS selector to define set of nodes to check
  1002. // words - regular expression to check content of the suspicious nodes
  1003. // params - object with multiple extra parameters:
  1004. // .log - display log in the console
  1005. // .hide - set display to none instead of removing from the page
  1006. // .parent - parent node to remove if content is found in the child node
  1007. // .siblings - number of simling nodes to remove (excluding text nodes)
  1008. let scRemove = (node) => node.parentNode.removeChild(node);
  1009. let scHide = function(node)
  1010. {
  1011. let style = _getAttribute.call(node, 'style') || '',
  1012. hide = ';display:none!important;';
  1013. if (style.indexOf(hide) < 0)
  1014. _setAttribute.call(node, 'style', style + hide);
  1015. };
  1016. function scissors (selector, words, scope, params)
  1017. {
  1018. if (params.log)
  1019. console.log('[s] starting with', selector, words, scope, JSON.stringify(params));
  1020. let remFunc = (params.hide ? scHide : scRemove),
  1021. iterFunc = (params.siblings > 0 ? 'nextSibling' : 'previousSibling'),
  1022. toRemove = [],
  1023. siblings;
  1024. for (let node of scope.querySelectorAll(selector))
  1025. {
  1026. if (params.log)
  1027. console.log('[s] found node', node);
  1028. if (params.parent)
  1029. {
  1030. while(node !== scope && !(node.matches(params.parent)))
  1031. node = node.parentNode;
  1032. if (params.log)
  1033. console.log('[s] moving to parent node', node);
  1034. if (node === scope)
  1035. {
  1036. if (params.log)
  1037. console.log('[s] reached scope node, nothing to remove here.');
  1038. break;
  1039. }
  1040. }
  1041. if (words.test(node.innerHTML) || !node.childNodes.length)
  1042. {
  1043. // drill up to the specified parent node if required
  1044. if (toRemove.indexOf(node) === -1)
  1045. {
  1046. if (params.log)
  1047. console.log('[s] adding node into list for removal');
  1048. toRemove.push(node);
  1049. // add multiple nodes if defined more than one sibling
  1050. siblings = Math.abs(params.siblings) || 0;
  1051. while (siblings)
  1052. {
  1053. node = node[iterFunc];
  1054. if (node.nodeType === Node.ELEMENT_NODE)
  1055. {
  1056. if (params.log)
  1057. console.log('[s] adding sibling node', node);
  1058. toRemove.push(node);
  1059. siblings -= 1; //count only element nodes
  1060. }
  1061. else if (!params.hide)
  1062. {
  1063. if (params.log)
  1064. console.log('[s] adding sibling node', node);
  1065. toRemove.push(node);
  1066. }
  1067. }
  1068. } else {
  1069. if (params.log)
  1070. console.log('[s] node already marked for removal');
  1071. }
  1072. } else {
  1073. if (params.log)
  1074. console.log('[s] word test failed, proceed to the next node');
  1075. }
  1076. }
  1077. if (params.log)
  1078. console.log('[s] proceeding with', (params.hide?'hide':'removal'), 'of', toRemove);
  1079. for (let node of toRemove)
  1080. remFunc(node);
  1081.  
  1082. return toRemove.length;
  1083. }
  1084.  
  1085. // function to perform multiple checks if ads inserted with a delay
  1086. // by default does 30 checks withing a 3 seconds unless nonstop mode specified
  1087. // also does 1 extra check when a page completely loads
  1088. // selector and words - passed dow to scissors
  1089. // params - object with multiple extra parameters:
  1090. // .log - display log in the console
  1091. // .root - selector to narrow down scope to scan;
  1092. // .observe - if true then check will be performed continuously;
  1093. // Other parameters passed down to scissors.
  1094. function gardener(selector, words, params)
  1095. {
  1096. params = params || {};
  1097. if (params.log)
  1098. console.log('[g] starting with', selector, words, JSON.stringify(params));
  1099. let scope = document,
  1100. nonstop = false;
  1101. // narrow down scope to a specific element
  1102. if (params.root)
  1103. {
  1104. scope = scope.querySelector(params.root);
  1105. if (!scope) // exit if the root element is not present on the page
  1106. return 0;
  1107. if (params.log)
  1108. console.log('[g] scope', scope);
  1109. }
  1110. // add observe mode if required
  1111. if (params.observe)
  1112. {
  1113. if (typeof MutationObserver === 'function')
  1114. {
  1115. (new MutationObserver(
  1116. function(ms)
  1117. {
  1118. for (let m of ms) if (m.addedNodes.length)
  1119. scissors(selector, words, scope, params);
  1120. }
  1121. )).observe(scope, { childList:true, subtree: true });
  1122. if (params.log)
  1123. console.log('[g] observer enabled');
  1124. } else {
  1125. nonstop = true;
  1126. if (params.log)
  1127. console.log('[g] nonstop mode enabled');
  1128. }
  1129. }
  1130. // wait for a full page load to do one extra cut
  1131. win.addEventListener(
  1132. 'load', function()
  1133. {
  1134. if (params.log)
  1135. console.log('[g] onload cleanup');
  1136. scissors(selector, words, scope, params);
  1137. }
  1138. );
  1139. // do multiple cuts during page load until ads removed
  1140. function cut(sci, s, w, sc, p, i)
  1141. {
  1142. if (i > 0)
  1143. i -= 1;
  1144. if (i && !sci(s, w, sc, p))
  1145. setTimeout(cut, 100, sci, s, w, sc, p, i);
  1146. }
  1147. cut(scissors, selector, words, scope, params, (nonstop ? -1 : 30));
  1148. }
  1149.  
  1150. // Helper function to close background tab if site opens itself in a new tab and then
  1151. // loads a 3rd-party page in the background one (thus performing background redirect).
  1152. function preventBackgroundRedirect()
  1153. {
  1154. // create "cose_me" event to call high-level window.close()
  1155. let key = Math.random().toString(36).substr(2);
  1156. window.addEventListener('close_me_' + key, () => window.close());
  1157.  
  1158. // window.open wrapper
  1159. function pbrLander()
  1160. {
  1161. let _open = window.open,
  1162. idx = String.prototype.indexOf,
  1163. event = new CustomEvent("close_me_%key%", {});
  1164. // site went to a new tab and attempts to unload
  1165. // call for high-level close through event
  1166. let closeWindow = () => window.dispatchEvent(event);
  1167.  
  1168. // window.open wrapper
  1169. window.open = function open()
  1170. {
  1171. console.log(arguments, window.location.host);
  1172. if (arguments[0] &&
  1173. (idx.call(arguments[0], window.location.host) > -1 ||
  1174. idx.call(arguments[0], '://') === -1))
  1175. window.addEventListener('unload', closeWindow, true);
  1176. _open.apply(window, arguments);
  1177. }.bind(window);
  1178.  
  1179. // Node.createElement wrapper to prevent click-dispatch in Google Chrome and similar browsers
  1180. let _createElement = Document.prototype.createElement;
  1181. Document.prototype.createElement = function createElement(name)
  1182. {
  1183. /*jshint validthis:true */
  1184. let el = _createElement.apply(this, arguments);
  1185. if (el.tagName === 'A')
  1186. el.addEventListener(
  1187. 'click', function(e)
  1188. {
  1189. if (!e.target.parentNode || !e.isTrusted)
  1190. window.addEventListener('unload', closeWindow, true);
  1191. }, false
  1192. );
  1193. return el;
  1194. };
  1195. console.log("Background redirect prevention enabled.");
  1196. }
  1197.  
  1198. // land wrapper on the page
  1199. let script = document.createElement('script');
  1200. script.textContent = '('+pbrLander.toString().replace(/%key%/g,key)+')();';
  1201. _appendChild(script);
  1202. _removeChild(script);
  1203. }
  1204.  
  1205. // Function to catch and block various methods to open a new window with 3rd-party content.
  1206. // Some advertisement networks went way past simple window.open call to circumvent default popup protection.
  1207. // This funciton blocks window.open, ability to restore original window.open from an IFRAME object,
  1208. // ability to perform an untrusted (not initiated by user) click on a link, click on a link without a parent
  1209. // node or simply a link with piece of javascript code in the HREF attribute.
  1210. function preventPopups()
  1211. {
  1212. if (inIFrame)
  1213. {
  1214. let i = -1, val;
  1215. do {
  1216. i++;
  1217. val = GM_getValue('forbid.popups.' + i);
  1218. } while(val & val !== win.location.href);
  1219. GM_setValue('forbid.popups.' + i, win.location.href);
  1220. win.top.postMessage('forbid.popups.' + i, '*');
  1221. return;
  1222. }
  1223.  
  1224. scriptLander(
  1225. function()
  1226. {
  1227. let _createElement = Document.prototype.createElement,
  1228. _appendChild = Element.prototype.appendChild;
  1229.  
  1230. function open()
  1231. {
  1232. '[native code]';
  1233. console.log('Site attempted to open a new window', arguments);
  1234. return {
  1235. document: {
  1236. write: () => {},
  1237. writeln: () => {}
  1238. }
  1239. };
  1240. }
  1241.  
  1242. function redefineOpen(obj)
  1243. {
  1244. Object.defineProperty(obj, 'open', {
  1245. get: () => open,
  1246. set: (val) => val,
  1247. enumerable: true
  1248. });
  1249. }
  1250. redefineOpen(win);
  1251.  
  1252. Document.prototype.createElement = function createElement(name)
  1253. {
  1254. /*jshint validthis:true */
  1255. let el = _createElement.apply(this, arguments);
  1256. if (el.tagName === 'A')
  1257. el.addEventListener(
  1258. 'click', function(e)
  1259. {
  1260. if (!e.target.parentNode || !e.isTrusted ||
  1261. (e.target.href && e.target.href.toLowerCase().indexOf('javascript') > -1))
  1262. {
  1263. e.preventDefault();
  1264. console.log('Blocked suspicious click event', e, 'on', e.target);
  1265. }
  1266. }, false
  1267. );
  1268. if (el.tagName === 'IFRAME')
  1269. el.addEventListener(
  1270. 'load', function(e)
  1271. {
  1272. try {
  1273. redefineOpen(e.target.contentWindow);
  1274. } catch(ignore) {}
  1275. }, false
  1276. );
  1277. return el;
  1278. };
  1279.  
  1280. Element.prototype.appendChild = function appendChild()
  1281. {
  1282. /*jshint validthis:true */
  1283. let el = _appendChild.apply(this, arguments);
  1284. if (el && el.nodeType === Node.ELEMENT_NODE && el.tagName === 'IFRAME') {
  1285. try {
  1286. redefineOpen(el.contentWindow);
  1287. } catch(ignore) {}
  1288. }
  1289. return el;
  1290. };
  1291. console.log('Popup prevention enabled.');
  1292. }
  1293. );
  1294. }
  1295. // External listener for case when site known to open popups were loaded in iframe
  1296. // It will sandbox any iframe which will send message 'forbid.popups' (preventPopups sends it)
  1297. // Some sites replace frame's window.location with data-url to run in clean context
  1298. if (!inIFrame)
  1299. {
  1300. let popWindows = new WeakSet();
  1301. window.addEventListener(
  1302. 'message', function(e)
  1303. {
  1304. if (e.data.slice(0,13) === 'forbid.popups' && !popWindows.has(e.source))
  1305. {
  1306. let src = GM_getValue(e.data);
  1307. if (src)
  1308. GM_deleteValue(e.data);
  1309. popWindows.add(e.source); // remember window of iframe with suspected domain
  1310. for (let frame of document.querySelectorAll('iframe'))
  1311. if (frame.contentWindow === e.source)
  1312. {
  1313. if (frame.hasAttribute('sandbox'))
  1314. // remove allow-popups if frame already sandboxed
  1315. frame.sandbox.remove('allow-popups');
  1316. else
  1317. // set sandbox mode for troublesome frame and allow scripts and forms
  1318. frame.setAttribute('sandbox','allow-forms allow-scripts');
  1319. console.log('Disallowed popups from iframe', frame);
  1320.  
  1321. // reload frame content to apply restrictions
  1322. if (!src) {
  1323. src = frame.src;
  1324. console.log('Unable to get current iframe location, reloading from src', src);
  1325. } else
  1326. console.log('Reloading iframe with URL', src);
  1327. frame.src = 'about:blank';
  1328. frame.src = src;
  1329. }
  1330. }
  1331. }, false
  1332. );
  1333. }
  1334.  
  1335. // Currently unused piece of code developed to prevent site from registering serviceWorker
  1336. // and uninstall any existing instances of serivceWorker in case there is one already.
  1337. /* Commented out since not used
  1338. function forbidServiceWorker()
  1339. {
  1340. if (!("serviceWorker" in navigator))
  1341. return;
  1342. let svr = navigator.serviceWorker.ready;
  1343. Object.defineProperty(navigator, 'serviceWorker', {
  1344. value: {
  1345. register: function()
  1346. {
  1347. console.log('Registration of serviceWorker ' + arguments[0] + ' blocked.');
  1348. return new Promise(function(){});
  1349. },
  1350. ready: new Promise(() => null),
  1351. addEventListener: () => null
  1352. }
  1353. });
  1354. document.addEventListener(
  1355. 'DOMContentLoaded', function()
  1356. {
  1357. if (!svr)
  1358. return;
  1359. svr.then(
  1360. function(sw)
  1361. {
  1362. console.log('Found existing serviceWorker:', sw);
  1363. console.log('Attempting to unregister...');
  1364. sw.unregister().then(
  1365. () => console.log('Done.')
  1366. ).catch(
  1367. function(err)
  1368. {
  1369. console.log('Unregistration failed. :(', err);
  1370. console.log('Try to remove it manually:');
  1371. console.log(' 1. Open: chrome://serviceworker-internals/ (Google Chrome and alike) or about:serviceworkers (Mozilla Firefox) in a new tab.');
  1372. console.log(' 2. Search there for one with "'+document.domain+'" in the name.');
  1373. console.log(' 3. Use buttons in the same block with service you found to stop it and uninstall/unregister.');
  1374. }
  1375. );
  1376. }
  1377. ).catch(
  1378. (e) => console.log("LOL, existing serviceWorker failed on it's own! -_-", e)
  1379. );
  1380. }, false
  1381. );
  1382. }
  1383. /**/
  1384.  
  1385. // Currently obsolete code developed to prevent error and load calls on objects supposed to load resources
  1386. // from the internet like IMG or IFRAME, but missing SRC/HREF attribute. Usually tricks like this are used
  1387. // to unwrap wrapped functions to be able to load ads.
  1388. /* Commented out since not used
  1389. function errorAndLoadEventsFilter()
  1390. {
  1391. let toString = Function.prototype.toString,
  1392. _addEventListener = Element.prototype.addEventListener,
  1393. _removeEventListener = Element.prototype.removeEventListener,
  1394. hasAttribute = Element.prototype.hasAttribute,
  1395. evtMap = new WeakMap();
  1396. Element.prototype.addEventListener = function addEventListener(evt, func, capt) {
  1397. if ((evt === 'error' || evt === 'load') && !evtMap.get(func))
  1398. {
  1399. evtMap.set(
  1400. func, function()
  1401. {
  1402. if (hasAttribute.call(this, 'src') ||
  1403. hasAttribute.call(this, 'href'))
  1404. func.apply(this, arguments);
  1405. else
  1406. console.log('Blocked', evt, 'handler', toString.call(func), 'on', this);
  1407. }
  1408. );
  1409. }
  1410. _addEventListener.call(this, evt, (evtMap.get(func) || func), capt);
  1411. };
  1412. Element.prototype.removeEventListener = function removeEventListener(evt, func, capt) {
  1413. _removeEventListener.call(this, evt, (evtMap.get(func) || func), capt);
  1414. };
  1415. Object.defineProperty(HTMLElement.prototype, 'onload', {
  1416. set: function(func)
  1417. {
  1418. if(evtMap.has(this)) {
  1419. if (evtMap.get(this).onload)
  1420. _removeEventListener.call(this, 'load', evtMap.get(this).onload, false);
  1421. evtMap.get(this).onload = func;
  1422. } else
  1423. evtMap.set(this, { onload: func });
  1424.  
  1425. if (func)
  1426. _addEventListener.call(this, 'load', func, false);
  1427.  
  1428. return func;
  1429. },
  1430. get: function()
  1431. {
  1432. return evtMap.has(this) ? evtMap.get(this).onload : null;
  1433. }
  1434. });
  1435. Object.defineProperty(HTMLElement.prototype, 'onerror', {
  1436. set: function(func)
  1437. {
  1438. if (evtMap.has(this))
  1439. evtMap.get(this).onerror = func;
  1440. else
  1441. evtMap.set(this, { onerror: func });
  1442.  
  1443. if (func)
  1444. console.log('Blocked error handler', toString.call(func), 'on', this);
  1445.  
  1446. return func;
  1447. },
  1448. get: function()
  1449. {
  1450. return evtMap.has(this) ? evtMap.get(this).onerror : null;
  1451. }
  1452. });
  1453. }
  1454. /**/
  1455.  
  1456. // === Scripts for specific domains ===
  1457.  
  1458. let scripts = {};
  1459. // prevent popups and redirects block
  1460. // Popups
  1461. scripts.preventPopups = {
  1462. other: [
  1463. 'biqle.ru',
  1464. 'chaturbate.com',
  1465. 'dfiles.ru',
  1466. 'hentaiz.org',
  1467. 'mirrorcreator.com',
  1468. 'online-multy.ru', 'openload.co',
  1469. 'radikal.ru',
  1470. 'seedoff.cc', 'seedoff.tv',
  1471. 'tapochek.net', 'thepiratebay.org', 'torseed.net',
  1472. 'unionpeer.com',
  1473. 'zippyshare.com'
  1474. ],
  1475. now: preventPopups
  1476. };
  1477. // Background redirects
  1478. scripts.preventBackgroundRedirect = {
  1479. other: [
  1480. 'mediafire.com', 'megapeer.org', 'megapeer.ru',
  1481. 'perfectgirls.net',
  1482. 'turbobit.net'
  1483. ],
  1484. now: preventBackgroundRedirect
  1485. };
  1486.  
  1487. // other
  1488. scripts['4pda.ru'] = {
  1489. now: function()
  1490. {
  1491. // https://gf.qytechs.cn/en/scripts/14470-4pda-unbrender
  1492. let hStyle,
  1493. isForum = document.location.href.search('/forum/') !== -1,
  1494. remove = (node) => (node ? node.parentNode.removeChild(node) : null),
  1495. afterClean = () => remove(hStyle);
  1496.  
  1497. function beforeClean()
  1498. {
  1499. // attach styles before document displayed
  1500. hStyle = createStyle([
  1501. 'html { overflow-y: scroll }',
  1502. 'section[id] {'+(
  1503. 'position: absolute;'+
  1504. 'width: 100%'
  1505. )+'}',
  1506. 'article + aside * { display: none !important }',
  1507. '#header + div:after {'+(
  1508. 'content: "";'+
  1509. 'position: fixed;'+
  1510. 'top: 0;'+
  1511. 'left: 0;'+
  1512. 'width: 100%;'+
  1513. 'height: 100%;'+
  1514. 'background-color: #E6E7E9'
  1515. )+'}',
  1516. // http://codepen.io/Beaugust/pen/DByiE
  1517. '@keyframes spin { 100% { transform: rotate(360deg) } }',
  1518. 'article + aside:after {'+(
  1519. 'content: "";'+
  1520. 'position: absolute;'+
  1521. 'width: 150px;'+
  1522. 'height: 150px;'+
  1523. 'top: 150px;'+
  1524. 'left: 50%;'+
  1525. 'margin-top: -75px;'+
  1526. 'margin-left: -75px;'+
  1527. 'box-sizing: border-box;'+
  1528. 'border-radius: 100%;'+
  1529. 'border: 10px solid rgba(0, 0, 0, 0.2);'+
  1530. 'border-top-color: rgba(0, 0, 0, 0.6);'+
  1531. 'animation: spin 2s infinite linear'
  1532. )+'}'
  1533. ], {id:'ubrHider'}, true);
  1534.  
  1535. // display content of a page if time to load a page is more than 2 seconds to avoid
  1536. // blocking access to a page if it is loading for too long or stuck in a loading state
  1537. setTimeout(2000, afterClean);
  1538. }
  1539.  
  1540. createStyle([
  1541. '#nav .use-ad { display: block !important }',
  1542. 'article:not(.post) + article:not(#id),'+
  1543. 'html:not(#id)>body:not(#id) a[target="_blank"] img[height="90"] { display: none !important }'
  1544. ]);
  1545.  
  1546. if (!isForum)
  1547. beforeClean();
  1548.  
  1549. // save links to non-overridden functions to use later
  1550. let protectedElems;
  1551. // protect/hide changed attributes in case site attempt to restore them
  1552. function styleProtector(eventMode)
  1553. {
  1554. let _toLowerCase = String.prototype.toLowerCase,
  1555. isStyleText = (t) => (_toLowerCase.call(t) === 'style'),
  1556. protectedElems = new WeakMap();
  1557. function protoOverride(element, functionName, isStyleCheck, returnIfProtected)
  1558. {
  1559. let originalFunction = element.prototype[functionName];
  1560. element.prototype[functionName] = function wrapper()
  1561. {
  1562. if (protectedElems.has(this) && isStyleCheck(arguments[0]))
  1563. return returnIfProtected(this, arguments);
  1564. return originalFunction.apply(this, arguments);
  1565. };
  1566. }
  1567. protoOverride(Element, 'removeAttribute', isStyleText, () => undefined);
  1568. protoOverride(Element, 'hasAttribute', isStyleText, (_this) => protectedElems.get(_this) !== null);
  1569. protoOverride(Element, 'setAttribute', isStyleText, (_this, args) => protectedElems.set(_this, args[1]));
  1570. protoOverride(Element, 'getAttribute', isStyleText, (_this) => protectedElems.get(_this));
  1571. if (!eventMode)
  1572. return protectedElems;
  1573. else
  1574. {
  1575. let e = document.createEvent('Event');
  1576. e.initEvent('protoOverride', false, false);
  1577. window.protectedElems = protectedElems;
  1578. window.dispatchEvent(e);
  1579. }
  1580. }
  1581. if (!isFirefox)
  1582. protectedElems = styleProtector(false);
  1583. else
  1584. {
  1585. let script = document.createElement('script');
  1586. script.textContent = '(' + styleProtector.toString() + ')(true);';
  1587. window.addEventListener(
  1588. 'protoOverride', function protoOverrideCallback(e)
  1589. {
  1590. if (win.protectedElems) {
  1591. protectedElems = win.protectedElems;
  1592. delete win.protectedElems;
  1593. }
  1594. document.removeEventListener('protoOverride', protoOverrideCallback, true);
  1595. }, true
  1596. );
  1597. _appendChild(script);
  1598. _removeChild(script);
  1599. }
  1600.  
  1601. // clean a page
  1602. window.addEventListener(
  1603. 'DOMContentLoaded', function()
  1604. {
  1605. let width = () => window.innerWidth || _de.clientWidth || document.body.clientWidth || 0;
  1606. let height = () => window.innerHeight || _de.clientHeight || document.body.clientHeight || 0;
  1607.  
  1608. if (isForum)
  1609. {
  1610. let si = document.querySelector('#logostrip');
  1611. if (si)
  1612. remove(si.parentNode.nextSibling);
  1613. }
  1614.  
  1615. if (document.location.href.search('/forum/dl/') !== -1) {
  1616. document.body.setAttribute('style', (document.body.getAttribute('style')||'')+
  1617. ';background-color:black!important');
  1618. for (let itm of document.querySelectorAll('body>div'))
  1619. if (!itm.querySelector('.dw-fdwlink'))
  1620. remove(itm);
  1621. }
  1622.  
  1623. if (isForum) // Do not continue if it's a forum
  1624. return;
  1625.  
  1626. {
  1627. let si = document.querySelector('#header');
  1628. if (si)
  1629. {
  1630. let rem = si.previousSibling;
  1631. while (rem)
  1632. {
  1633. si = rem.previousSibling;
  1634. remove(rem);
  1635. rem = si;
  1636. }
  1637. }
  1638. }
  1639.  
  1640. for (let itm of document.querySelectorAll('#nav li[class]'))
  1641. if (itm && itm.querySelector('a[href^="/tag/"]'))
  1642. remove(itm);
  1643.  
  1644. let style, result,
  1645. fakeStyles = new WeakMap(),
  1646. styleProxy = {
  1647. get: function(target, prop)
  1648. {
  1649. let fakeStyle = fakeStyles.get(target);
  1650. return ((prop in fakeStyle) ? fakeStyle : target)[prop];
  1651. },
  1652. set: function(target, prop, value)
  1653. {
  1654. let fakeStyle = fakeStyles.get(target);
  1655. ((prop in fakeStyle) ? fakeStyle : target)[prop] = value;
  1656. return value;
  1657. }
  1658. };
  1659. for (let itm of document.querySelectorAll('DIV, A'))
  1660. {
  1661. if (itm.tagName ==='DIV' &&
  1662. itm.offsetWidth > 0.95 * width() &&
  1663. itm.offsetHeight > 0.85 * height())
  1664. {
  1665. style = window.getComputedStyle(itm, null);
  1666. result = [];
  1667.  
  1668. if (style.backgroundImage !== 'none')
  1669. result.push('background-image:none!important');
  1670.  
  1671. if (style.backgroundColor !== 'transparent' &&
  1672. style.backgroundColor !== 'rgba(0, 0, 0, 0)')
  1673. result.push('background-color:transparent!important');
  1674.  
  1675. if (result.length)
  1676. {
  1677. if (itm.getAttribute('style'))
  1678. result.unshift(itm.getAttribute('style'));
  1679.  
  1680. fakeStyles.set(itm.style, {
  1681. 'backgroundImage': itm.style.backgroundImage,
  1682. 'backgroundColor': itm.style.backgroundColor
  1683. });
  1684.  
  1685. try {
  1686. Object.defineProperty(itm, 'style', {
  1687. value: new Proxy(itm.style, styleProxy),
  1688. enumerable: true
  1689. });
  1690. } catch (e) {
  1691. console.log('Unable to protect style property.', e);
  1692. }
  1693.  
  1694. if (protectedElems)
  1695. protectedElems.set(itm, _getAttribute.call(itm, 'style'));
  1696.  
  1697. _setAttribute.call(itm, 'style', result.join(';'));
  1698. }
  1699. }
  1700. if (itm.tagName ==='A' &&
  1701. (itm.offsetWidth > 0.95 * width() ||
  1702. itm.offsetHeight > 0.85 * height()))
  1703. {
  1704. if (protectedElems)
  1705. protectedElems.set(itm, _getAttribute.call(itm, 'style'));
  1706.  
  1707. _setAttribute.call(itm, 'style', 'display:none!important');
  1708. }
  1709. }
  1710.  
  1711. for (let itm of document.querySelectorAll('ASIDE>DIV'))
  1712. if ( ((itm.querySelector('script, iframe, a[href*="/ad/www/"]') ||
  1713. itm.querySelector('img[src$=".gif"]:not([height="0"]), img[height="400"]')) &&
  1714. !itm.classList.contains('post') ) || !itm.childNodes.length )
  1715. remove(itm);
  1716.  
  1717. document.body.setAttribute('style', (document.body.getAttribute('style')||'')+';background-color:#E6E7E9!important');
  1718.  
  1719. // display content of the page
  1720. afterClean();
  1721. }
  1722. );
  1723. }
  1724. };
  1725.  
  1726. scripts['allmovie.pro'] = {
  1727. other: ['rufilmtv.org'],
  1728. dom: function()
  1729. {
  1730. // pretend to be Android to make site use different played for ads
  1731. if (isSafari)
  1732. return;
  1733. Object.defineProperty(navigator, 'userAgent', {
  1734. 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'; },
  1735. enumerable: true
  1736. });
  1737. }
  1738. };
  1739.  
  1740. scripts['anidub-online.ru'] = {
  1741. other: ['online.anidub.com'],
  1742. dom: function()
  1743. {
  1744. if (win.ogonekstart1)
  1745. win.ogonekstart1 = () => console.log("Fire in the hole!");
  1746. },
  1747. now: () => createStyle([
  1748. '.background {background: none!important;}',
  1749. '.background > script + div,'+
  1750. '.background > script ~ div:not([id]):not([class]) + div[id][class]'+
  1751. '{display:none!important}'
  1752. ])
  1753. };
  1754.  
  1755. scripts['drive2.ru'] = () => gardener('.c-block:not([data-metrika="recomm"]),.o-grid__item', />Реклама<\//i);
  1756.  
  1757. scripts['fishki.net'] = () => gardener('.drag_list > .drag_element, .list-view > .paddingtop15, .post-wrap', /543769|Новости\sпартнеров/);
  1758.  
  1759. scripts['gidonline.club'] = {
  1760. now: () => createStyle('.tray > div[style] {display: none!important}')
  1761. };
  1762.  
  1763. scripts['hdgo.cc'] = {
  1764. other: ['46.30.43.38', 'couber.be'],
  1765. now: () => (new MutationObserver(
  1766. function(ms)
  1767. {
  1768. let m, node;
  1769. for (m of ms) for (node of m.addedNodes)
  1770. if (node.tagName === 'SCRIPT' && _getAttribute.call(node, 'onerror') !== null)
  1771. node.removeAttribute('onerror');
  1772. }
  1773. )).observe(document, { childList:true, subtree: true })
  1774. };
  1775.  
  1776. scripts['gismeteo.ru'] = {
  1777. other: ['gismeteo.ua'],
  1778. dom: () => gardener('div > a[target^="_"]', /Яндекс\.Директ/i, { root: 'body', observe: true, parent: 'div[class*="frame"]'})
  1779. };
  1780.  
  1781. scripts['hdrezka.me'] = {
  1782. now: function()
  1783. {
  1784. Object.defineProperty(win, 'fuckAdBlock', {
  1785. value: { onDetected: () => console.log('Pretending to be an ABP detector.') },
  1786. enumerable: true
  1787. });
  1788. Object.defineProperty(win, 'ab', {
  1789. value: false,
  1790. enumerable: true
  1791. });
  1792. },
  1793. dom: () => gardener('div[id][onclick][onmouseup][onmousedown]', /onmouseout/i)
  1794. };
  1795.  
  1796. scripts['imageban.ru'] = {
  1797. now: preventBackgroundRedirect,
  1798. dom: () => win.addEventListener(
  1799. 'unload', function()
  1800. {
  1801. window.location.hash = 'x'+Math.random().toString(36).substr(2);
  1802. }, true
  1803. )
  1804. };
  1805.  
  1806. scripts['mail.ru'] = {
  1807. // Trick to prevent mail.ru from removing 3rd-party styles
  1808. now: () => scriptLander(
  1809. () => Object.defineProperty(Object.prototype, 'restoreVisibility', {
  1810. get: () => (() => null),
  1811. set: () => null
  1812. })
  1813. )
  1814. };
  1815.  
  1816. scripts['megogo.net'] = {
  1817. now: function()
  1818. {
  1819. Object.defineProperty(win, "adBlock", {
  1820. get: () => false,
  1821. set: () => null,
  1822. enumerable : true
  1823. });
  1824. Object.defineProperty(win, "showAdBlockMessage", {
  1825. get: () => (() => null),
  1826. set: () => null,
  1827. enumerable: true
  1828. });
  1829. }
  1830. };
  1831.  
  1832. scripts['naruto-base.su'] = () => gardener('div[id^="entryID"],.block', /href="http.*?target="_blank"/i);
  1833.  
  1834. scripts['overclockers.ru'] = {
  1835. now: function()
  1836. {
  1837. createStyle('.fixoldhtml {display:block!important}');
  1838. if (!isChrome && !isOpera)
  1839. return; // Looks like my code works only in Chrome-like browsers
  1840. let noContentYet = true;
  1841. function jWrap()
  1842. {
  1843. let _$ = win.$, _e = _$.extend;
  1844. win.$ = function()
  1845. {
  1846. let _ret = _$.apply(window, arguments);
  1847. if (_ret[0] === document.body)
  1848. _ret.html = () => console.log('Anti-adblock prevented.');
  1849. return _ret;
  1850. };
  1851. win.$.extend = function()
  1852. {
  1853. return _e.apply(_$, arguments);
  1854. };
  1855. win.jQuery = win.$;
  1856. }
  1857. (function jReady()
  1858. {
  1859. if (!win.$ && noContentYet)
  1860. setTimeout(jReady, 0);
  1861. else
  1862. jWrap();
  1863. })();
  1864. document.addEventListener ('DOMContentLoaded', () => (noContentYet = false), false);
  1865. }
  1866. };
  1867. scripts['forums.overclockers.ru'] = {
  1868. now: function()
  1869. {
  1870. createStyle('.needblock {position: fixed; left: -10000px}');
  1871. Object.defineProperty(win, 'adblck', {
  1872. get: () => 'no',
  1873. set: () => null,
  1874. enumerable: true
  1875. });
  1876. }
  1877. };
  1878.  
  1879. scripts['pb.wtf'] = {
  1880. other: ['piratbit.org', 'piratbit.ru'],
  1881. dom: function()
  1882. {
  1883. createStyle('.reques,#result,tbody.row1:not([id]) {display: none !important}');
  1884. // image in the slider in the header
  1885. gardener('a[href^="/ex"],a[href$="=="]', /img/i, {root:'.release-navbar', observe:true, parent:'div'});
  1886. // ads in blocks on the page
  1887. gardener('a[href^="/topic/234257"]', /Как\sразместить/i, {siblings:-1, root:'#main_content', observe:true, parent:'span[style]'});
  1888. // line above topic content
  1889. gardener('.re_top1', /./, {root:'#main_content', parent:'.hidden-sm'});
  1890. }
  1891. };
  1892.  
  1893. scripts['pikabu.ru'] = () => gardener('.story', /story__sponsor|story__gag|profile\/ads"/i, {root: '.inner_wrap', observe: true});
  1894.  
  1895. scripts['qrz.ru'] = {
  1896. now: function()
  1897. {
  1898. Object.defineProperty(win, 'ab', {
  1899. get:()=>false,
  1900. set:()=>null
  1901. });
  1902. Object.defineProperty(win, 'tryMessage', {
  1903. get:()=>(()=>null),
  1904. set:()=>null
  1905. });
  1906. }
  1907. }
  1908.  
  1909. scripts['razlozhi.ru'] = {
  1910. now: function()
  1911. {
  1912. for (let func of ['createShadowRoot', 'attachShadow'])
  1913. if (func in Element.prototype)
  1914. Element.prototype[func] = function(){ return this.cloneNode(); };
  1915. }
  1916. };
  1917.  
  1918. scripts['rp5.ru'] = {
  1919. other: ['rp5.by', 'rp5.kz', 'rp5.ua'],
  1920. dom: function()
  1921. {
  1922. createStyle('#bannerBottom {display: none!important}');
  1923. let co = document.querySelector('#content');
  1924. if (!co)
  1925. return;
  1926. let nodes = co.parentNode.childNodes,
  1927. i = nodes.length;
  1928. while (i--)
  1929. if (nodes[i] !== co)
  1930. nodes[i].parentNode.removeChild(nodes[i]);
  1931. }
  1932. };
  1933.  
  1934. scripts['rustorka.com'] = {
  1935. other: ['rumedia.ws'],
  1936. now: function()
  1937. {
  1938. createStyle('.header > div:not(.head-block) a, #sidebar1 img, #logo img {opacity:0!important}', {
  1939. id: 'tempHidingStyles'
  1940. }, true);
  1941. preventPopups();
  1942. },
  1943. dom: function()
  1944. {
  1945. for (let o of document.querySelectorAll('IMG, A'))
  1946. if ((o.clientWidth === 728 && o.clientHeight === 90) ||
  1947. (o.clientWidth === 300 && o.clientHeight === 250))
  1948. {
  1949. while (o && o.tagName !== 'A')
  1950. o = o.parentNode;
  1951. if (o)
  1952. _setAttribute.call(o, 'style', 'display: none !important');
  1953. }
  1954. let s = document.querySelector('#tempHidingStyles');
  1955. s.parentNode.removeChild(s);
  1956. }
  1957. };
  1958.  
  1959. scripts['sport-express.ru'] = () => gardener('.js-relap__item',/>Реклама\s+<\//, {root:'.container', observe: true});
  1960.  
  1961. scripts['sports.ru'] = function()
  1962. {
  1963. gardener('.aside-news-list__item', /aside-news-list__advert/i, {root:'.columns-layout__left', observe: true});
  1964. gardener('.material-list__item', /Реклама/i, {root:'.columns-layout', observe: true});
  1965. // extra functionality: shows/hides panel at the top depending on scroll direction
  1966. createStyle([
  1967. '.user-panel__fixed { transition: top 0.2s ease-in-out!important; }',
  1968. '.user-panel-up { top: -40px!important }'
  1969. ], {id: 'userPanelSlide'}, false);
  1970. (function lookForPanel()
  1971. {
  1972. let panel = document.querySelector('.user-panel__fixed');
  1973. if (!panel)
  1974. setTimeout(lookForPanel, 100);
  1975. else
  1976. window.addEventListener(
  1977. 'wheel', function(e)
  1978. {
  1979. if (e.deltaY > 0 && !panel.classList.contains('user-panel-up'))
  1980. panel.classList.add('user-panel-up');
  1981. else if (e.deltaY < 0 && panel.classList.contains('user-panel-up'))
  1982. panel.classList.remove('user-panel-up');
  1983. }, false
  1984. );
  1985. })();
  1986. };
  1987.  
  1988. scripts['vk.com'] = () => gardener('div[data-post-id]', /wall_marked_as_ads/, {root: '#page_wall_posts', observe: true});
  1989.  
  1990. scripts['yap.ru'] = {
  1991. other: ['yaplakal.com'],
  1992. dom: function()
  1993. {
  1994. gardener('form > table[id^="p_row_"]:nth-of-type(2)', /member1438|Administration/);
  1995. gardener('.icon-comments', /member1438|Administration|\/go\/\?http/, {parent:'tr', siblings:-2});
  1996. }
  1997. };
  1998.  
  1999. scripts['rambler.ru'] = {
  2000. now: () => scriptLander(
  2001. function()
  2002. {
  2003. let _createElement = Document.prototype.createElement,
  2004. loadMap = new WeakMap();
  2005. Document.prototype.createElement = function createElement(name) {
  2006. /*jshint validthis:true */
  2007. let el = _createElement.apply(this, arguments);
  2008. if (el.tagName !== 'LINK')
  2009. return el;
  2010. Object.defineProperty(el, 'onload', {
  2011. get: function() {
  2012. return loadMap.get(loadMap.get(this));
  2013. },
  2014. set: function(func) {
  2015. let wrap = loadMap.get(this),
  2016. isContent = /\{\s*content\s*:\s*"[^"]+"/i;
  2017. if (wrap)
  2018. {
  2019. this.removeEventListener('load', wrap, false);
  2020. loadMap.remove(wrap);
  2021. loadMap.remove(this);
  2022. }
  2023. wrap = function(e)
  2024. {
  2025. if (e.target && e.target.sheet && e.target.sheet.cssRules &&
  2026. e.target.sheet.cssRules[0] && e.target.sheet.cssRules[0].cssText &&
  2027. isContent.test(e.target.sheet.cssRules[0].cssText))
  2028. {
  2029. console.log('Blocked "onload" for', e.target.href);
  2030. return false;
  2031. }
  2032. return func.apply(this, arguments);
  2033. };
  2034. loadMap.set(this, wrap);
  2035. loadMap.set(wrap, func);
  2036. this.addEventListener('load', wrap, false);
  2037. },
  2038. enumberable: true
  2039. });
  2040. return el;
  2041. };
  2042. }
  2043. )
  2044. };
  2045.  
  2046. scripts['reactor.cc'] = {
  2047. other: ['joyreactor.cc', 'pornreactor.cc'],
  2048. now: function()
  2049. {
  2050. win.open = (function(){ throw new Error('Redirect prevention.'); }).bind(window);
  2051. },
  2052. click: function(e)
  2053. {
  2054. let node = e.target;
  2055. if (node.nodeType === Node.ELEMENT_NODE &&
  2056. node.style.position === 'absolute' &&
  2057. node.style.zIndex > 0)
  2058. node.parentNode.removeChild(node);
  2059. },
  2060. dom: function()
  2061. {
  2062. let words = new RegExp(
  2063. 'блокировщика рекламы'
  2064. .split('')
  2065. .map(function(e){return e+'[\u200b\u200c\u200d]*';})
  2066. .join('')
  2067. .replace(' ', '\\s*')
  2068. .replace(/[аоре]/g, function(e){return ['[аa]','[оo]','[рp]','[еe]']['аоре'.indexOf(e)];}),
  2069. 'i'),
  2070. can;
  2071. function deeper(spider)
  2072. {
  2073. let c, l, n;
  2074. if (words.test(spider.innerText))
  2075. {
  2076. if (spider.nodeType === Node.TEXT_NODE)
  2077. return true;
  2078. c = spider.childNodes;
  2079. l = c.length;
  2080. n = 0;
  2081. while(l--)
  2082. if (deeper(c[l]), can)
  2083. n++;
  2084. if (n > 0 && n === c.length && spider.offsetHeight < 750)
  2085. can.push(spider);
  2086. return false;
  2087. }
  2088. return true;
  2089. }
  2090. function probe()
  2091. {
  2092. if (words.test(document.body.innerText))
  2093. {
  2094. can = [];
  2095. deeper(document.body);
  2096. let i = can.length, spider;
  2097. while(i--) {
  2098. spider = can[i];
  2099. if (spider.offsetHeight > 10 && spider.offsetHeight < 750)
  2100. _setAttribute.call(spider, 'style', 'background:none!important');
  2101. }
  2102. }
  2103. }
  2104. (new MutationObserver(probe))
  2105. .observe(document, { childList:true, subtree:true });
  2106. }
  2107. };
  2108.  
  2109. scripts['auto.ru'] = function()
  2110. {
  2111. let words = /Реклама|Яндекс.Директ|yandex_ad_/;
  2112. let userAdsListAds = (
  2113. '.listing-list > .listing-item,'+
  2114. '.listing-item_type_fixed.listing-item'
  2115. );
  2116. let catalogAds = (
  2117. 'div[class*="layout_catalog-inline"],'+
  2118. 'div[class$="layout_horizontal"]'
  2119. );
  2120. let otherAds = (
  2121. '.advt_auto,'+
  2122. '.sidebar-block,'+
  2123. '.pager-listing + div[class],'+
  2124. '.card > div[class][style],'+
  2125. '.sidebar > div[class],'+
  2126. '.main-page__section + div[class],'+
  2127. '.listing > tbody'
  2128. );
  2129. gardener(userAdsListAds, words, {root:'.listing-wrap', observe:true});
  2130. gardener(catalogAds, words, {root:'.catalog__page,.content__wrapper', observe:true});
  2131. gardener(otherAds, words);
  2132. };
  2133.  
  2134. scripts['rsload.net'] = {
  2135. load: function()
  2136. {
  2137. let dis = document.querySelector('label[class*="cb-disable"]');
  2138. if (dis)
  2139. dis.click();
  2140. },
  2141. click: function(e)
  2142. {
  2143. let t = e.target;
  2144. if (t && t.href && (/:\/\/\d+\.\d+\.\d+\.\d+\//.test(t.href)))
  2145. t.href = t.href.replace('://','://rsload.net:rsload.net@');
  2146. }
  2147. };
  2148.  
  2149. let domain, name;
  2150. // add alternate domain names if present
  2151. for (name in scripts) if (scripts[name].other)
  2152. for (domain of scripts[name].other) if (!(domain in scripts))
  2153. scripts[domain] = scripts[name];
  2154. // look for current domain in the list and run appropriate code
  2155. domain = document.domain;
  2156. while (domain.indexOf('.') > -1)
  2157. {
  2158. if (domain in scripts)
  2159. {
  2160. if (typeof scripts[domain] === 'function')
  2161. {
  2162. document.addEventListener ('DOMContentLoaded', scripts[domain], false);
  2163. break;
  2164. }
  2165. for (name in scripts[domain])
  2166. switch(name)
  2167. {
  2168. case 'other':
  2169. break;
  2170. case 'now':
  2171. scripts[domain][name]();
  2172. break;
  2173. case 'load':
  2174. window.addEventListener('load', scripts[domain][name], false);
  2175. break;
  2176. case 'dom':
  2177. document.addEventListener('DOMContentLoaded', scripts[domain][name], false);
  2178. break;
  2179. default:
  2180. document.addEventListener (name, scripts[domain][name], false);
  2181. }
  2182. }
  2183. domain = domain.slice(domain.indexOf('.') + 1);
  2184. }
  2185. })();

QingJ © 2025

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