RU AdList JS Fixes

try to take over the world!

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

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