RU AdList JS Fixes

try to take over the world!

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

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

QingJ © 2025

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