RU AdList JS Fixes

try to take over the world!

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

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

QingJ © 2025

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