RU AdList JS Fixes

try to take over the world!

当前为 2018-03-29 提交的版本,查看 最新版本

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