RU AdList JS Fixes

try to take over the world!

目前為 2017-08-01 提交的版本,檢視 最新版本

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

QingJ © 2025

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