RU AdList JS Fixes

try to take over the world!

目前为 2018-04-01 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name RU AdList JS Fixes
  3. // @namespace ruadlist_js_fixes
  4. // @version 20180401.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 and setAttribute style to display:none
  992. let remove = (node) => {
  993. if (!node || !node.parentNode)
  994. return false;
  995. console.log('Removed node.');
  996. node.parentNode.removeChild(node);
  997. };
  998. let hide = (node) => {
  999. if (!node)
  1000. return false;
  1001. console.log('Hid node.');
  1002. _setAttribute.call(node, 'style', 'display:none!important');
  1003. };
  1004. // Yandex search ads in Google Chrome
  1005. if ('attachShadow' in Element.prototype)
  1006. {
  1007. let _attachShadow = Element.prototype.attachShadow;
  1008. Element.prototype.attachShadow = function()
  1009. {
  1010. let node = this,
  1011. root = _attachShadow.apply(node, arguments);
  1012. pageUpdateObserver(
  1013. (ms) => {
  1014. for (let m of ms) if (m.addedNodes.length)
  1015. if (adWords.test(root.textContent))
  1016. remove(node.closest('.serp-item'));
  1017. }, root
  1018. );
  1019. return root;
  1020. };
  1021. }
  1022. // prevent/defuse adblock detector
  1023. setInterval(()=>{
  1024. localStorage.ic = '';
  1025. localStorage._mt__data = '';
  1026. },100);
  1027. let _doc_proto = ('cookie' in _Document.prototype) ? _Document.prototype : Object.getPrototypeOf(document);
  1028. let _cookie = Object.getOwnPropertyDescriptor(_doc_proto, 'cookie');
  1029. if (_cookie)
  1030. {
  1031. let _set_cookie = Function.prototype.call.bind(_cookie.set);
  1032. _cookie.set = function(value)
  1033. {
  1034. if (/^(mda=|yp=|ys=|yabs-|__)/.test(value))
  1035. {
  1036. // remove value, set expired
  1037. if (!value.startsWith('yp=')) {
  1038. value = value.replace(/^([^=]+=)[^;]+/,'$1').replace(/(expires=)[\w\s\d,]+/,'$1Thu, 01 Jan 1970 00');
  1039. console.log('expire cookie', value.match(/^[^=]+/)[0]);
  1040. } else {
  1041. let parts = value.split(';');
  1042. let values = parts[0].split('#').filter(part => /\.sp\./.test(part));
  1043. if (values.length)
  1044. values[0] = values[0].replace(/^yp=/, '');
  1045. parts[0] = `yp=${values.join('#')}`;
  1046. value = parts.join(';');
  1047. console.log(`set cookie ${parts[0]}`);
  1048. }
  1049. //return null;
  1050. }
  1051. return _set_cookie(this, value);
  1052. };
  1053. Object.defineProperty(_doc_proto, 'cookie', _cookie);
  1054. }
  1055. // other ads
  1056. document.addEventListener(
  1057. 'DOMContentLoaded', function()
  1058. {
  1059. { // Generic ads removal and fixes
  1060. let node = _querySelector('.serp-header');
  1061. if (node)
  1062. node.style.marginTop = '0';
  1063. for (node of _querySelectorAll(
  1064. '.serp-adv__head + .serp-item,'+
  1065. '#adbanner,'+
  1066. '.serp-adv,'+
  1067. '.b-spec-adv,'+
  1068. 'div[class*="serp-adv__"]:not(.serp-adv__found):not(.serp-adv__displayed)'
  1069. )) remove(node);
  1070. }
  1071. // Search ads
  1072. function removeSearchAds()
  1073. {
  1074. for (let node of _querySelectorAll('.serp-item'))
  1075. if (_getAttribute.call(node, 'role') === 'complementary' ||
  1076. adWords.test((node.querySelector('.label')||{}).textContent))
  1077. hide(node);
  1078. }
  1079. // News ads
  1080. function removeNewsAds()
  1081. {
  1082. let node, block, item, items, mask, classes,
  1083. masks = [
  1084. { class: '.ads__wrapper', regex: /[^,]*?,[^,]*?\.ads__wrapper/ },
  1085. { class: '.ads__pool', regex: /[^,]*?,[^,]*?\.ads__pool/ }
  1086. ];
  1087. for (node of _querySelectorAll('style[nonce]'))
  1088. {
  1089. classes = node.innerText.replace(/\{[^}]+\}+/ig, '|').split('|');
  1090. for (block of classes) for (mask of masks)
  1091. if (block.includes(mask.class))
  1092. {
  1093. block = block.match(mask.regex)[0];
  1094. items = _querySelectorAll(block);
  1095. for (item of items)
  1096. remove(items[0]);
  1097. }
  1098. }
  1099. }
  1100. // Music ads
  1101. function removeMusicAds()
  1102. {
  1103. for (let node of _querySelectorAll('.ads-block'))
  1104. remove(node);
  1105. }
  1106. // Mail ads
  1107. function removeMailAds()
  1108. {
  1109. let slice = Array.prototype.slice,
  1110. nodes = slice.call(_querySelectorAll('.ns-view-folders')),
  1111. node, len, cls;
  1112.  
  1113. for (node of nodes)
  1114. if (!len || len > node.classList.length)
  1115. len = node.classList.length;
  1116.  
  1117. node = nodes.pop();
  1118. while (node)
  1119. {
  1120. if (node.classList.length > len)
  1121. for (cls of slice.call(node.classList))
  1122. if (cls.indexOf('-') === -1)
  1123. {
  1124. remove(node);
  1125. break;
  1126. }
  1127. node = nodes.pop();
  1128. }
  1129. }
  1130. // News fixes
  1131. function removePageAdsClass()
  1132. {
  1133. if (document.body.classList.contains("b-page_ads_yes"))
  1134. {
  1135. document.body.classList.remove("b-page_ads_yes");
  1136. console.log('Page ads class removed.');
  1137. }
  1138. }
  1139. // TV fixes
  1140. function removeTVAds()
  1141. {
  1142. for (let node of _querySelectorAll('div[class^="_"][data-reactid] > div'))
  1143. if (yadWord.test(node.textContent) || node.querySelector('iframe:not([src])'))
  1144. {
  1145. if (node.offsetWidth)
  1146. {
  1147. let pad = document.createElement('div');
  1148. _setAttribute.call(pad, 'style', `width:${node.offsetWidth}px`);
  1149. node.parentNode.appendChild(pad);
  1150. }
  1151. remove(node);
  1152. }
  1153. }
  1154.  
  1155. if (location.hostname.startsWith('mail.')) {
  1156. pageUpdateObserver(
  1157. function(ms, o)
  1158. {
  1159. let aside = _querySelector('.mail-Layout-Aside');
  1160. if (aside) {
  1161. o.disconnect();
  1162. pageUpdateObserver(removeMailAds, aside);
  1163. }
  1164. }, document.body
  1165. );
  1166. removeMailAds();
  1167. } else if (location.hostname.startsWith('music.')) {
  1168. pageUpdateObserver(removeMusicAds, _querySelector('.sidebar'));
  1169. removeMusicAds();
  1170. } else if (location.hostname.startsWith('news.')) {
  1171. pageUpdateObserver(removeNewsAds, document.body);
  1172. pageUpdateObserver(removePageAdsClass, document.body, { attributes:true, attributesFilter:['class'] });
  1173. removeNewsAds();
  1174. removePageAdsClass();
  1175. } else if (location.hostname.startsWith('tv.')) {
  1176. pageUpdateObserver(removeTVAds, document.body);
  1177. removeTVAds();
  1178. } else {
  1179. pageUpdateObserver(removeSearchAds, _querySelector('.main__content'));
  1180. removeSearchAds();
  1181. }
  1182. }
  1183. );
  1184. }
  1185.  
  1186. // Yandex Link Tracking
  1187. if (/^https?:\/\/([^.]+\.)*yandex\.[^\/]+/i.test(win.location.href))
  1188. {
  1189. // remove banner on the start page
  1190. scriptLander(() => {
  1191. let nt = new nullTools({log: false, trace: true});
  1192. let AwapsJsonAPI_Json_prototype = {};
  1193. let AwapsJsonAPI_Json = function(...args) {
  1194. console.log('>> new AwapsJsonAPI.Json(', ...args, ')');
  1195. };
  1196. [
  1197. 'setID', 'addImageContent',
  1198. 'sendCounts', 'expand', 'refreshAd'
  1199. ].forEach(name => AwapsJsonAPI_Json.prototype[name] = nt.proxy(nt.func(null, name)));
  1200. AwapsJsonAPI_Json.prototype.checkBannerVisibility = nt.proxy(nt.func(true, 'checkBannerVisibility'));
  1201. AwapsJsonAPI_Json.prototype.addIframeContent = nt.proxy(function(...args) {
  1202. try {
  1203. let frame = args[1][0].parentNode;
  1204. frame.parentNode.removeChild(frame);
  1205. console.log(`Removed banner placeholder.`);
  1206. } catch(ignore) {
  1207. console.log(`Can't locate frame object to remove.`);
  1208. }
  1209. });
  1210. AwapsJsonAPI_Json.prototype.getHTML = nt.proxy(nt.func('', 'getHTML'));
  1211. AwapsJsonAPI_Json.prototype = nt.proxy(AwapsJsonAPI_Json.prototype);
  1212. AwapsJsonAPI_Json = nt.proxy(AwapsJsonAPI_Json);
  1213. if ('AwapsJsonAPI' in win) {
  1214. console.log('Oops! AwapsJsonAPI already defined.');
  1215. let f = win.AwapsJsonAPI.Json;
  1216. win.AwapsJsonAPI.Json = AwapsJsonAPI_Json;
  1217. if (f && f.prototype)
  1218. f.prototype = AwapsJsonAPI_Json.prototype;
  1219. } else {
  1220. nt.define(win, 'AwapsJsonAPI', nt.proxy({
  1221. Json: AwapsJsonAPI_Json
  1222. }));
  1223. }
  1224.  
  1225. let home = win.home || {};
  1226. let parseExport = x => {
  1227. if (!x)
  1228. return x;
  1229. // remove banner placeholder
  1230. if (x.banner && x.banner.cls) {
  1231. let _parent = `.${x.banner.cls.banner__parent}`;
  1232. document.addEventListener('DOMContentLoaded', () => {
  1233. for (let banner of document.querySelectorAll(_parent)) {
  1234. _setAttribute.call(banner, 'style', 'display:none!important');
  1235. console.log('Hid banner placeholder.');
  1236. }
  1237. }, false);
  1238. }
  1239.  
  1240. // remove banner data and some other stuff
  1241. delete x.banner;
  1242. delete x.consistency;
  1243. delete x['i-bannerid'];
  1244. delete x['i-counter'];
  1245. delete x['ga-counter'];
  1246. delete x['promo-curtain'];
  1247.  
  1248. return x;
  1249. };
  1250. let home_export = parseExport(home.export);
  1251. Object.defineProperty(home, 'export', {
  1252. get: x => home_export,
  1253. set: x => {
  1254. home_export = parseExport(x);
  1255. }
  1256. });
  1257. nt.define(win, 'home', home);
  1258. }, nullTools, '_setAttribute = Element.prototype.setAttribute');
  1259.  
  1260. if ('attachShadow' in Element.prototype) {
  1261. let fakeRoot = () => ({
  1262. firstChild: null,
  1263. appendChild: ()=>null,
  1264. querySelector: ()=>null,
  1265. querySelectorAll: ()=>null
  1266. });
  1267. Element.prototype.createShadowRoot = fakeRoot;
  1268. let shadows = new WeakMap();
  1269. let _attachShadow = Object.getOwnPropertyDescriptor(Element.prototype, 'attachShadow');
  1270. let _call_attachShadow = _attachShadow.value;
  1271. _attachShadow.value = function() {
  1272. return shadows.set(this, fakeRoot()).get(this);
  1273. };
  1274. Object.defineProperty(Element.prototype, 'attachShadow', _attachShadow);
  1275. let _shadowRoot = Object.getOwnPropertyDescriptor(Element.prototype, 'shadowRoot');
  1276. _shadowRoot.set = () => null;
  1277. _shadowRoot.get = function() {
  1278. return shadows.has(this) ? shadows.get(this) : void 0;
  1279. };
  1280. Object.defineProperty(Element.prototype, 'shadowRoot', _shadowRoot);
  1281. }
  1282. // Partially based on https://greasyfork.org/en/scripts/22737-remove-yandex-redirect
  1283. let selectors = (
  1284. 'A[onmousedown*="/jsredir"],'+
  1285. 'A[data-vdir-href],'+
  1286. 'A[data-counter]'
  1287. );
  1288. let removeTrackingAttributes = function(link)
  1289. {
  1290. link.removeAttribute('onmousedown');
  1291. if (link.hasAttribute('data-vdir-href')) {
  1292. link.removeAttribute('data-vdir-href');
  1293. link.removeAttribute('data-orig-href');
  1294. }
  1295. if (link.hasAttribute('data-counter')) {
  1296. link.removeAttribute('data-counter');
  1297. link.removeAttribute('data-bem');
  1298. }
  1299. };
  1300. let removeTracking = function(scope)
  1301. {
  1302. for (let link of scope.querySelectorAll(selectors))
  1303. removeTrackingAttributes(link);
  1304. };
  1305. document.addEventListener('DOMContentLoaded', (e) => removeTracking(e.target));
  1306. (new MutationObserver(
  1307. function(ms)
  1308. {
  1309. let m, node;
  1310. for (m of ms) for (node of m.addedNodes) if (node.nodeType === _Node.ELEMENT_NODE)
  1311. if (node.tagName === 'A' && node.matches(selectors)) {
  1312. removeTrackingAttributes(node);
  1313. } else {
  1314. removeTracking(node);
  1315. }
  1316. }
  1317. )).observe(_de, { childList: true, subtree: true });
  1318. }
  1319.  
  1320. // https://greasyfork.org/en/scripts/21937-moonwalk-hdgo-kodik-fix v0.8 (adapted)
  1321. document.addEventListener(
  1322. 'DOMContentLoaded', function()
  1323. {//createPlayer();
  1324. function log (name) {
  1325. console.log(`Player FIX: Detected ${name} player in ${location.href}`);
  1326. }
  1327. if (win.adv_enabled !== undefined && win.condition_detected !== undefined)
  1328. {
  1329. log('Moonwalk');
  1330. if (win.adv_enabled)
  1331. win.adv_enabled = false;
  1332. win.condition_detected = false;
  1333. if (win.MXoverrollCallback)
  1334. document.addEventListener(
  1335. 'click', function catcher(e)
  1336. {
  1337. e.stopPropagation();
  1338. win.MXoverrollCallback.call(window);
  1339. document.removeEventListener('click', catcher, true);
  1340. }, true
  1341. );
  1342. }
  1343. else if (win.stat_url !== undefined && win.is_html5 !== undefined && win.is_wp8 !== undefined)
  1344. {
  1345. log('HDGo');
  1346. document.body.onclick = null;
  1347. let tmp = document.querySelector('#swtf');
  1348. if (tmp)
  1349. tmp.style.display = 'none';
  1350. if (win.banner_second !== undefined)
  1351. win.banner_second = 0;
  1352. if (win.$banner_ads !== undefined)
  1353. win.$banner_ads = false;
  1354. if (win.$new_ads !== undefined)
  1355. win.$new_ads = false;
  1356. if (win.createCookie !== undefined)
  1357. win.createCookie('popup', 'true', '999');
  1358. if (win.canRunAds !== undefined && win.canRunAds !== true)
  1359. win.canRunAds = true;
  1360. }
  1361. else if (win.MXoverrollCallback && win.iframeSearch !== undefined)
  1362. {
  1363. log('Kodik');
  1364. let tmp = document.querySelector('.play_button');
  1365. if (tmp)
  1366. tmp.onclick = win.MXoverrollCallback.bind(window);
  1367. win.IsAdBlock = false;
  1368. }
  1369. else if (win.getnextepisode && win.uppodEvent)
  1370. {
  1371. log('Share-Serials.net');
  1372. scriptLander(
  1373. function()
  1374. {
  1375. let _setInterval = win.setInterval,
  1376. _setTimeout = win.setTimeout;
  1377. win.setInterval = function(func)
  1378. {
  1379. if (func instanceof Function && func.toString().indexOf('_delay') > -1)
  1380. {
  1381. let intv = _setInterval.call(
  1382. this, function()
  1383. {
  1384. _setTimeout.call(
  1385. this, function(intv)
  1386. {
  1387. clearInterval(intv);
  1388. let timer = document.querySelector('#timer');
  1389. if (timer)
  1390. timer.click();
  1391. }, 100, intv);
  1392. func.call(this);
  1393. }, 5
  1394. );
  1395.  
  1396. return intv;
  1397. }
  1398. return _setInterval.apply(this, arguments);
  1399. };
  1400. win.setTimeout = function(func) {
  1401. if (func instanceof Function && func.toString().indexOf('adv_showed') > -1)
  1402. {
  1403. return _setTimeout.call(this, func, 0);
  1404. }
  1405. return _setTimeout.apply(this, arguments);
  1406. };
  1407. }
  1408. );
  1409. } else if ('ADC' in win)
  1410. {
  1411. log('vjs-creatives plugin in');
  1412. let replacer = (obj) => {
  1413. for (let name in obj)
  1414. if (obj[name] instanceof Function)
  1415. obj[name] = () => null;
  1416. };
  1417. replacer(win.ADC);
  1418. replacer(win.currentAdSlot);
  1419. }
  1420. UberVK: {
  1421. if (!inIFrame)
  1422. break UberVK;
  1423. let oddNames = 'HD' in win &&
  1424. !Object.getOwnPropertyNames(win).every(n => !n.startsWith('_0x'));
  1425. if (!oddNames)
  1426. break UberVK;
  1427. log('UberVK');
  1428. XMLHttpRequest.prototype.open = () => { throw 404; };
  1429. }
  1430. }, false
  1431. );
  1432.  
  1433. // piguiqproxy.com circumvention prevention
  1434. scriptLander(
  1435. () => {
  1436. let _open = XMLHttpRequest.prototype.open;
  1437. // blacklist of third-party domains requests to which are ignored
  1438. let blacklist = /[/.@](amgload\.net|dsn-fishki\.ru|kingoablc\.com|piguiqproxy\.com|rcdn\.pro)[:/]/i;
  1439. // blacklist of domains where all third-party requests are ignored
  1440. let ondomains = /(^|[/.@])oane\.ws($|[:/])/i;
  1441. // highly suspicious URLs
  1442. let suspicious = /^https?:\/\/(csp-)?[a-z0-9]{6}\.ru\//i;
  1443. let on_get_ban = /^https?:\/\/(csp-)?[a-z0-9]{6}\.ru\/([a-z0-9\/]{45,}|[a-z0-9]{8,}|ad\/banner\/.+)$/i;
  1444. let on_post_ban = /^https?:\/\/(csp-)?[a-z0-9]{6}\.ru\/([a-z0-9]{6,})$/i;
  1445.  
  1446. XMLHttpRequest.prototype.open = function(method, url)
  1447. {
  1448. if (method === 'GET' &&
  1449. (blacklist.test(url) || on_get_ban.test(url) ||
  1450. ondomains.test(location.hostname) && !ondomains.test(url)) ||
  1451. method === 'POST' && on_post_ban.test(url))
  1452. {
  1453. this.send = () => null;
  1454. this.setRequestHeader = () => null;
  1455. console.log('Blocked request: ', url);
  1456. return;
  1457. }
  1458. if (suspicious.test(url))
  1459. console.warn('Suspicious request: ', url);
  1460. return _open.apply(this, arguments);
  1461. };
  1462. }
  1463. );
  1464.  
  1465. // === Helper functions ===
  1466.  
  1467. // function to search and remove nodes by content
  1468. // selector - standard CSS selector to define set of nodes to check
  1469. // words - regular expression to check content of the suspicious nodes
  1470. // params - object with multiple extra parameters:
  1471. // .log - display log in the console
  1472. // .hide - set display to none instead of removing from the page
  1473. // .parent - parent node to remove if content is found in the child node
  1474. // .siblings - number of simling nodes to remove (excluding text nodes)
  1475. let scRemove = (node) => node.parentNode.removeChild(node);
  1476. let scHide = function(node)
  1477. {
  1478. let style = _getAttribute.call(node, 'style') || '',
  1479. hide = ';display:none!important;';
  1480. if (style.indexOf(hide) < 0)
  1481. _setAttribute.call(node, 'style', style + hide);
  1482. };
  1483.  
  1484. function scissors (selector, words, scope, params)
  1485. {
  1486. let logger = function() { return params.log ? console.log(...arguments) : null; };
  1487. if (!scope.contains(document.body))
  1488. logger('[s] scope', scope);
  1489. let remFunc = (params.hide ? scHide : scRemove),
  1490. iterFunc = (params.siblings > 0 ? 'nextElementSibling' : 'previousElementSibling'),
  1491. toRemove = [],
  1492. siblings;
  1493. for (let node of scope.querySelectorAll(selector))
  1494. {
  1495. // drill up to a parent node if specified, break if not found
  1496. if (params.parent)
  1497. {
  1498. let old = node;
  1499. node = node.closest(params.parent);
  1500. if (node === null || node.contains(scope))
  1501. {
  1502. logger('[s] went out of scope with', old);
  1503. continue;
  1504. }
  1505. }
  1506. logger('[s] processing', node);
  1507. if (toRemove.includes(node))
  1508. continue;
  1509. if (words.test(node.innerHTML))
  1510. {
  1511. // skip node if already marked for removal
  1512. logger('[s] marked for removal');
  1513. toRemove.push(node);
  1514. // add multiple nodes if defined more than one sibling
  1515. siblings = Math.abs(params.siblings) || 0;
  1516. while (siblings)
  1517. {
  1518. node = node[iterFunc];
  1519. if (!node) break; // can't go any further - exit
  1520. logger('[s] adding sibling node', node);
  1521. toRemove.push(node);
  1522. siblings -= 1;
  1523. }
  1524. }
  1525. }
  1526. let toSkip = [];
  1527. for (let node of toRemove)
  1528. if (!toRemove.every(other => other === node || !node.contains(other)))
  1529. toSkip.push(node);
  1530. if (toRemove.length)
  1531. logger(`[s] proceeding with ${params.hide?'hide':'removal'} of`, toRemove, `skip`, toSkip);
  1532. for (let node of toRemove) if (!toSkip.includes(node))
  1533. remFunc(node);
  1534. }
  1535.  
  1536. // function to perform multiple checks if ads inserted with a delay
  1537. // by default does 30 checks withing a 3 seconds unless nonstop mode specified
  1538. // also does 1 extra check when a page completely loads
  1539. // selector and words - passed dow to scissors
  1540. // params - object with multiple extra parameters:
  1541. // .log - display log in the console
  1542. // .root - selector to narrow down scope to scan;
  1543. // .observe - if true then check will be performed continuously;
  1544. // Other parameters passed down to scissors.
  1545. function gardener(selector, words, params)
  1546. {
  1547. let logger = function() { return params.log ? console.log(...arguments) : null; };
  1548. params = params || {};
  1549. logger(`[gardener] selector: '${selector}' detector: ${words} options: ${JSON.stringify(params)}`);
  1550. let scope;
  1551. let globalScope = [_de];
  1552. let domLoaded = false;
  1553. let getScope = root => root ? _de.querySelectorAll(root) : globalScope;
  1554. let onevent = e => {
  1555. logger(`[gardener] cleanup on ${Object.getPrototypeOf(e)} "${e.type}"`);
  1556. for (let node of scope)
  1557. scissors(selector, words, node, params);
  1558. };
  1559. let repeater = n => {
  1560. if (!domLoaded && n) {
  1561. setTimeout(repeater, 500, n - 1);
  1562. scope = getScope(params.root);
  1563. if (!scope) // exit if the root element is not present on the page
  1564. return 0;
  1565. onevent({type: 'Repeater'});
  1566. }
  1567. };
  1568. repeater(20);
  1569. document.addEventListener(
  1570. 'DOMContentLoaded', (e) => {
  1571. domLoaded = true;
  1572. // narrow down scope to a specific element
  1573. scope = getScope(params.root);
  1574. if (!scope) // exit if the root element is not present on the page
  1575. return 0;
  1576. logger('[g] scope', scope);
  1577. // add observe mode if required
  1578. if (params.observe)
  1579. {
  1580. let params = { childList:true, subtree: true };
  1581. let observer = new MutationObserver(
  1582. function(ms)
  1583. {
  1584. for (let m of ms)
  1585. if (m.addedNodes.length)
  1586. onevent(m);
  1587. }
  1588. );
  1589. for (let node of scope)
  1590. observer.observe(node, params);
  1591. logger('[g] observer enabled');
  1592. }
  1593. onevent(e);
  1594. }, false);
  1595. // wait for a full page load to do one extra cut
  1596. win.addEventListener('load', onevent, false);
  1597. }
  1598.  
  1599. // wrap popular methods to open a new tab to catch specific behaviours
  1600. function createWindowOpenWrapper(openFunc, onClickFunc)
  1601. {
  1602. let _createElement = _Document.prototype.createElement,
  1603. _appendChild = Element.prototype.appendChild,
  1604. fakeNative = (f) => (f.toString = () => `function ${f.name}() { [native code] }`);
  1605.  
  1606. let nt = new nullTools();
  1607. fakeNative(openFunc);
  1608.  
  1609. let parser = _createElement.call(document, 'a');
  1610. let openWhitelist = (url, parent) => {
  1611. parser.href = url;
  1612. return parser.hostname === 'www.imdb.com' || parser.hostname === 'www.kinopoisk.ru' ||
  1613. parent.hostname === 'radikal.ru' && url === void 0;
  1614. };
  1615.  
  1616. let redefineOpen = (root) => {
  1617. if ('open' in root) {
  1618. let _open = root.open.bind(root);
  1619. nt.define(root, 'open', (...args) => {
  1620. if (openWhitelist(args[0], location)) {
  1621. console.log('Whitelisted popup:', ...args);
  1622. return _open(...args);
  1623. }
  1624. return openFunc(...args);
  1625. });
  1626. }
  1627. };
  1628. redefineOpen(win);
  1629.  
  1630. function createElement(name) {
  1631. '[native code]';
  1632. // jshint validthis:true
  1633. let el = _createElement.apply(this, arguments);
  1634. // redefine window.open in first-party frames
  1635. if (el instanceof HTMLIFrameElement || el instanceof HTMLObjectElement)
  1636. el.addEventListener('load', (e) => {
  1637. try {
  1638. redefineOpen(e.target.contentWindow);
  1639. } catch(ignore) {}
  1640. }, false);
  1641. return el;
  1642. }
  1643. fakeNative(createElement);
  1644.  
  1645. let redefineCreateElement = (obj) => {
  1646. for (let root of [obj.document, _Document.prototype]) if ('createElement' in root)
  1647. nt.define(root, 'createElement', createElement);
  1648. };
  1649. redefineCreateElement(win);
  1650.  
  1651. // wrap window.open in newly added first-party frames
  1652. Element.prototype.appendChild = function appendChild()
  1653. {
  1654. '[native code]';
  1655. let el = _appendChild.apply(this, arguments);
  1656. if (el instanceof HTMLIFrameElement) {
  1657. try {
  1658. redefineOpen(el.contentWindow);
  1659. redefineCreateElement(el.contentWindow);
  1660. } catch(ignore) {}
  1661. }
  1662. return el;
  1663. };
  1664. fakeNative(Element.prototype.appendChild);
  1665. }
  1666.  
  1667. // Function to catch and block various methods to open a new window with 3rd-party content.
  1668. // Some advertisement networks went way past simple window.open call to circumvent default popup protection.
  1669. // This funciton blocks window.open, ability to restore original window.open from an IFRAME object,
  1670. // ability to perform an untrusted (not initiated by user) click on a link, click on a link without a parent
  1671. // node or simply a link with piece of javascript code in the HREF attribute.
  1672. function preventPopups()
  1673. {
  1674. // call sandbox-me if in iframe and not whitelisted
  1675. if (inIFrame) {
  1676. win.top.postMessage({ name: 'sandbox-me', href: win.location.href }, '*');
  1677. return;
  1678. }
  1679.  
  1680. scriptLander(() => {
  1681. let open = (...args) => {
  1682. '[native code]';
  1683. console.warn('Site attempted to open a new window', args);
  1684. if (new RegExp(`^https?://${location.hostname}/`).test(args[0])) // skip extra click in case of blocked popunder
  1685. location.assign(args[0]);
  1686. return {
  1687. document: {
  1688. write: () => {},
  1689. writeln: () => {}
  1690. },
  1691. location: {}
  1692. };
  1693. };
  1694.  
  1695. let clickHandler = (e) => {
  1696. let link = e.target;
  1697. if (!link.parentNode || !e.isTrusted ||
  1698. (link.href && link.href.trim().toLowerCase().indexOf('javascript') === 0))
  1699. {
  1700. e.preventDefault();
  1701. console.warn('Blocked suspicious click event', e, 'on', e.target);
  1702. }
  1703. };
  1704.  
  1705. createWindowOpenWrapper(open, clickHandler);
  1706.  
  1707. console.log('Popup prevention enabled.');
  1708. }, nullTools, createWindowOpenWrapper);
  1709. }
  1710.  
  1711. // Helper function to close background tab if site opens itself in a new tab and then
  1712. // loads a 3rd-party page in the background one (thus performing background redirect).
  1713. function preventPopunders()
  1714. {
  1715. // create "close_me" event to call high-level window.close()
  1716. let eventName = `close_me_${Math.random().toString(36).substr(2)}`;
  1717. let callClose = () => (console.log('close call'), window.close());
  1718. window.addEventListener(eventName, callClose, true);
  1719.  
  1720. scriptLander(() => {
  1721. // get host of a provided URL with help of an anchor object
  1722. // unfortunately new URL(url, window.location) generates wrong URL in some cases
  1723. let parseURL = document.createElement('A');
  1724. let getHost = (url) => (parseURL.href = url, parseURL.hostname);
  1725. // site went to a new tab and attempts to unload
  1726. // call for high-level close through event
  1727. let closeWindow = () => window.dispatchEvent(new CustomEvent(eventName, {}));
  1728. // check is URL local or goes to different site
  1729. let isLocal = (url) => {
  1730. if (url === location.pathname || url === location.href)
  1731. return true; // URL points to current pathname or full address
  1732. let host = getHost(url);
  1733. let site = location.hostname;
  1734. return host !== '' && // URLs with unusual protocol may have empty 'host'
  1735. (site === host || site.endsWith(`.${host}`) || host.endsWith(`.${site}`));
  1736. };
  1737.  
  1738. let _open = window.open.bind(window);
  1739. let open = (...args) => {
  1740. '[native code]';
  1741. let url = args[0];
  1742. if (url && isLocal(url))
  1743. window.addEventListener('beforeunload', closeWindow, true);
  1744. // jshint validthis:true
  1745. return _open(...args);
  1746. };
  1747.  
  1748. let clickHandler = (e) => {
  1749. if (!e.target.parentNode || !e.isTrusted)
  1750. window.addEventListener('beforeunload', closeWindow, true);
  1751. };
  1752.  
  1753. createWindowOpenWrapper(open, clickHandler);
  1754.  
  1755. console.log("Background redirect prevention enabled.");
  1756. }, `let eventName="${eventName}"`, nullTools, createWindowOpenWrapper);
  1757. }
  1758.  
  1759. // Mix between check for popups and popunders
  1760. // Significantly more agressive than both and can't be used as universal solution
  1761. function preventPopMix()
  1762. {
  1763. if (inIFrame)
  1764. {
  1765. win.top.postMessage({ name: 'sandbox-me', href: win.location.href }, '*');
  1766. return;
  1767. }
  1768.  
  1769. // create "close_me" event to call high-level window.close()
  1770. let eventName = `close_me_${Math.random().toString(36).substr(2)}`;
  1771. let callClose = () => (console.log('close call'), window.close());
  1772. window.addEventListener(eventName, callClose, true);
  1773.  
  1774. scriptLander(() => {
  1775. let _open = window.open,
  1776. parseURL = document.createElement('A');
  1777. // get host of a provided URL with help of an anchor object
  1778. // unfortunately new URL(url, window.location) generates wrong URL in some cases
  1779. let getHost = (url) => (parseURL.href = url, parseURL.host);
  1780. // site went to a new tab and attempts to unload
  1781. // call for high-level close through event
  1782. let closeWindow = () => (_open(window.location,'_self'), window.dispatchEvent(new CustomEvent(eventName, {})));
  1783. // check is URL local or goes to different site
  1784. function isLocal(url)
  1785. {
  1786. let loc = window.location;
  1787. if (url === loc.pathname || url === loc.href)
  1788. return true; // URL points to current pathname or full address
  1789. let host = getHost(url),
  1790. site = loc.host;
  1791. if (host === '')
  1792. return false; // URLs with unusual protocol may have empty 'host'
  1793. if (host.length > site.length)
  1794. [site, host] = [host, site];
  1795. return site.includes(host, site.length - host.length);
  1796. }
  1797.  
  1798. // add check for redirect for 5 seconds, then disable it
  1799. function checkRedirect()
  1800. {
  1801. window.addEventListener('beforeunload', closeWindow, true);
  1802. setTimeout(closeWindow=>window.removeEventListener('beforeunload', closeWindow, true), 5000, closeWindow);
  1803. }
  1804.  
  1805. function open(url, name)
  1806. {
  1807. '[native code]';
  1808. if (url && isLocal(url) && (!name || name === '_blank'))
  1809. {
  1810. console.warn('Suspicious local new window', arguments);
  1811. checkRedirect();
  1812. // jshint validthis:true
  1813. return _open.apply(this, arguments);
  1814. }
  1815. console.warn('Blocked attempt to open a new window', arguments);
  1816. return {
  1817. document: {
  1818. write: () => {},
  1819. writeln: () => {}
  1820. }
  1821. };
  1822. }
  1823.  
  1824. function clickHandler(e)
  1825. {
  1826. let link = e.target,
  1827. url = link.href||'';
  1828. if (e.targetParentNode && e.isTrusted || link.target !== '_blank')
  1829. {
  1830. console.log('Link', link, 'were created dinamically, but looks fine.');
  1831. return true;
  1832. }
  1833. if (isLocal(url) && link.target === '_blank')
  1834. {
  1835. console.log('Suspicious local link', link);
  1836. checkRedirect();
  1837. return;
  1838. }
  1839. console.log('Blocked suspicious click on a link', link);
  1840. e.stopPropagation();
  1841. e.preventDefault();
  1842. }
  1843.  
  1844. createWindowOpenWrapper(open, clickHandler);
  1845.  
  1846. console.log("Mixed popups prevention enabled.");
  1847. }, `let eventName="${eventName}"`, createWindowOpenWrapper);
  1848. }
  1849. // External listener for case when site known to open popups were loaded in iframe
  1850. // It will sandbox any iframe which will send message 'forbid.popups' (preventPopups sends it)
  1851. // Some sites replace frame's window.location with data-url to run in clean context
  1852. if (!inIFrame)
  1853. {
  1854. window.addEventListener(
  1855. 'message', function(e)
  1856. {
  1857. if (!e.data || e.data.name !== 'sandbox-me' || !e.data.href)
  1858. return;
  1859. let src = e.data.href;
  1860. for (let frame of document.querySelectorAll('iframe'))
  1861. if (frame.contentWindow === e.source)
  1862. {
  1863. if (frame.hasAttribute('sandbox'))
  1864. {
  1865. if (!frame.sandbox.contains('allow-popups'))
  1866. return; // exit frame since it's already sandboxed and popups are blocked
  1867. // remove allow-popups if frame already sandboxed
  1868. frame.sandbox.remove('allow-popups');
  1869. } else {
  1870. // set sandbox mode for troublesome frame and allow scripts, forms and a few other actions
  1871. // technically allowing both scripts and same-origin allows removal of the sandbox attribute,
  1872. // but to apply content must be reloaded and this script will re-apply it in the result
  1873. frame.setAttribute('sandbox','allow-forms allow-scripts allow-presentation allow-top-navigation allow-same-origin');
  1874. }
  1875. console.log('Disallowed popups from iframe', frame);
  1876.  
  1877. // reload frame content to apply restrictions
  1878. if (!src) {
  1879. src = frame.src;
  1880. console.log('Unable to get current iframe location, reloading from src', src);
  1881. } else
  1882. console.log('Reloading iframe with URL', src);
  1883. frame.src = 'about:blank';
  1884. frame.src = src;
  1885. }
  1886. }, false
  1887. );
  1888. }
  1889.  
  1890. function selectiveEval() {
  1891. scriptLander(() => {
  1892. let nt = new nullTools();
  1893. let _eval = win.eval.bind(window);
  1894. nt.define(win, 'eval', function(...args) {
  1895. if (/_0x|location\s*?=|location.href\s*?=|location.assign\(|open\(/i.test(args[0])) {
  1896. console.log(`Skipped eval of ${args[0].slice(0, 512)}\u2026`);
  1897. return null;
  1898. }
  1899. return _eval(...args);
  1900. });
  1901. }, nullTools);
  1902. }
  1903.  
  1904. // === Scripts for specific domains ===
  1905.  
  1906. let scripts = {};
  1907. // prevent popups and redirects block
  1908. // Popups
  1909. scripts.preventPopups = {
  1910. other: [
  1911. 'biqle.ru',
  1912. 'chaturbate.com',
  1913. 'dfiles.ru',
  1914. 'eporner.eu',
  1915. 'hentaiz.org',
  1916. 'mirrorcreator.com',
  1917. 'online-multy.ru',
  1918. 'radikal.ru', 'rumedia.ws',
  1919. 'thepiratebay.org',
  1920. 'unionpeer.com',
  1921. 'zippyshare.com'
  1922. ],
  1923. now: preventPopups
  1924. };
  1925. // Popunders (background redirect)
  1926. scripts.preventPopunders = {
  1927. other: [
  1928. 'lostfilm-online.ru',
  1929. 'mediafire.com', 'megapeer.org', 'megapeer.ru',
  1930. 'perfectgirls.net'
  1931. ],
  1932. now: preventPopunders
  1933. };
  1934. // PopMix (both types of popups encountered on site)
  1935. scripts['openload.co'] = {
  1936. other: ['oload.tv', 'oload.info'],
  1937. now: () => {
  1938. let nt = new nullTools();
  1939. nt.define(win, 'CNight', win.CoinHive);
  1940. if (location.pathname.startsWith('/embed/'))
  1941. {
  1942. nt.define(win, 'BetterJsPop', {
  1943. add: ((a, b) => console.warn('BetterJsPop.add', a, b)),
  1944. config: ((o) => console.warn('BetterJsPop.config', o)),
  1945. Browser: { isChrome: true }
  1946. });
  1947. nt.define(win, 'isSandboxed', nt.func(null));
  1948. nt.define(win, 'adblock', false);
  1949. nt.define(win, 'adblock2', false);
  1950. } else
  1951. preventPopMix();
  1952. }
  1953. };
  1954. scripts['turbobit.net'] = preventPopMix;
  1955.  
  1956. // workaround for moradu.com/apu.php load error handler script, not sure which ad network is this
  1957. scripts['tapochek.net'] = () => {
  1958. let _appendChild = Object.getOwnPropertyDescriptor(_Node.prototype, 'appendChild');
  1959. let _appendChild_value = _appendChild.value;
  1960. _appendChild.value = function appendChild(node) {
  1961. if (this === win.document.body)
  1962. if ((node instanceof HTMLScriptElement || node instanceof HTMLStyleElement) &&
  1963. /^https?:\/\/[0-9a-f]{15}\.com\/\d+(\/|\.css)$/.test(node.src) ||
  1964. node instanceof HTMLDivElement && node.style.zIndex > 900000 &&
  1965. node.style.backgroundImage.includes('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'))
  1966. throw '...eenope!';
  1967. return _appendChild_value.apply(this, arguments);
  1968. };
  1969. Object.defineProperty(_Node.prototype, 'appendChild', _appendChild);
  1970.  
  1971. preventPopups();
  1972. };
  1973.  
  1974. scripts['rustorka.com'] = {
  1975. other: ['rustorka.lib'],
  1976. now: () => scriptLander(() => {
  1977. let crumbler = e => { // crumble suspicious cookies
  1978. let base = '=; expires=Thu, 01 Jan 1970 00:00:01 UTC; Max-Age=-99999999; path=/';
  1979. console.log('cookies', document.cookie);
  1980. for (let name of ['adblock', 'gophp', '_692293176245', '_692293176246'])
  1981. document.cookie = `${name}${base}`;
  1982. for (let name of ['st2', 'st3']) {
  1983. document.cookie = `${name}${base}forum`;
  1984. document.cookie = `${name}${base}forum/`;
  1985. }
  1986. console.log('cookies', document.cookie);
  1987. };
  1988. document.addEventListener('DOMContentLoaded', crumbler, false);
  1989. crumbler();
  1990.  
  1991. let nt = new nullTools({trace: true});
  1992. nt.define(win, 'syka', false);
  1993. nt.define(win, '_692293176244', location.href);
  1994. [
  1995. 'MTLuxup', 'MTAdSniper', 'MTutarg', 'MTUAatar', 'MTcityAds', 'MTmxMark',
  1996. 'MTmxMark2', 'MTmdnt', 'MTrfDumedia', 'MXsmTDS', 'MTritorno', 'MTadvice',
  1997. 'cyka', 'MTAdTraff', 'MTExebid', 'MXsockFound'
  1998. ].forEach(p => nt.define(win, p, nt.func(null, p)));
  1999. let _eval_def = Object.getOwnPropertyDescriptor(win, 'eval');
  2000. if (!_eval_def)
  2001. return;
  2002. let _eval_val = _eval_def.value;
  2003. _eval_def.value = (...args) => {
  2004. if (args[0] && args[0].includes('antiadblock'))
  2005. return console.log('Anti-AdBlock script may run another day, but not today.');
  2006. return _eval_val.apply(this, args);
  2007. };
  2008. Object.defineProperty(win, 'eval', _eval_def);
  2009. win.open = (...args) => {
  2010. console.warn(`Site attempted to open "${args[0]}" in a new window.`);
  2011. location.replace(location.href);
  2012. return null;
  2013. };
  2014. window.addEventListener('DOMContentLoaded', () => {
  2015. let link = void 0;
  2016. document.body.addEventListener('mousedown', e => {
  2017. link = e.target.closest('a, select, #fancybox-title-wrap');
  2018. }, false);
  2019. let _open = window.open.bind(window);
  2020. let _getAttribute = Element.prototype.getAttribute;
  2021. win.open = (...args) => {
  2022. let url = args[0];
  2023. let allow = false;
  2024. if (link instanceof HTMLAnchorElement) {
  2025. // third-party post links
  2026. let href = _getAttribute.call(link, 'href');
  2027. if (link.classList.contains('postLink') &&
  2028. !link.matches(`a[href*="${location.hostname}"]`) &&
  2029. (href === url || link.href === url)) {
  2030. return _open(...args);
  2031. }
  2032. // onclick # links
  2033. if (href === '#' && /window\.open/.test(_getAttribute.call(link, 'onclick'))) {
  2034. return _open(...args);
  2035. }
  2036. // force local links to load in the current window
  2037. if (href[0] === '/' || href.startsWith('./') || href.includes(`//${location.hostname}/`))
  2038. location.assign(href);
  2039. }
  2040. // list of image hostings under upload picture button (new comment)
  2041. if (link instanceof HTMLSelectElement &&
  2042. !url.includes(location.hostname) &&
  2043. link.value === url) {
  2044. return _open(...args);
  2045. }
  2046. // open screenshot in a new window
  2047. if (link instanceof HTMLSpanElement &&
  2048. link.id === 'fancybox-title-wrap') {
  2049. return _open(...args);
  2050. }
  2051. // looks like tabunder
  2052. if (link === null && url === location.href)
  2053. location.replace(url); // reload current page
  2054. // other cases
  2055. console.warn(`Site attempted to open "${url}" in a new window. Source: `, link);
  2056. return {};
  2057. };
  2058. }, true);
  2059. }, nullTools)
  2060. };
  2061.  
  2062. // other
  2063. scripts['1tv.ru'] = () => scriptLander(() => {
  2064. let nt = new nullTools();
  2065. nt.define(win, 'EUMPAntiblockConfig', nt.proxy({url: '//www.1tv.ru/favicon.ico'}));
  2066. let disablePlugins = {
  2067. 'antiblock': false,
  2068. 'stat1tv': false
  2069. };
  2070. let _EUMPConfig = void 0;
  2071. let _EUMPConfig_set = x => {
  2072. if (x.plugins) {
  2073. x.plugins = x.plugins.filter(plugin => (plugin in disablePlugins) ? !(disablePlugins[plugin] = true) : true);
  2074. console.warn(`Player plugins: active [${x.plugins}], disabled [${Object.keys(disablePlugins).filter(x => disablePlugins[x])}]`);
  2075. }
  2076. _EUMPConfig = x;
  2077. };
  2078. if ('EUMPConfig' in win)
  2079. _EUMPConfig_set(win.EUMPConfig);
  2080. Object.defineProperty(win, 'EUMPConfig', {
  2081. enumerable: true,
  2082. get: x => _EUMPConfig,
  2083. set: _EUMPConfig_set
  2084. });
  2085. }, nullTools);
  2086.  
  2087. scripts['2picsun.ru'] = {
  2088. other: [
  2089. 'pics2sun.ru', '3pics-img.ru'
  2090. ],
  2091. now: () => {
  2092. Object.defineProperty(navigator, 'userAgent', {value: 'googlebot'});
  2093. }
  2094. };
  2095.  
  2096. scripts['4pda.ru'] = {
  2097. now: () => {
  2098. // https://greasyfork.org/en/scripts/14470-4pda-unbrender
  2099. let hStyle,
  2100. isForum = document.location.href.search('/forum/') !== -1,
  2101. remove = (node) => (node ? node.parentNode.removeChild(node) : null),
  2102. afterClean = () => remove(hStyle);
  2103.  
  2104. function beforeClean()
  2105. {
  2106. // attach styles before document displayed
  2107. hStyle = createStyle([
  2108. 'html { overflow-y: scroll }',
  2109. 'article + aside * { display: none !important }',
  2110. `section[id] {${(
  2111. 'position: absolute;'+
  2112. 'width: 100%'
  2113. )}}`,
  2114. `#header + div:after {${(
  2115. 'content: "";'+
  2116. 'position: fixed;'+
  2117. 'top: 0;'+
  2118. 'left: 0;'+
  2119. 'width: 100%;'+
  2120. 'height: 100%;'+
  2121. 'background-color: #E6E7E9'
  2122. )}}`,
  2123. // http://codepen.io/Beaugust/pen/DByiE
  2124. '@keyframes spin { 100% { transform: rotate(360deg) } }',
  2125. `article + aside:after {${(
  2126. 'content: "";'+
  2127. 'position: absolute;'+
  2128. 'width: 150px;'+
  2129. 'height: 150px;'+
  2130. 'top: 150px;'+
  2131. 'left: 50%;'+
  2132. 'margin-top: -75px;'+
  2133. 'margin-left: -75px;'+
  2134. 'box-sizing: border-box;'+
  2135. 'border-radius: 100%;'+
  2136. 'border: 10px solid rgba(0, 0, 0, 0.2);'+
  2137. 'border-top-color: rgba(0, 0, 0, 0.6);'+
  2138. 'animation: spin 2s infinite linear'
  2139. )}}`
  2140. ], {id:'ubrHider'}, true);
  2141.  
  2142. // display content of a page if time to load a page is more than 2 seconds to avoid
  2143. // blocking access to a page if it is loading for too long or stuck in a loading state
  2144. setTimeout(2000, afterClean);
  2145. }
  2146.  
  2147. createStyle([
  2148. '#nav .use-ad { display: block !important }',
  2149. 'article:not(.post) + article:not(#id),'+
  2150. 'html:not(#id)>body:not(#id) a[target="_blank"] img[height="90"] { display: none !important }'
  2151. ]);
  2152.  
  2153. if (!isForum)
  2154. beforeClean();
  2155.  
  2156. // save links to non-overridden functions to use later
  2157. let protectedElems;
  2158. // protect/hide changed attributes in case site attempt to restore them
  2159. function styleProtector(eventMode)
  2160. {
  2161. let _toLowerCase = String.prototype.toLowerCase,
  2162. isStyleText = (t) => (_toLowerCase.call(t) === 'style'),
  2163. protectedElems = new WeakMap();
  2164. function protoOverride(element, functionName, isStyleCheck, returnIfProtected)
  2165. {
  2166. let originalFunction = element.prototype[functionName];
  2167. element.prototype[functionName] = function wrapper()
  2168. {
  2169. if (protectedElems.has(this) && isStyleCheck(arguments[0]))
  2170. return returnIfProtected(this, arguments);
  2171. return originalFunction.apply(this, arguments);
  2172. };
  2173. }
  2174. protoOverride(Element, 'removeAttribute', isStyleText, () => undefined);
  2175. protoOverride(Element, 'hasAttribute', isStyleText, (_this) => protectedElems.get(_this) !== null);
  2176. protoOverride(Element, 'setAttribute', isStyleText, (_this, args) => protectedElems.set(_this, args[1]));
  2177. protoOverride(Element, 'getAttribute', isStyleText, (_this) => protectedElems.get(_this));
  2178. if (!eventMode)
  2179. return protectedElems;
  2180. else
  2181. {
  2182. let e = document.createEvent('Event');
  2183. e.initEvent('protoOverride', false, false);
  2184. window.protectedElems = protectedElems;
  2185. window.dispatchEvent(e);
  2186. }
  2187. }
  2188. if (!isFirefox)
  2189. protectedElems = styleProtector(false);
  2190. else
  2191. {
  2192. let script = document.createElement('script');
  2193. script.textContent = `(${styleProtector.toString()})(true);`;
  2194. window.addEventListener(
  2195. 'protoOverride', function protoOverrideCallback(e)
  2196. {
  2197. if (win.protectedElems) {
  2198. protectedElems = win.protectedElems;
  2199. delete win.protectedElems;
  2200. }
  2201. document.removeEventListener('protoOverride', protoOverrideCallback, true);
  2202. }, true
  2203. );
  2204. _appendChild(script);
  2205. _removeChild(script);
  2206. }
  2207.  
  2208. // clean a page
  2209. window.addEventListener(
  2210. 'DOMContentLoaded', function()
  2211. {
  2212. let width = () => window.innerWidth || _de.clientWidth || document.body.clientWidth || 0;
  2213. let height = () => window.innerHeight || _de.clientHeight || document.body.clientHeight || 0;
  2214.  
  2215. if (isForum)
  2216. {
  2217. let si = document.querySelector('#logostrip');
  2218. if (si)
  2219. remove(si.parentNode.nextSibling);
  2220. }
  2221.  
  2222. // clear background in the download frame
  2223. if (location.pathname.startsWith('/forum/dl/')) {
  2224. let setBackground = node => _setAttribute.call(
  2225. node,
  2226. 'style', (_getAttribute.call(node, 'style') || '') +
  2227. ';background-color:#4ebaf6!important'
  2228. );
  2229. setBackground(document.body);
  2230. for (let itm of document.querySelectorAll('body > div'))
  2231. if (!itm.querySelector('.dw-fdwlink, .content') && !itm.classList.contains('footer')) {
  2232. remove(itm);
  2233. } else {
  2234. setBackground(itm);
  2235. }
  2236. }
  2237.  
  2238. if (isForum) // Do not continue if it's a forum
  2239. return;
  2240.  
  2241. {
  2242. let si = document.querySelector('#header');
  2243. if (si)
  2244. {
  2245. let rem = si.previousSibling;
  2246. while (rem)
  2247. {
  2248. si = rem.previousSibling;
  2249. remove(rem);
  2250. rem = si;
  2251. }
  2252. }
  2253. }
  2254.  
  2255. for (let itm of document.querySelectorAll('#nav li[class]'))
  2256. if (itm && itm.querySelector('a[href^="/tag/"]'))
  2257. remove(itm);
  2258.  
  2259. let style, result,
  2260. fakeStyles = new WeakMap(),
  2261. styleProxy = {
  2262. get: function(target, prop)
  2263. {
  2264. let fakeStyle = fakeStyles.get(target);
  2265. return ((prop in fakeStyle) ? fakeStyle : target)[prop];
  2266. },
  2267. set: function(target, prop, value)
  2268. {
  2269. let fakeStyle = fakeStyles.get(target);
  2270. ((prop in fakeStyle) ? fakeStyle : target)[prop] = value;
  2271. return true;
  2272. }
  2273. };
  2274. for (let itm of document.querySelectorAll('DIV, A'))
  2275. {
  2276. if (itm.tagName ==='DIV' &&
  2277. itm.offsetWidth > 0.95 * width() &&
  2278. itm.offsetHeight > 0.85 * height())
  2279. {
  2280. style = window.getComputedStyle(itm, null);
  2281. result = [];
  2282.  
  2283. if (style.backgroundImage !== 'none')
  2284. result.push('background-image:none!important');
  2285.  
  2286. if (style.backgroundColor !== 'transparent' &&
  2287. style.backgroundColor !== 'rgba(0, 0, 0, 0)')
  2288. result.push('background-color:transparent!important');
  2289.  
  2290. if (result.length)
  2291. {
  2292. if (itm.getAttribute('style'))
  2293. result.unshift(itm.getAttribute('style'));
  2294.  
  2295. fakeStyles.set(itm.style, {
  2296. 'backgroundImage': itm.style.backgroundImage,
  2297. 'backgroundColor': itm.style.backgroundColor
  2298. });
  2299.  
  2300. try {
  2301. Object.defineProperty(itm, 'style', {
  2302. value: new Proxy(itm.style, styleProxy),
  2303. enumerable: true
  2304. });
  2305. } catch (e) {
  2306. console.log('Unable to protect style property.', e);
  2307. }
  2308.  
  2309. if (protectedElems)
  2310. protectedElems.set(itm, _getAttribute.call(itm, 'style'));
  2311.  
  2312. _setAttribute.call(itm, 'style', result.join(';'));
  2313. }
  2314. }
  2315. if (itm.tagName ==='A' &&
  2316. (itm.offsetWidth > 0.95 * width() ||
  2317. itm.offsetHeight > 0.85 * height()))
  2318. {
  2319. if (protectedElems)
  2320. protectedElems.set(itm, _getAttribute.call(itm, 'style'));
  2321.  
  2322. _setAttribute.call(itm, 'style', 'display:none!important');
  2323. }
  2324. }
  2325.  
  2326. for (let itm of document.querySelectorAll('ASIDE>DIV'))
  2327. if ( ((itm.querySelector('script, iframe, a[href*="/ad/www/"]') ||
  2328. itm.querySelector('img[src$=".gif"]:not([height="0"]), img[height="400"]')) &&
  2329. !itm.classList.contains('post') ) || !itm.childNodes.length )
  2330. remove(itm);
  2331.  
  2332. document.body.setAttribute('style', (document.body.getAttribute('style')||'')+';background-color:#E6E7E9!important');
  2333.  
  2334. // display content of the page
  2335. afterClean();
  2336. }
  2337. );
  2338. }
  2339. };
  2340.  
  2341. scripts['adhands.ru'] = () => scriptLander(() => {
  2342. let nt = new nullTools();
  2343. try {
  2344. let _adv;
  2345. Object.defineProperty(win, 'adv', {
  2346. get: () => _adv,
  2347. set: (v) => {
  2348. console.log('Blocked advert on adhands.ru.');
  2349. nt.define(v, 'advert', '');
  2350. _adv = v;
  2351. }
  2352. });
  2353. } catch (ignore) {
  2354. if (!win.adv)
  2355. console.log('Unable to locate advert on adhands.ru.');
  2356. else {
  2357. console.log('Blocked advert on adhands.ru.');
  2358. nt.define(win.adv, 'advert', '');
  2359. }
  2360. }
  2361. }, nullTools);
  2362.  
  2363. scripts['all-episodes.tv'] = () => {
  2364. let nt = new nullTools();
  2365. nt.define(win, 'perX1', 2);
  2366. createStyle('#advtss, #ad3, a[href*="/ad.admitad.com/"] { display:none!important }');
  2367. };
  2368.  
  2369. scripts['allhentai.ru'] = () => {
  2370. selectiveEval();
  2371. preventPopups();
  2372. scriptLander(() => {
  2373. let _onerror = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'onerror');
  2374. if (!_onerror)
  2375. return;
  2376. _onerror.set = (...args) => console.log(args[0].toString());
  2377. Object.defineProperty(HTMLElement.prototype, 'onerror', _onerror);
  2378. });
  2379. };
  2380.  
  2381. scripts['allmovie.pro'] = {
  2382. other: ['rufilmtv.org'],
  2383. dom: function()
  2384. {
  2385. // pretend to be Android to make site use different played for ads
  2386. if (isSafari)
  2387. return;
  2388. Object.defineProperty(navigator, 'userAgent', {
  2389. 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'; },
  2390. enumerable: true
  2391. });
  2392. }
  2393. };
  2394.  
  2395. scripts['anidub-online.ru'] = {
  2396. other: ['online.anidub.com'],
  2397. dom: function()
  2398. {
  2399. if (win.ogonekstart1)
  2400. win.ogonekstart1 = () => console.log("Fire in the hole!");
  2401. },
  2402. now: () => createStyle([
  2403. '.background {background: none!important;}',
  2404. '.background > script + div,'+
  2405. '.background > script ~ div:not([id]):not([class]) + div[id][class]'+
  2406. '{display:none!important}'
  2407. ])
  2408. };
  2409.  
  2410. scripts['drive2.ru'] = () => gardener('.c-block:not([data-metrika="recomm"]),.o-grid__item', />Реклама<\//i);
  2411.  
  2412. scripts['fishki.net'] = () => {
  2413. scriptLander(() => {
  2414. let nt = new nullTools();
  2415. let fishki = {};
  2416. nt.define(fishki, 'adv', nt.proxy({
  2417. afterAdblockCheck: nt.func(null),
  2418. refreshFloat: nt.func(null)
  2419. }));
  2420. nt.define(fishki, 'is_adblock', false);
  2421. nt.define(win, 'fishki', fishki);
  2422. }, nullTools);
  2423. gardener('.drag_list > .drag_element, .list-view > .paddingtop15, .post-wrap', /543769|Новости\sпартнеров|Полезная\sреклама/);
  2424. };
  2425.  
  2426. scripts['gidonline.club'] = () => createStyle('.tray > div[style] {display: none!important}');
  2427.  
  2428. scripts['hdgo.cc'] = {
  2429. other: ['46.30.43.38', 'couber.be'],
  2430. now: () => (new MutationObserver(
  2431. (ms) => {
  2432. let m, node;
  2433. for (m of ms) for (node of m.addedNodes)
  2434. if (node.tagName instanceof HTMLScriptElement && _getAttribute.call(node, 'onerror') !== null)
  2435. node.removeAttribute('onerror');
  2436. }
  2437. )).observe(document.documentElement, { childList:true, subtree: true })
  2438. };
  2439.  
  2440. scripts['gismeteo.ru'] = {
  2441. other: ['gismeteo.ua'],
  2442. now: () => gardener('div > script', /AdvManager/i, { observe: true, parent: 'div' })
  2443. };
  2444.  
  2445. scripts['hdrezka.ag'] = () => {
  2446. Object.defineProperty(win, 'ab', { value: false, enumerable: true });
  2447. gardener('div[id][onclick][onmouseup][onmousedown]', /onmouseout/i);
  2448. };
  2449.  
  2450. scripts['hideip.me'] = {
  2451. now: () => scriptLander(() => {
  2452. let _innerHTML = Object.getOwnPropertyDescriptor(Element.prototype, 'innerHTML');
  2453. let _set_innerHTML = _innerHTML.set;
  2454. let _innerText = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'innerText');
  2455. let _get_innerText = _innerText.get;
  2456. let div = document.createElement('div');
  2457. _innerHTML.set = function(...args) {
  2458. _set_innerHTML.call(div, args[0].replace('i','a'));
  2459. if (args[0] && /[рp][еe]кл/.test(_get_innerText.call(div))||
  2460. /(\d\d\d?\.){3}\d\d\d?\:\d/.test(_get_innerText.call(this)) ) {
  2461. console.log('Anti-Adblock killed.');
  2462. return true;
  2463. }
  2464. _set_innerHTML.apply(this, args);
  2465. };
  2466. Object.defineProperty(Element.prototype, 'innerHTML', _innerHTML);
  2467. Object.defineProperty(win, 'adblock', {
  2468. get: x => false,
  2469. set: x => null,
  2470. enumerable: true
  2471. });
  2472. let _$ = {};
  2473. let _$_map = new WeakMap();
  2474. let _gOPD = Object.getOwnPropertyDescriptor(Object, 'getOwnPropertyDescriptor');
  2475. let _val_gOPD = _gOPD.value;
  2476. _gOPD.value = function(...args) {
  2477. let _res = _val_gOPD.apply(this, args);
  2478. if (args[0] instanceof Window && (args[1] === '$' || args[1] === 'jQuery')) {
  2479. delete _res.get;
  2480. delete _res.set;
  2481. _res.value = win[args[1]];
  2482. }
  2483. return _res;
  2484. };
  2485. Object.defineProperty(Object, 'getOwnPropertyDescriptor', _gOPD);
  2486. let getJQWrap = (n) => {
  2487. let name = n;
  2488. return {
  2489. enumerable: true,
  2490. get: x => _$[name],
  2491. set: x => {
  2492. if (_$_map.has(x)) {
  2493. _$[name] = _$_map.get(x);
  2494. return true;
  2495. }
  2496. if (x === _$.$ || x === _$.jQuery) {
  2497. _$[name] = x;
  2498. return true;
  2499. }
  2500. _$[name] = new Proxy(x, {
  2501. apply: (t, o, args) => {
  2502. let _res = t.apply(o, args);
  2503. if (_$_map.has(_res.is)) {
  2504. _res.is = _$_map.get(_res.is);
  2505. } else {
  2506. let _is = _res.is;
  2507. _res.is = function(...args) {
  2508. if (args[0] === ':hidden')
  2509. return false;
  2510. return _is.apply(this, args);
  2511. };
  2512. _$_map.set(_is, _res.is);
  2513. }
  2514. return _res;
  2515. }
  2516. });
  2517. _$_map.set(x, _$[name]);
  2518. return true;
  2519. }
  2520. };
  2521. };
  2522. Object.defineProperty(win, '$', getJQWrap('$'));
  2523. Object.defineProperty(win, 'jQuery', getJQWrap('jQuery'));
  2524. let _dP = Object.defineProperty;
  2525. Object.defineProperty = function(...args) {
  2526. if (args[0] instanceof Window && (args[1] === '$' || args[1] === 'jQuery'))
  2527. return void 0;
  2528. return _dP.apply(this, args);
  2529. };
  2530. })
  2531. };
  2532.  
  2533. scripts['igra-prestoloff.cx'] = () => scriptLander(() => {
  2534. let nt = new nullTools();
  2535. /*jslint evil: true */ // yes, evil, I know
  2536. let _write = document.write.bind(document);
  2537. /*jslint evil: false */
  2538. nt.define(document, 'write', t => {
  2539. let id = t.match(/jwplayer\("(\w+)"\)/i);
  2540. if (id && id[1]) {
  2541. return _write(`<div id="${id[1]}"></div>${t}`);
  2542. } else {
  2543. return _write('');
  2544. }
  2545. });
  2546. });
  2547.  
  2548. scripts['imageban.ru'] = {
  2549. now: () => {
  2550. Object.defineProperty(win, 'V7x1J', { get: () => null });
  2551. //preventPopunders();
  2552. }
  2553. };
  2554.  
  2555. scripts['kinopoisk.ru'] = {
  2556. now: () => {
  2557. // set no-branding body style
  2558. createStyle('body:not(#id) { background: #d5d5d5 url(/images/noBrandBg.jpg) 50% 0 no-repeat !important }');
  2559. },
  2560. dom: () => {
  2561. (style => style ? style.parentNode.removeChild(style) : console.log('Unable to locate branding style.')
  2562. )(_de.querySelector('#branding-style'));
  2563. }
  2564. };
  2565.  
  2566. scripts['korrespondent.net'] = {
  2567. now: () => scriptLander(() => {
  2568. let nt = new nullTools();
  2569. nt.define(win, 'holder', function(id) {
  2570. let div = document.getElementById(id);
  2571. if (!div)
  2572. return;
  2573. if (div.parentNode.classList.contains('col__sidebar')) {
  2574. div.parentNode.appendChild(div);
  2575. div.style.height = '300px';
  2576. }
  2577. });
  2578. }, nullTools),
  2579. dom: () => {
  2580. for (let frame of document.querySelectorAll('.unit-side-informer > iframe'))
  2581. frame.parentNode.style.width = '1px';
  2582. }
  2583. };
  2584.  
  2585. scripts['mail.ru'] = () => scriptLander(() => {
  2586. let nt = new nullTools();
  2587. // Trick to prevent mail.ru from removing 3rd-party styles
  2588. nt.define(Object.prototype, 'restoreVisibility', nt.func(null), false);
  2589. // Disable some of their counters
  2590. nt.define(win, 'rb_counter', nt.func(null, 'rb_counter'));
  2591. if (location.hostname !== 'e.mail.ru')
  2592. nt.define(win, 'createRadar', nt.func(nt.func(null, 'aRadar'), 'createRadar'));
  2593. else
  2594. nt.define(win, 'aRadar', nt.func(null, 'aRadar'));
  2595.  
  2596. // Disable page scrambler on mail.ru to let extensions easily block ads there
  2597. function defineLocator(root)
  2598. {
  2599. let _locator;
  2600. let fishnet = {
  2601. apply: (target, thisArg, args) => {
  2602. console.log(`locator.${target._name}(${JSON.stringify(args).slice(1,-1)})`);
  2603. return target.apply(thisArg, args);
  2604. }
  2605. };
  2606.  
  2607. function wrapLocator(locator)
  2608. {
  2609. if ('setup' in locator)
  2610. {
  2611. let _setup = locator.setup;
  2612. locator.setup = function(o)
  2613. {
  2614. if ('enable' in o)
  2615. {
  2616. o.enable = false;
  2617. console.log('Disable mimic mode.');
  2618. }
  2619. if ('links' in o)
  2620. {
  2621. o.links = [];
  2622. console.log('Call with empty list of sheets.');
  2623. }
  2624. return _setup.call(this, o);
  2625. };
  2626. locator.insertSheet = () => console.log('Ignore insertSheet.');
  2627. locator.wrap = () => console.log('Ignore wrap.');
  2628. }
  2629. try {
  2630. let names = [];
  2631. for (let name in locator)
  2632. if (locator[name] instanceof Function) {
  2633. locator[name]._name = name;
  2634. locator[name] = new Proxy(locator[name], fishnet);
  2635. names.push(name);
  2636. }
  2637. console.log(`[locator] wrapped properties: ${names.join(', ')}`);
  2638. } catch(e) {
  2639. console.log(e);
  2640. }
  2641. _locator = locator;
  2642. }
  2643.  
  2644. if ('locator' in root && root.locator)
  2645. {
  2646. console.log('Found existing "locator" object. :|');
  2647. _locator = root.locator;
  2648. wrapLocator(root.locator);
  2649. }
  2650.  
  2651. let loc_desc = Object.getOwnPropertyDescriptor(root, 'locator');
  2652. if (!loc_desc || loc_desc.set !== wrapLocator)
  2653. try {
  2654. Object.defineProperty(root, 'locator', {
  2655. set: wrapLocator,
  2656. get: () => _locator
  2657. });
  2658. } catch (err) {
  2659. console.log('Unable to redefine "locator" object!!!', err);
  2660. }
  2661. }
  2662.  
  2663. function defineDetector(mr)
  2664. {
  2665. let __ = mr._ || {};
  2666.  
  2667. if ('HONEYPOT' in __)
  2668. {
  2669. console.log('Disarming existing detector instance. :|', JSON.stringify(__));
  2670. nt.define(__, 'HONEYPOT', '.honeypot_fake_class_to_miss');
  2671. nt.define(__, 'STUCK_IN_POT', false);
  2672. }
  2673.  
  2674. __ = new Proxy(__, {
  2675. get: (t, p) => t[p],
  2676. set: (t, p, v) => {
  2677. console.log(`mr._.${p} =`, v);
  2678. if (['HONEYPOT', 'STUCK_IN_POT'].includes(p))
  2679. console.log('Not changed.');
  2680. t[p] = v; // setter in nt.define will prevent this when needed
  2681. return true;
  2682. }
  2683. });
  2684. Object.defineProperty(mr, '_', {
  2685. enumerable: true,
  2686. value: __
  2687. });
  2688. }
  2689.  
  2690. if (location.hostname === 'e.mail.ru')
  2691. defineLocator(win);
  2692. else {
  2693. try {
  2694. let _mr;
  2695. Object.defineProperty(win, 'mr', {
  2696. enumerable: true,
  2697. get: () => _mr,
  2698. set: (v) => {
  2699. if (v === _mr)
  2700. return true;
  2701. console.log('Trapped new "mr" object.');
  2702. defineLocator(v.mimic ? v.mimic : v);
  2703. defineDetector(v);
  2704. _mr = v;
  2705. }
  2706. });
  2707. if (!('mr' in win))
  2708. throw 'Wat!?';
  2709. } catch (e) {
  2710. console.log('Found existing "mr" object.', e instanceof TypeError ? '' : e);
  2711. defineLocator(win.mr);
  2712. defineDetector(win.mr);
  2713. }
  2714. }
  2715. }, nullTools);
  2716.  
  2717. scripts['megogo.net'] = {
  2718. now: () => {
  2719. let nt = new nullTools();
  2720. nt.define(win, 'adBlock', false);
  2721. nt.define(win, 'showAdBlockMessage', nt.func(null));
  2722. }
  2723. };
  2724.  
  2725. scripts['naruto-base.su'] = () => gardener('div[id^="entryID"],.block', /href="http.*?target="_blank"/i);
  2726.  
  2727. scripts['overclockers.ru'] = {
  2728. now: () => scriptLander(() => {
  2729. let _innerHTML = Object.getOwnPropertyDescriptor(Element.prototype, 'innerHTML');
  2730. let _set_innerHTML = _innerHTML.set;
  2731. _innerHTML.set = function() {
  2732. if (this === document.body) {
  2733. console.log('Anti-Adblock killed.');
  2734. return true;
  2735. }
  2736. _set_innerHTML.apply(this, arguments);
  2737. };
  2738. Object.defineProperty(Element.prototype, 'innerHTML', _innerHTML);
  2739. })
  2740. };
  2741. scripts['forums.overclockers.ru'] = {
  2742. now: () => {
  2743. createStyle('.needblock {position: fixed; left: -10000px}');
  2744. Object.defineProperty(win, 'adblck', {
  2745. get: () => 'no',
  2746. set: () => undefined,
  2747. enumerable: true
  2748. });
  2749. }
  2750. };
  2751.  
  2752. scripts['pb.wtf'] = {
  2753. other: ['piratbit.org', 'piratbit.ru'],
  2754. now: () => {
  2755. // line above topic content and images in the slider in the header
  2756. gardener(
  2757. 'a[href^="/exit/"], a[href^="/fxt/"], a[href$="=="]',
  2758. /img|Реклама|center/i,
  2759. { root: '.release-navbar,#page_content', observe: true, parent: 'div,tr' }
  2760. );
  2761. // ads in comments
  2762. gardener('img[data-name="PiraBo"]', /./i, {root:'#main_content .table', observe:true, parent:'tr'});
  2763. }
  2764. };
  2765.  
  2766. scripts['pikabu.ru'] = () => gardener('.story', /story__author[^>]+>ads</i, {root: '.inner_wrap', observe: true});
  2767.  
  2768. scripts['peka2.tv'] = () => {
  2769. let bodyClass = 'body--branding';
  2770. let checkNode = node => {
  2771. for (let className of node.classList)
  2772. if (className.includes('banner') || className === bodyClass) {
  2773. _removeAttribute.call(node, 'style');
  2774. node.classList.remove(className);
  2775. for (let attr of Array.from(node.attributes)) {
  2776. if (attr.name.startsWith('advert'))
  2777. _removeAttribute.call(node, attr.name);
  2778. }
  2779. }
  2780. };
  2781. (new MutationObserver(ms => {
  2782. let m, node;
  2783. for (m of ms) for (node of m.addedNodes)
  2784. if (node instanceof HTMLElement)
  2785. checkNode(node);
  2786. })).observe(_de, {childList: true, subtree: true});
  2787. (new MutationObserver(ms => {
  2788. for (let m of ms)
  2789. checkNode(m.target);
  2790. })).observe(_de, {attributes: true, subtree: true, attributeFilter: ['class']});
  2791. };
  2792.  
  2793. scripts['qrz.ru'] = {
  2794. now: () => {
  2795. let nt = new nullTools();
  2796. nt.define(win, 'ab', false);
  2797. nt.define(win, 'tryMessage', nt.func(null));
  2798. }
  2799. };
  2800.  
  2801. scripts['razlozhi.ru'] = {
  2802. now: () => {
  2803. for (let func of ['createShadowRoot', 'attachShadow'])
  2804. if (func in Element.prototype)
  2805. Element.prototype[func] = function(){ return this.cloneNode(); };
  2806. }
  2807. };
  2808.  
  2809. scripts['rbc.ru'] = {
  2810. dom: () => {
  2811. let _preventDefault = Event.prototype.preventDefault;
  2812. Event.prototype.preventDefault = function preventDefault()
  2813. {
  2814. let t = this.target;
  2815. if (t instanceof HTMLAnchorElement || t.closest('A'))
  2816. throw new Error('an.yandex redirect prevention');
  2817. return _preventDefault.call(this);
  2818. };
  2819.  
  2820. function cleaner(nodes)
  2821. {
  2822. for (let node of nodes)
  2823. {
  2824. if (!node.classList || !node.classList.contains('js-yandex-counter'))
  2825. continue;
  2826. node.classList.remove('js-yandex-counter');
  2827. node.removeAttribute('data-yandex-name');
  2828. node.removeAttribute('data-yandex-params');
  2829. }
  2830. }
  2831. cleaner(_de.querySelectorAll('.js-yandex-counter'));
  2832.  
  2833. (new MutationObserver(
  2834. ms => { for (let m of ms) cleaner(m.addedNodes); }
  2835. )).observe(_de, {childList: true, subtree: true});
  2836. }
  2837. };
  2838.  
  2839. scripts['rp5.ru'] = {
  2840. other: ['rp5.by', 'rp5.kz', 'rp5.ua'],
  2841. now: () => gardener('div[id][class]', /\?AdvertMgmt=|adsbygoogle/, { root: '#content-wrapper', log: true })
  2842. };
  2843.  
  2844. scripts['rutube.ru'] = () => scriptLander(() => {
  2845. let _parse = JSON.parse.bind(JSON);
  2846. let _skip_enabled = false;
  2847. JSON.parse = (...args) => {
  2848. let res = _parse(...args),
  2849. log = false;
  2850. if (!res)
  2851. return res;
  2852. // parse player configuration
  2853. if ('appearance' in res || 'video_balancer' in res) {
  2854. log = true;
  2855. if ('appearance' in res) {
  2856. res.appearance.forbid_seek = false;
  2857. res.appearance.forbid_timeline_preview = false;
  2858. }
  2859. _skip_enabled = !!res.remove_unseekable_blocks;
  2860. res.advert = [];
  2861. for (let limit of res.limits)
  2862. limit.limit = 0;
  2863. res.yast = null;
  2864. res.yast_live_online = null;
  2865. Object.defineProperty(res, 'stat', {
  2866. get: x => [],
  2867. set: x => true,
  2868. enumerable: true
  2869. });
  2870. }
  2871.  
  2872. // parse video configuration
  2873. if ('video_url' in res) {
  2874. log = true;
  2875. if ('cuepoints' in res && !_skip_enabled)
  2876. for (let point of res.cuepoints) {
  2877. point.is_pause = false;
  2878. point.show_navigation = true;
  2879. point.forbid_seek = false;
  2880. }
  2881. }
  2882.  
  2883. if (log)
  2884. console.log('[rutube]', res);
  2885. return res;
  2886. };
  2887. });
  2888.  
  2889. scripts['simpsonsua.com.ua'] = () => scriptLander(() => {
  2890. let _addEventListener = Object.getPrototypeOf(HTMLDocument).prototype.addEventListener;
  2891. document.addEventListener = function(event, callback) {
  2892. if (event === 'DOMContentLoaded' && callback.toString().includes('show_warning'))
  2893. return;
  2894. return _addEventListener.apply(this, arguments);
  2895. };
  2896. });
  2897.  
  2898. scripts['spaces.ru'] = () => {
  2899. gardener('div:not(.f-c_fll) > a[href*="spaces.ru/?Cl="]', /./, { parent: 'div' });
  2900. gardener('.js-banner_rotator', /./, { parent: '.widgets-group' });
  2901. };
  2902.  
  2903. scripts['spam-club.blogspot.co.uk'] = () => {
  2904. let _clientHeight = Object.getOwnPropertyDescriptor(Element.prototype, 'clientHeight'),
  2905. _clientWidth = Object.getOwnPropertyDescriptor(Element.prototype, 'clientWidth');
  2906. let wrapGetter = (getter) => {
  2907. let _getter = getter;
  2908. return function()
  2909. {
  2910. let _size = _getter.apply(this, arguments);
  2911. return _size ? _size : 1;
  2912. };
  2913. };
  2914. _clientHeight.get = wrapGetter(_clientHeight.get);
  2915. _clientWidth.get = wrapGetter(_clientWidth.get);
  2916. Object.defineProperty(Element.prototype, 'clientHeight', _clientHeight);
  2917. Object.defineProperty(Element.prototype, 'clientWidth', _clientWidth);
  2918. let _onload = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'onload'),
  2919. _set_onload = _onload.set;
  2920. _onload.set = function()
  2921. {
  2922. if (this instanceof HTMLImageElement)
  2923. return true;
  2924. _set_onload.apply(this, arguments);
  2925. };
  2926. Object.defineProperty(HTMLElement.prototype, 'onload', _onload);
  2927. };
  2928.  
  2929. scripts['sport-express.ru'] = () => gardener('.js-relap__item',/>Реклама\s+<\//, {root:'.container', observe: true});
  2930.  
  2931. scripts['sports.ru'] = {
  2932. now: () => {
  2933. gardener('.aside-news-list__item', /aside-news-list__advert/i, {root:'.columns-layout__left', observe: true});
  2934. gardener('.material-list__item', /Реклама/i, {root:'.columns-layout', observe: true});
  2935. // extra functionality: shows/hides panel at the top depending on scroll direction
  2936. createStyle([
  2937. '.user-panel__fixed { transition: top 0.2s ease-in-out!important; }',
  2938. '.user-panel-up { top: -40px!important }'
  2939. ], {id: 'userPanelSlide'}, false);
  2940. },
  2941. dom: () => {
  2942. (function lookForPanel()
  2943. {
  2944. let panel = document.querySelector('.user-panel__fixed');
  2945. if (!panel)
  2946. setTimeout(lookForPanel, 100);
  2947. else
  2948. window.addEventListener(
  2949. 'wheel', function(e)
  2950. {
  2951. if (e.deltaY > 0 && !panel.classList.contains('user-panel-up'))
  2952. panel.classList.add('user-panel-up');
  2953. else if (e.deltaY < 0 && panel.classList.contains('user-panel-up'))
  2954. panel.classList.remove('user-panel-up');
  2955. }, false
  2956. );
  2957. })();
  2958. }
  2959. };
  2960.  
  2961. scripts['stealthz.ru'] = {
  2962. dom: () => {
  2963. // skip timeout
  2964. let $ = document.querySelector.bind(document);
  2965. let [timer_1, timer_2] = [$('#timer_1'), $('#timer_2')];
  2966. if (!timer_1 || !timer_2)
  2967. return;
  2968. timer_1.style.display = 'none';
  2969. timer_2.style.display = 'block';
  2970. }
  2971. };
  2972.  
  2973. scripts['yap.ru'] = {
  2974. other: ['yaplakal.com'],
  2975. now: () => {
  2976. gardener('form > table[id^="p_row_"]:nth-of-type(2)', /member1438|Administration/);
  2977. gardener('.icon-comments', /member1438|Administration|\/go\/\?http/, {parent:'tr', siblings:-2});
  2978. }
  2979. };
  2980.  
  2981. scripts['rambler.ru'] = {
  2982. other: ['championat.com','gazeta.ru','media.eagleplatform.com','lenta.ru', 'quto.ru'],
  2983. now: () => scriptLander(() => {
  2984. // Prevent autoplay
  2985. if (!('EaglePlayer' in win)) {
  2986. let _EaglePlayer = void 0;
  2987. Object.defineProperty(win, 'EaglePlayer', {
  2988. enumerable: true,
  2989. get: x => _EaglePlayer,
  2990. set: x => {
  2991. if (x === _EaglePlayer)
  2992. return true;
  2993. _EaglePlayer = x;
  2994. let _init = void 0;
  2995. Object.defineProperty(_EaglePlayer.prototype, 'init', {
  2996. enumerable: true,
  2997. set: x => _init = x,
  2998. get: function() {
  2999. let _self = this;
  3000. if (_self.options) {
  3001. Object.defineProperty(this.options, 'autoplay', {
  3002. enumerable: true,
  3003. get: x => false,
  3004. set: x => null
  3005. });
  3006. }
  3007. if (_self.options && _self.options.el && inIFrame) {
  3008. let addListener = (player) => {
  3009. console.log('Attached autostop');
  3010. player.addEventListener('canplay', e => {
  3011. e.target.play = () => console.log('Applied autostop.');
  3012. setTimeout(player => {
  3013. delete player.play;
  3014. console.log('Detached autostop');
  3015. }, 1500, e.target);
  3016. }, false);
  3017. };
  3018. (new MutationObserver(ms => {
  3019. let m, node;
  3020. for (m of ms) for (node of m.addedNodes)
  3021. if (node instanceof HTMLVideoElement)
  3022. addListener(node);
  3023. })).observe(this.options.el, { childList: true, subtree: true });
  3024. }
  3025. return _init;
  3026. }
  3027. });
  3028. }
  3029. });
  3030. let _setAttribute = Element.prototype.setAttribute;
  3031. let isAutoplay = /^autoplay$/i;
  3032. Element.prototype.setAttribute = function setAttribute(name)
  3033. {
  3034. if (!this._stopped && isAutoplay.test(name))
  3035. {
  3036. console.log('Prevented assigning autoplay attribute.');
  3037. return null;
  3038. }
  3039. return _setAttribute.apply(this, arguments);
  3040. };
  3041. } else if (inIFrame) {
  3042. let _setAttribute = Element.prototype.setAttribute;
  3043. let isAutoplay = /^autoplay$/i;
  3044. Element.prototype.setAttribute = function setAttribute(name)
  3045. {
  3046. if (!this._stopped && isAutoplay.test(name))
  3047. {
  3048. console.log('Prevented assigning autoplay attribute.');
  3049. this._stopped = true;
  3050. this.play = () => {
  3051. console.log('Prevented attempt to force-start playback.');
  3052. delete this.play;
  3053. };
  3054. return null;
  3055. }
  3056. return _setAttribute.apply(this, arguments);
  3057. };
  3058. }
  3059. if (location.hostname.endsWith('.media.eagleplatform.com'))
  3060. return;
  3061. let CSSRuleProto = 'cssText' in CSSRule.prototype ? CSSRule.prototype : CSSStyleRule.prototype;
  3062. let _cssText = Object.getOwnPropertyDescriptor(CSSRuleProto, 'cssText');
  3063. let _cssText_get = _cssText.get;
  3064. _cssText.configurable = false;
  3065. _cssText.get = function()
  3066. {
  3067. let cssText = _cssText_get.call(this);
  3068. if (cssText.includes('content:'))
  3069. {
  3070. console.log('Blocked access to suspicious cssText:', cssText.slice(0,60), '\u2026', cssText.length);
  3071. return null;
  3072. }
  3073. return cssText;
  3074. };
  3075. Object.defineProperty(CSSRuleProto, 'cssText', _cssText);
  3076. // fake global Adf object
  3077. let nt = new nullTools();
  3078. let Adf_banner = {};
  3079. [
  3080. 'reloadssp', 'sspScroll',
  3081. 'sspRich', 'ssp'
  3082. ].forEach(name => Adf_banner[name] = nt.proxy(() => new Promise((r,j) => r({status: true}))));
  3083. nt.define(win, 'Adf', nt.proxy({
  3084. banner: nt.proxy(Adf_banner)
  3085. }));
  3086. // extra script to remove partner news on gazeta.ru
  3087. if (!location.hostname.includes('gazeta.ru'))
  3088. return;
  3089. (new MutationObserver(
  3090. (ms) => {
  3091. let m, node, header;
  3092. for (m of ms) for (node of m.addedNodes)
  3093. if (node instanceof HTMLDivElement && node.matches('.sausage'))
  3094. {
  3095. header = node.querySelector('.sausage-header');
  3096. if (header && /новости\s+партн[её]ров/i.test(header.textContent))
  3097. node.style.display = 'none';
  3098. }
  3099. }
  3100. )).observe(document.documentElement, { childList:true, subtree: true });
  3101. }, `let inIFrame = ${inIFrame}`, nullTools)
  3102. };
  3103.  
  3104. scripts['reactor.cc'] = {
  3105. other: ['joyreactor.cc', 'pornreactor.cc'],
  3106. now: () => {
  3107. selectiveEval();
  3108. scriptLander(() => {
  3109. let nt = new nullTools();
  3110. win.open = (function(){ throw new Error('Redirect prevention.'); }).bind(window);
  3111. nt.define(win, 'Worker', function(){});
  3112. nt.define(win, 'JRCH', win.CoinHive);
  3113. }, nullTools);
  3114. },
  3115. click: function(e)
  3116. {
  3117. let node = e.target;
  3118. if (node.nodeType === _Node.ELEMENT_NODE &&
  3119. node.style.position === 'absolute' &&
  3120. node.style.zIndex > 0)
  3121. node.parentNode.removeChild(node);
  3122. },
  3123. dom: function()
  3124. {
  3125. let words = new RegExp(
  3126. 'блокировщик рекламы'
  3127. .split('')
  3128. .map(function(e){return e+'[\u200b\u200c\u200d]*';})
  3129. .join('')
  3130. .replace(' ', '\\s*')
  3131. .replace(/[аоре]/g, function(e){return ['[аa]','[оo]','[рp]','[еe]']['аоре'.indexOf(e)];}),
  3132. 'i'),
  3133. can;
  3134. function deeper(spider)
  3135. {
  3136. let c, l, n;
  3137. if (words.test(spider.innerText))
  3138. {
  3139. if (spider.nodeType === _Node.TEXT_NODE)
  3140. return true;
  3141. c = spider.childNodes;
  3142. l = c.length;
  3143. n = 0;
  3144. while(l--)
  3145. if (deeper(c[l]), can)
  3146. n++;
  3147. if (n > 0 && n === c.length && spider.offsetHeight < 750)
  3148. can.push(spider);
  3149. return false;
  3150. }
  3151. return true;
  3152. }
  3153. function probe()
  3154. {
  3155. if (words.test(document.body.innerText))
  3156. {
  3157. can = [];
  3158. deeper(document.body);
  3159. let i = can.length, spider;
  3160. while(i--) {
  3161. spider = can[i];
  3162. if (spider.offsetHeight > 10 && spider.offsetHeight < 750)
  3163. _setAttribute.call(spider, 'style', 'background:none!important');
  3164. }
  3165. }
  3166. }
  3167. (new MutationObserver(probe))
  3168. .observe(document, { childList:true, subtree:true });
  3169. }
  3170. };
  3171.  
  3172. scripts['auto.ru'] = () => {
  3173. let words = /Реклама|Яндекс.Директ|yandex_ad_/;
  3174. let userAdsListAds = (
  3175. '.listing-list > .listing-item,'+
  3176. '.listing-item_type_fixed.listing-item'
  3177. );
  3178. let catalogAds = (
  3179. 'div[class*="layout_catalog-inline"],'+
  3180. 'div[class$="layout_horizontal"]'
  3181. );
  3182. let otherAds = (
  3183. '.advt_auto,'+
  3184. '.sidebar-block,'+
  3185. '.pager-listing + div[class],'+
  3186. '.card > div[class][style],'+
  3187. '.sidebar > div[class],'+
  3188. '.main-page__section + div[class],'+
  3189. '.listing > tbody'
  3190. );
  3191. gardener(userAdsListAds, words, {root:'.listing-wrap', observe:true});
  3192. gardener(catalogAds, words, {root:'.catalog__page,.content__wrapper', observe:true});
  3193. gardener(otherAds, words);
  3194. };
  3195.  
  3196. scripts['rsload.net'] = {
  3197. load: () => {
  3198. let dis = document.querySelector('label[class*="cb-disable"]');
  3199. if (dis)
  3200. dis.click();
  3201. },
  3202. click: () => {
  3203. let t = e.target;
  3204. if (t && t.href && (/:\/\/\d+\.\d+\.\d+\.\d+\//.test(t.href)))
  3205. t.href = t.href.replace('://','://rsload.net:rsload.net@');
  3206. }
  3207. };
  3208.  
  3209. let domain;
  3210. // add alternative domain names if present and wrap functions into objects
  3211. for (let name in scripts)
  3212. {
  3213. if (scripts[name] instanceof Function)
  3214. scripts[name] = { now: scripts[name] };
  3215. for (domain of (scripts[name].other||[]))
  3216. {
  3217. if (domain in scripts)
  3218. console.log('Error in scripts list. Script for', name, 'replaced script for', domain);
  3219. scripts[domain] = scripts[name];
  3220. }
  3221. delete scripts[name].other;
  3222. }
  3223. // look for current domain in the list and run appropriate code
  3224. domain = document.domain;
  3225. while (domain.indexOf('.') > -1)
  3226. {
  3227. if (domain in scripts) for (let when in scripts[domain])
  3228. switch(when)
  3229. {
  3230. case 'now':
  3231. scripts[domain][when]();
  3232. break;
  3233. case 'dom':
  3234. document.addEventListener('DOMContentLoaded', scripts[domain][when], false);
  3235. break;
  3236. default:
  3237. document.addEventListener (when, scripts[domain][when], false);
  3238. }
  3239. domain = domain.slice(domain.indexOf('.') + 1);
  3240. }
  3241.  
  3242. // Batch script lander
  3243. if (!skipLander)
  3244. landScript(batchLand, batchPrepend);
  3245.  
  3246. { // JS Fixes Tools Menu
  3247. let openOptions = function()
  3248. {
  3249. let ovl = _createElement('div'),
  3250. inner = _createElement('div');
  3251. ovl.style = (
  3252. 'position: fixed;'+
  3253. 'top:0; left:0;'+
  3254. 'bottom: 0; right: 0;'+
  3255. 'background: rgba(0,0,0,0.85);'+
  3256. 'z-index: 2147483647;'+
  3257. 'padding: 5em'
  3258. );
  3259. inner.style = (
  3260. 'background: whitesmoke;'+
  3261. 'font-size: 10pt;'+
  3262. 'color: black;'+
  3263. 'padding: 1em'
  3264. );
  3265. inner.textContent = 'JS Fixes Tools';
  3266. inner.appendChild(_createElement('br'));
  3267. inner.appendChild(_createElement('br'));
  3268. ovl.addEventListener(
  3269. 'click', function(e)
  3270. {
  3271. if (e.target === ovl) {
  3272. ovl.parentNode.removeChild(ovl);
  3273. e.preventDefault();
  3274. }
  3275. e.stopPropagation();
  3276. }, false
  3277. );
  3278.  
  3279. let sObjBtn = _createElement('button');
  3280. sObjBtn.onclick = getStrangeObjectsList;
  3281. sObjBtn.textContent = 'Print (in console) list of unusual window properties';
  3282. inner.appendChild(_createElement('br'));
  3283. inner.appendChild(sObjBtn);
  3284.  
  3285. document.body.appendChild(ovl);
  3286. ovl.appendChild(inner);
  3287. };
  3288.  
  3289. // monitor keys pressed for Ctrl+Alt+Shift+J > s > f code
  3290. let opPos = 0, opKey = ['KeyJ','KeyS','KeyF'];
  3291. document.addEventListener(
  3292. 'keydown', function(e)
  3293. {
  3294. if ((e.code === opKey[opPos] || e.location) &&
  3295. (!!opPos || e.altKey && e.ctrlKey && e.shiftKey))
  3296. {
  3297. opPos += e.location ? 0 : 1;
  3298. e.stopPropagation();
  3299. e.preventDefault();
  3300. } else {
  3301. opPos = 0;
  3302. }
  3303. if (opPos === opKey.length)
  3304. {
  3305. opPos = 0;
  3306. openOptions();
  3307. }
  3308. }, false
  3309. );
  3310. }
  3311. })();