RU AdList JS Fixes

try to take over the world!

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

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