RU AdList JS Fixes

try to take over the world!

当前为 2017-12-19 提交的版本,查看 最新版本

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

QingJ © 2025

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