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

QingJ © 2025

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