RU AdList JS Fixes

try to take over the world!

当前为 2017-09-05 提交的版本,查看 最新版本

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

QingJ © 2025

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