RU AdList JS Fixes

try to take over the world!

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

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

QingJ © 2025

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