RU AdList JS Fixes

try to take over the world!

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

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

QingJ © 2025

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