RU AdList JS Fixes

try to take over the world!

当前为 2018-02-22 提交的版本,查看 最新版本

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