RU AdList JS Fixes

try to take over the world!

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

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