RU AdList JS Fixes

try to take over the world!

当前为 2017-07-01 提交的版本,查看 最新版本

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

QingJ © 2025

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