RU AdList JS Fixes

try to take over the world!

目前為 2019-02-11 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name RU AdList JS Fixes
  3. // @namespace ruadlist_js_fixes
  4. // @version 20190211.2
  5. // @description try to take over the world!
  6. // @author lainverse & dimisa
  7. // @supportURL https://greasyfork.org/en/scripts/19993-ru-adlist-js-fixes/feedback
  8. // @match *://*/*
  9. // @exclude *://auth.wi-fi.ru/*
  10. // @exclude *://*.alfabank.ru/*
  11. // @exclude *://alfabank.ru/*
  12. // @exclude *://*.unicreditbanking.net/*
  13. // @exclude *://unicreditbanking.net/*
  14. // @exclude *://*.telegram.org/*
  15. // @exclude *://telegram.org/*
  16. // @grant unsafeWindow
  17. // @grant window.close
  18. // @run-at document-start
  19. // ==/UserScript==
  20.  
  21. (function() {
  22. 'use strict';
  23.  
  24. let win = (unsafeWindow || window);
  25.  
  26. // MooTools are crazy enough to replace standard browser object window.Document: https://mootools.net/core
  27. // Occasionally their code runs before my script on some domains and causes all kinds of havoc.
  28. let _Document = Object.getPrototypeOf(HTMLDocument.prototype);
  29. let _Element = Object.getPrototypeOf(HTMLElement.prototype);
  30. // dTree 2.05 in some cases replaces Node object
  31. let _Node = Object.getPrototypeOf(_Element);
  32. let _console = {};
  33. for (let name in win.console) _console[name] = console[name];
  34.  
  35. // http://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser
  36. let isOpera = (!!window.opr && !!window.opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0,
  37. isChrome = !!window.chrome && !!window.chrome.webstore,
  38. isSafari =
  39. Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0 ||
  40. (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window.safari || window.safari.pushNotification);
  41. let isFirefox = 'InstallTrigger' in win;
  42. let inIFrame = (win.self !== win.top);
  43. let _getAttribute = Function.prototype.call.bind(_Element.getAttribute),
  44. _setAttribute = Function.prototype.call.bind(_Element.setAttribute),
  45. _removeAttribute = Function.prototype.call.bind(_Element.removeAttribute);
  46. let _document = win.document,
  47. _de = _document.documentElement,
  48. _appendChild = _Document.appendChild.bind(_de),
  49. _removeChild = _Document.removeChild.bind(_de),
  50. _createElement = _Document.createElement.bind(_document),
  51. _querySelector = _Document.querySelector.bind(_document),
  52. _querySelectorAll = _Document.querySelectorAll.bind(_document);
  53.  
  54. if (isFirefox && // Exit on image pages in Fx
  55. _document.constructor.prototype.toString() === '[object ImageDocumentPrototype]')
  56. return;
  57.  
  58. // NodeList and HTMLCollection iterator polyfill
  59. // required for old versions of Safari and Chrome 49 (last available for WinXP)
  60. // https://jakearchibald.com/2014/iterators-gonna-iterate/
  61. if (!NodeList.prototype[Symbol.iterator])
  62. NodeList.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
  63. if (!HTMLCollection.prototype[Symbol.iterator])
  64. HTMLCollection.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
  65.  
  66. // Wrapper to run scripts designed to override objects available to other scripts
  67. // Required in old versions of Firefox (<58) or when running with Greasemonkey
  68. let skipLander = true;
  69. try {
  70. skipLander = !(isFirefox && ('StopIteration' in win || GM.info.scriptHandler === 'Greasemonkey'));
  71. } catch(ignore){}
  72. let batchLand = [];
  73. let batchPrepend = [];
  74. let _APIString = 'let win = window, _console = {}; for (let name in win.console) _console[name] = console[name]; '+
  75. 'let _document = win.document, _Document = Object.getPrototypeOf(HTMLDocument.prototype),'+
  76. ' _Element = Object.getPrototypeOf(HTMLElement.prototype), _Node = Object.getPrototypeOf(_Element);';
  77. let landScript = (f, pre) => {
  78. let script = _createElement('script');
  79. script.textContent = `(()=>{${_APIString}${(
  80. (pre.length > 0 ? pre.join(';') : '')
  81. )};(${f.join(')();(')})();})();`;
  82. _appendChild(script);
  83. _removeChild(script);
  84. };
  85. let scriptLander = f => f();
  86. if (!skipLander) {
  87. scriptLander = (func, ...prepend) => {
  88. prepend.forEach(
  89. x => batchPrepend.includes(x) ? null : batchPrepend.push(x)
  90. );
  91. batchLand.push(func);
  92. };
  93. _document.addEventListener(
  94. 'DOMContentLoaded', () => void (scriptLander = (f, ...prep) => landScript([f], prep)), false
  95. );
  96. }
  97.  
  98. function nullTools(opts) {
  99. let nt = this;
  100. opts = opts || {};
  101. let log = (...args) => opts.log && _console.log(...args);
  102. let warn = (...args) => _console.warn(...args);
  103. let trace = (...args) => (opts.log || opts.trace) && warn(...args);
  104.  
  105. nt.destroy = function(o, destroy) {
  106. if (!opts.destroy && !destroy && o instanceof Object)
  107. return;
  108. log('cleaning', o);
  109. try {
  110. for (let item in o) {
  111. if (item instanceof Object)
  112. nt.destroy(item);
  113. delete o[item];
  114. }
  115. } catch (e) {
  116. log('Error in object destructor', e);
  117. }
  118. };
  119.  
  120. nt.define = function(obj, prop, val, enumerable = true) {
  121. try {
  122. Object.defineProperty(
  123. obj, prop, {
  124. get: () => val,
  125. set: v => {
  126. if (v !== val) {
  127. log(`set ${prop} of`, obj, 'to', v);
  128. nt.destroy(v);
  129. }
  130. },
  131. enumerable: enumerable
  132. }
  133. );
  134. } catch (err) {
  135. _console.log(`Unable to redefine "${prop}" in `, obj, err);
  136. }
  137. };
  138. nt.proxy = function(obj, missingFuncParentName, missingFuncValue) {
  139. return new Proxy(
  140. obj, {
  141. get: (t, p) => {
  142. if (p in t)
  143. return t[p];
  144. if (typeof p === 'symbol') {
  145. t[p] = void 0;
  146. _console.warn('Missing', p, missingFuncParentName ? `in ${missingFuncParentName}` : '', '>>', t[p]);
  147. return t[p];
  148. }
  149. if (missingFuncParentName) {
  150. t[p] = nt.func(missingFuncValue, `${missingFuncParentName}.${p}`);
  151. return t[p];
  152. }
  153. _console.warn(`Missing ${p} in`, t);
  154. },
  155. set: (t, p, v) => {
  156. if (v !== t[p]) {
  157. log(`set ${p} of`, t, 'to', v);
  158. nt.destroy(v);
  159. }
  160. return true;
  161. }
  162. }
  163. );
  164. };
  165. nt.func = (val, name = '', force_log = false) => nt.proxy((...args) => {
  166. (force_log ? warn : trace)(`call ${name}(`, ...args,`) return`, val);
  167. return val;
  168. });
  169. }
  170.  
  171. // Debug function, lists all unusual window properties
  172. function getStrangeObjectsList() {
  173. _console.warn('Strangers list start');
  174. let _toString = Function.prototype.call.bind(Function.prototype.toString);
  175. let _skip = 'frames/self/window/webkitStorageInfo'.split('/');
  176. for (let n in win) {
  177. let val = win[n];
  178. if (val && !_skip.includes(n) && (win !== window && val !== window[n] || win === window) &&
  179. (!(val instanceof Function) ||
  180. val instanceof Function &&
  181. !(new RegExp (`^function\\s(${n})?\\(\\)[\\s\\r\\n]*\\{[\\s\\r\\n]*\\[native\\scode\\][\\s\\r\\n]*\\}$`)).test(_toString(val))))
  182. _console.log(`${n} =`, val);
  183. }
  184. _console.warn('Strangers list end');
  185. }
  186.  
  187. // Creates and return protected style (unless protection is manually disabled).
  188. // Protected style will re-add itself on removal and remaind enabled on attempt to disable it.
  189. function createStyle(rules, props, skip_protect) {
  190. props = props || {};
  191. props.type = 'text/css';
  192.  
  193. function _protect(style) {
  194. if (skip_protect)
  195. return;
  196.  
  197. Object.defineProperty(style, 'sheet', {
  198. value: null,
  199. enumerable: true
  200. });
  201. Object.defineProperty(style, 'disabled', {
  202. get: () => true, //pretend to be disabled
  203. set: () => undefined,
  204. enumerable: true
  205. });
  206. (new MutationObserver(
  207. (ms) => _removeChild(ms[0].target)
  208. )).observe(style, { childList: true });
  209. }
  210.  
  211.  
  212. function _create() {
  213. let style = _appendChild(_createElement('style'));
  214. Object.assign(style, props);
  215.  
  216. function insertRules(rule) {
  217. if (rule.forEach)
  218. rule.forEach(insertRules);
  219. else try {
  220. style.sheet.insertRule(rule, 0);
  221. } catch (e) {
  222. _console.error(e);
  223. }
  224. }
  225.  
  226. insertRules(rules);
  227. _protect(style);
  228.  
  229. return style;
  230. }
  231.  
  232. let style = _create();
  233. if (skip_protect)
  234. return style;
  235.  
  236. (new MutationObserver(
  237. function(ms) {
  238. let m, node;
  239. let createStyleInANewThread = resolve => setTimeout(
  240. resolve => resolve(_create()),
  241. 0, resolve
  242. );
  243. let setStyle = st => void(style = st);
  244. for (m of ms) for (node of m.removedNodes)
  245. if (node === style)
  246. (new Promise(createStyleInANewThread))
  247. .then(setStyle);
  248. }
  249. )).observe(_de, { childList: true });
  250.  
  251. return style;
  252. }
  253.  
  254. // Fake objects of advertisement networks to break their workflow
  255. // Popular adblock detector
  256. function deployFAB() {
  257. let nt = new nullTools();
  258. if (!('fuckAdBlock' in win)) {
  259. let FuckAdBlock = function(options) {
  260. let self = this;
  261. self._options = {
  262. checkOnLoad: false,
  263. resetOnEnd: false,
  264. checking: false
  265. };
  266. self.setOption = function(opt, val) {
  267. if (val)
  268. self._options[opt] = val;
  269. else
  270. Object.assign(self._options, opt);
  271. };
  272. if (options)
  273. self.setOption(options);
  274.  
  275. self._var = { event: {} };
  276. self.clearEvent = function() {
  277. self._var.event.detected = [];
  278. self._var.event.notDetected = [];
  279. };
  280. self.clearEvent();
  281.  
  282. self.on = function(detected, fun) {
  283. self._var.event[detected?'detected':'notDetected'].push(fun);
  284. return self;
  285. };
  286. self.onDetected = function(cb) {
  287. return self.on(true, cb);
  288. };
  289. self.onNotDetected = function(cb) {
  290. return self.on(false, cb);
  291. };
  292. self.emitEvent = function() {
  293. for (let fun of self._var.event.notDetected)
  294. fun();
  295. if (self._options.resetOnEnd)
  296. self.clearEvent();
  297. return self;
  298. };
  299. self._creatBait = () => null;
  300. self._destroyBait = () => null;
  301. self._checkBait = function() {
  302. setTimeout((() => self.emitEvent()), 1);
  303. };
  304. self.check = function() {
  305. self._checkBait();
  306. return true;
  307. };
  308.  
  309. let callback = function() {
  310. if (self._options.checkOnLoad)
  311. setTimeout(self.check, 1);
  312. };
  313. window.addEventListener('load', callback, false);
  314. };
  315. nt.define(win, 'FuckAdBlock', FuckAdBlock);
  316. nt.define(win, 'fuckAdBlock', new FuckAdBlock({
  317. checkOnLoad: true,
  318. resetOnEnd: true
  319. }));
  320. }
  321. }
  322. // new version of fAB adapting to fake API
  323. if (!location.hostname.endsWith('omsi2mod.ru') && // let them fail a bit later then
  324. !location.hostname.endsWith('dok-film.net'))
  325. scriptLander(deployFAB, nullTools);
  326.  
  327. scriptLander(() => {
  328. let nt = new nullTools();
  329.  
  330. // CoinHive miner stub. Continuous 100% CPU load can easily kill some CPU with overheat.
  331. if (!('CoinHive' in win))
  332. if (location.hostname !== 'cnhv.co') {
  333. // CoinHive stub for cases when it doesn't affect site functionality
  334. let CoinHiveConstructor = function() {
  335. _console.warn('Fake CoinHive miner created.');
  336. this.setThrottle = nt.func(null);
  337. this.start = nt.func(null);
  338. this.on = nt.func(null);
  339. this.getHashesPerSecond = nt.func(Infinity);
  340. this.getTotalHashes = nt.func(Infinity);
  341. this.getAcceptedHashes = nt.func(Infinity);
  342. };
  343. let CoinHiveStub = nt.proxy({
  344. Anonymous: CoinHiveConstructor,
  345. User: CoinHiveConstructor,
  346. Token: CoinHiveConstructor,
  347. JobThread: nt.func(null),
  348. Res: nt.func(null),
  349. IF_EXCLUSIVE_TAB: false,
  350. CONFIG: nt.proxy({})
  351. });
  352. nt.define(win, 'CoinHive', CoinHiveStub);
  353. } else {
  354. // CoinHive wrapper to fool sites which expect it to actually work and return results
  355. let CoinHiveObject;
  356. Object.defineProperty(win, 'CoinHive', {
  357. set: function(obj) {
  358. if ('Token' in obj) {
  359. _console.log('[CoinHive] Token wrapper applied.');
  360. let _Token = obj.Token.bind(obj);
  361. obj.Token = function(siteKey, goal, params) {
  362. let _goal = goal;
  363. goal = goal > 256 ? 256 : goal;
  364. _console.log(`[CoinHive] Original goal: ${_goal}, new smaller goal ${goal}.`);
  365. _console.log(`With smaller goals server may return 'invalid_goal' error and stop working.`);
  366. let miner = _Token(siteKey, goal, params);
  367. miner.setThrottle(0.99);
  368. miner.setThrottle = () => null;
  369. let _start = miner.start.bind(miner);
  370. miner.start = function() {
  371. let res = _start(window.CoinHive.FORCE_EXCLUSIVE_TAB);
  372. return res;
  373. };
  374. let _getTotalHashes = miner.getTotalHashes;
  375. miner.getTotalHashes = function() {
  376. return Math.trunc(_getTotalHashes.call(this) / goal * _goal);
  377. };
  378. let __emit = miner._emit;
  379. miner._emit = function(state, props) {
  380. let _self = this;
  381. _console.log('[CoinHive] state:', state, props);
  382. if (state === 'job')
  383. setTimeout(() => {
  384. _self.stop();
  385. _self._emit('accepted', { hashes: goal });
  386. }, 1000);
  387. return __emit.apply(_self, arguments);
  388. };
  389. let _on = miner.on.bind(miner);
  390. miner.on = function(type, callback) {
  391. if (type === 'accepted') {
  392. _console.log('[CoinHive] "accepted" callback wrapper applied.');
  393. let _callback = callback;
  394. callback = function(params) {
  395. _console.log('[CoinHive] "accepted" callback is called, imitating original goal being reached.');
  396. params.hashes = _goal;
  397. return _callback.apply(this, arguments);
  398. };
  399. miner.stop();
  400. }
  401. return _on(type, callback);
  402. };
  403. return miner;
  404. };
  405. }
  406. CoinHiveObject = obj;
  407. },
  408. get: () => CoinHiveObject
  409. });
  410. }
  411.  
  412. // VideoJS player wrapper
  413. VideoJS: {
  414. let _videojs = win.videojs || void 0;
  415. Object.defineProperty(win, 'videojs', {
  416. get: () => _videojs,
  417. set: f => {
  418. if (f === _videojs)
  419. return true;
  420. _console.log('videojs =', f);
  421. _videojs = new Proxy(f, {
  422. apply: (tgt, ths, args) => {
  423. _console.log('videojs(', ...args, ')');
  424. let params = args[1];
  425. if (params) {
  426. if (params.hasAd)
  427. params.hasAd = false;
  428. if (params.autoplay)
  429. params.autoplay = false;
  430. if (params.plugins && params.plugins.vastClient)
  431. delete params.plugins.vastClient;
  432. }
  433. let res = tgt.apply(ths, args);
  434. if (res && res.seed)
  435. res.seed = () => null;
  436. _console.log('player = ', res);
  437. return res;
  438. }
  439. });
  440. }
  441. });
  442. }
  443.  
  444. // Set a little trap for BodyClick ads
  445. Object.defineProperty(win, '__BC_domain', {
  446. set: () => { throw 'BodyClick trap' }
  447. });
  448.  
  449. // Yandex API (ADBTools, Metrika)
  450. let hostname = location.hostname;
  451. if (// Thank you, Greasemonkey, now I have to check for this. -_-
  452. location.protocol === 'about:' ||
  453. // Google likes to define odd global variables like Ya
  454. hostname.startsWith('google.') || hostname.includes('.google.') ||
  455. // Also, Yandex uses their Ya object for a lot of things on their pages and
  456. // wrapping it may cause problems. It's better to skip it in some cases.
  457. ((hostname.startsWith('yandex.') || hostname.includes('.yandex.')) &&
  458. /^\/((yand)?search|images)/i.test(location.pathname) && !hostname.startsWith('news.')) ||
  459. // Also skip on these following sites since they use
  460. // code minification which generated global Ya variable.
  461. hostname.endsWith('chatango.com') || hostname.endsWith('github.io') ||
  462. hostname.endsWith('grimtools.com') || hostname.endsWith('poeplanner.com'))
  463. return;
  464.  
  465. let YaProps = new Set();
  466. function setObfuscatedProperty(Ya, rootProp, obj, name) {
  467. if (YaProps.has(rootProp))
  468. return;
  469. _console.warn(`Ya.${rootProp} = Ya.${name}`);
  470. nt.define(Ya, rootProp, Ya[name]);
  471. YaProps.add(rootProp);
  472. for (let prop in obj)
  473. delete obj[prop];
  474. for (let prop in Ya[name])
  475. obj[prop] = Ya[name][prop];
  476. }
  477. function onObfuscatedProperty (Ya, rootProp, obj) {
  478. if ('AdvManager' in obj || 'isAllowedRepeatAds' in obj) {
  479. setObfuscatedProperty(Ya, rootProp, obj, 'Context');
  480. return Ya.Context;
  481. }
  482. if ('create' in obj && 'createAdaptive' in obj && 'createScroll' in obj) {
  483. setObfuscatedProperty(Ya, rootProp, obj, 'adfoxCode');
  484. return Ya.adfoxCode;
  485. }
  486. return new Proxy(obj, {
  487. set: (tgt, prop, val) => {
  488. if (prop === 'AdvManager' || prop === 'isAllowedRepeatAds') {
  489. setObfuscatedProperty(Ya, rootProp, obj, 'Context');
  490. return true;
  491. }
  492. if (prop === 'create' && 'createAdaptive' in obj && 'createScroll' in obj ||
  493. prop === 'createScroll' && 'create' in obj && 'createAdaptive' in obj ||
  494. prop === 'createAdaptive' && 'create' in obj && 'createScroll' in obj) {
  495. setObfuscatedProperty(Ya, rootProp, obj, 'adfoxCode');
  496. return true;
  497. }
  498. tgt[prop] = val;
  499. return true;
  500. },
  501. get: (tgt, prop) => {
  502. if (prop === 'AdvManager' && !(prop in tgt)) {
  503. _console.warn(`Injected missing ${prop} in Ya.${rootProp}.`);
  504. tgt[prop] = Ya.Context[prop];
  505. }
  506. return tgt[prop];
  507. }
  508. });
  509. }
  510. let Rum = {};
  511. [
  512. '__timeMarks', '_timeMarks', '__deltaMarks', '_deltaMarks',
  513. '__defRes', '_defRes', '__defTimes', '_defTimes', '_vars',
  514. 'commonVars'
  515. ].forEach(name => void(Rum[name] = []));
  516. [
  517. 'getSettings', 'getVarsList'
  518. ].forEach(name => void(Rum[name] = nt.func([], `Ya.Rum.${name}`)));
  519. [
  520. ['ajaxStart', 0], ['ajaxComplete', 0],
  521. ['enabled', true], ['_tti', null],
  522. ['vsChanged', false], ['vsStart', 'visible']
  523. ].forEach(([prop, val]) => void(Rum[prop] = val));
  524. Rum = nt.proxy(Rum, 'Ya.Rum', null);
  525. let Ya = new Proxy({}, {
  526. set: function(tgt, prop, val) {
  527. if (val === tgt[prop])
  528. return true;
  529. if (prop === 'Rum') {
  530. nt.define(tgt, prop, Rum);
  531. YaProps.add(prop);
  532. Object.assign(val, Rum);
  533. }
  534. if (YaProps.has(prop)) {
  535. _console.log(`Ya.${prop} \u2260`, val);
  536. return true;
  537. }
  538. if (val instanceof Object && prop !== '__inline_params__')
  539. val = onObfuscatedProperty(Ya, prop, val);
  540. tgt[prop] = val;
  541. _console.log(`Ya.${prop} =`, val);
  542. return true;
  543. },
  544. get: (tgt, prop) => tgt[prop]
  545. });
  546. let callWithParams = function(f) {
  547. f.call(this, Ya.__inline_params__ || {});
  548. Ya.__inline_params__ = null;
  549. };
  550. nt.define(Ya, 'callWithParams', callWithParams);
  551. nt.define(Ya, 'PerfCounters', nt.proxy({
  552. __cacheEvents: []
  553. }, 'Ya.PerfCounters', null));
  554. nt.define(Ya, '__isSent', true);
  555. nt.define(Ya, 'confirmUrl', '');
  556. nt.define(Ya, 'Direct', nt.proxy({}, 'Ya.Direct', null));
  557. nt.define(Ya, 'mediaCode', nt.proxy({
  558. create: function() {
  559. if (inIFrame) {
  560. _console.log('Removed body of ad-frame.');
  561. _document.documentElement.removeChild(_document.body);
  562. }
  563. }
  564. }, 'Ya.mediaCode', null));
  565. let extra = nt.proxy({
  566. extra: nt.proxy({ match: 0, confirm: '', src: '' }),
  567. id: 0, percent: 100, threshold: 1
  568. });
  569. nt.define(Ya, '_exp', nt.proxy({
  570. id: 0, coin: 0,
  571. choose: nt.func(extra),
  572. get: (prop) => extra.hasOwnProperty(prop) ? extra[prop] : null,
  573. getId: nt.func(0),
  574. defaultVersion: extra,
  575. getExtra: nt.func(extra.extra),
  576. getDefaultExtra: nt.func(extra.extra),
  577. versions: [extra]
  578. }));
  579. nt.define(Ya, 'c', nt.func(null));
  580. nt.define(Ya, 'ADBTools', function(){
  581. this.getCurrentState = nt.func(true);
  582. return nt.proxy(this, 'Ya.ADBTools', null);
  583. });
  584. nt.define(Ya, 'AdDetector', nt.proxy({}, 'Ya.AdDetector', null));
  585. let adfoxCode = {
  586. forcedDirectLoadingExp: nt.proxy({ isLoadingTurnedOn: false, isExp: false }),
  587. isLoadingTurnedOn: false,
  588. xhrExperiment: nt.proxy({ isXhr: true, isControl: true }),
  589. pr: 0, _: []
  590. };
  591. [
  592. 'clearSession', 'create', 'createAdaptive', 'createScroll',
  593. 'destroy', 'moduleLoad', 'reload', 'setModule'
  594. ].forEach(name => void(adfoxCode[name] = nt.func(null, `Ya.adfoxCode.${name}`)));
  595. nt.define(Ya, 'adfoxCode', nt.proxy(adfoxCode, 'Ya.adfoxCode', null));
  596. let managerForAdfox = {
  597. loaderVersion: 1,
  598. isCurrrencyExp: true,
  599. isReady: nt.func(true, 'Ya.headerBidding.managerForAdfox.isReady'),
  600. getRequestTimeout: nt.func(300 + Math.floor(Math.random()*100), 'Ya.headerBidding.managerForAdfox.getRequestTimeout')
  601. };
  602. let headerBidding = nt.proxy({
  603. setSettings: opts => {
  604. if (!(opts && opts.adUnits))
  605. return null;
  606. let ids = [];
  607. for (let unit of opts.adUnits)
  608. ids.push(unit.code);
  609. createStyle(`#${ids.join(', #')} { display: none !important }`);
  610. },
  611. managerForAdfox: nt.proxy(managerForAdfox, 'Ya.headerBidding.managerForAdfox', null)
  612. });
  613. nt.define(Ya, 'headerBidding', headerBidding);
  614.  
  615. let AdvManager = function() {
  616. this.render = function(o) {
  617. if (!o.renderTo)
  618. return;
  619. let placeholder = _document.getElementById(o.renderTo);
  620. if (!placeholder)
  621. return _console.warn('Ya.AdvManager.render call w/o placeholder', o);
  622. let parent = placeholder.parentNode;
  623. placeholder.style = 'display:none!important';
  624. parent.style = (parent.getAttribute('style')||'') + 'height:auto!important';
  625. // fix for Yandex TV pages
  626. if (location.hostname.startsWith('tv.yandex.')) {
  627. let sibling = placeholder.previousSibling;
  628. if (sibling && sibling.classList && sibling.classList.contains('tv-spin'))
  629. sibling.style.display = 'none';
  630. }
  631. };
  632. this.constructor = Object;
  633. return nt.proxy(this, 'Ya.AdvManager', null);
  634. };
  635. let _Ya_Context_undefined_count = {};
  636. nt.define(Ya, 'Context', new Proxy({
  637. __longExperiment: null,
  638. _callbacks: nt.proxy([]),
  639. _asyncModeOn: true,
  640. _init: nt.func(null),
  641. _load_callbacks: nt.proxy([]),
  642. processCallbacks: nt.func(null),
  643. isAllowedRepeatAds: nt.func(null),
  644. isNewLoader: nt.func(false),
  645. AdvManager: new AdvManager(),
  646. AdvManagerStatic: nt.func({})
  647. }, {
  648. get: (ctx, prop) => {
  649. if (prop in ctx)
  650. return ctx[prop];
  651. if (prop in _Ya_Context_undefined_count)
  652. _Ya_Context_undefined_count[prop]++;
  653. else {
  654. _Ya_Context_undefined_count[prop] = 1;
  655. _console.warn(`Mising '${prop}' in Ya.Context`);
  656. }
  657. if (_Ya_Context_undefined_count[prop] >= 5) {
  658. _console.warn(`Ya.Context.${prop} = Ya.Context.AdvManager`);
  659. ctx[prop] = ctx.AdvManager;
  660. }
  661. },
  662. set: () => true
  663. }));
  664. let Metrika = function Metrika(x) {
  665. this._ecommerce = '';
  666. if (x && 'id' in x)
  667. this.id = x.id;
  668. else
  669. this.id = 0;
  670. return nt.proxy(this, 'Ya.Metrika', null);
  671. };
  672. Metrika.counters = () => Ya._metrika.counters;
  673. nt.define(Ya, 'Metrika', Metrika);
  674. nt.define(Ya, 'Metrika2', Metrika);
  675. let counter = new Ya.Metrika();
  676. nt.define(Ya, '_metrika', nt.proxy({
  677. counter: counter,
  678. counters: [counter],
  679. hitParam: {},
  680. counterNum: 0,
  681. hitId: 0,
  682. v: 1,
  683. i: 0,
  684. _globalMetrikaHitId: 0,
  685. getCounters: null,
  686. dataLayer: null,
  687. f1: null
  688. }));
  689. nt.define(Ya, '_globalMetrikaHitId', 0);
  690. counter = {};
  691. [
  692. 'stringifyParams','_getVars',
  693. 'getUid','getUrl','getHash'
  694. ].forEach(name => void(counter[name] = nt.func('', `Ya.counter.${name}`)));
  695. nt.define(Ya, 'counter', nt.proxy(counter, 'Ya.counter', null));
  696. nt.define(Ya, 'jserrors', []);
  697. nt.define(Ya, 'onerror', nt.func(null, 'Ya.onerror'));
  698. let error_on_access = false;
  699. if ('Ya' in win)
  700. try {
  701. _console.log('Found existing Ya object:', win.Ya);
  702. for (let prop in win.Ya)
  703. Ya[prop] = win.Ya[prop];
  704. } catch(ignore) {
  705. error_on_access = true;
  706. }
  707. if (!error_on_access && // some people don't know how to export only necessary stuff into global context
  708. location.hostname !== 'material.io') { // so, here is an exception for one of such cases
  709. for (let prop in Ya)
  710. if (prop !== '__inline_params__')
  711. YaProps.add(prop);
  712. nt.define(win, 'Ya', Ya);
  713. } else
  714. _console.log('Looks like window.Ya blocked with error-on-access scriptlet.');
  715. // Yandex.Metrika callbacks
  716. let yandex_metrika_callbacks = [];
  717. _document.addEventListener(
  718. 'DOMContentLoaded', () => {
  719. yandex_metrika_callbacks.forEach((f) => f && f.call(window));
  720. yandex_metrika_callbacks.length = 0;
  721. yandex_metrika_callbacks.push = (f) => setTimeout(f, 0);
  722. }, false
  723. );
  724. nt.define(win, 'yandex_metrika_callbacks', yandex_metrika_callbacks);
  725. }, nullTools, createStyle);
  726.  
  727. if (!isFirefox) {
  728. // scripts for non-Firefox browsers
  729. // https://greasyfork.org/scripts/14720-it-s-not-important
  730. unimptt: {
  731. // BigInt were implemented in Chrome 67 which also support
  732. // proper user styles and doesn't need this fix anymore.
  733. if ((isChrome || isOpera) && 'BigInt' in win)
  734. break unimptt;
  735.  
  736. let imptt = /((display|(margin|padding)(-top|-bottom)?)\s*:[^;!]*)!\s*important/ig,
  737. ret_b = (a,b) => b,
  738. _toLowerCase = String.prototype.toLowerCase,
  739. protectedNodes = new WeakSet(),
  740. log = false;
  741.  
  742. let logger = function() {
  743. if (log)
  744. _console.log('Some page elements became a bit less important.');
  745. log = false;
  746. };
  747.  
  748. let unimportanter = function(node) {
  749. let style = (node.nodeType === _Node.ELEMENT_NODE) ?
  750. _getAttribute(node, 'style') : null;
  751.  
  752. if (!style || !imptt.test(style) || node.style.display === 'none' ||
  753. (node.src && node.src.startsWith('chrome-extension:'))) // Web of Trust IFRAME and similar
  754. return false; // get out if we have nothing to do here
  755.  
  756. protectedNodes.add(node);
  757. _setAttribute(node, 'style', style.replace(imptt, ret_b));
  758. log = true;
  759. };
  760.  
  761. (new MutationObserver(
  762. function(mutations) {
  763. setTimeout(
  764. function(ms) {
  765. let m, node;
  766. for (m of ms) for (node of m.addedNodes)
  767. unimportanter(node);
  768. logger();
  769. }, 0, mutations
  770. );
  771. }
  772. )).observe(_document, {
  773. childList : true,
  774. subtree : true
  775. });
  776.  
  777. _Element.setAttribute = function setAttribute(name, value) {
  778. '[native code]';
  779. let replaced = value;
  780. if (name && _toLowerCase.call(name) === 'style' && protectedNodes.has(this))
  781. replaced = value.replace(imptt, ret_b);
  782. log = (replaced !== value);
  783. logger();
  784. return _setAttribute(this, ...arguments);
  785. };
  786.  
  787. win.addEventListener (
  788. 'load', () => {
  789. for (let imp of _document.querySelectorAll('[style*="!"]'))
  790. unimportanter(imp);
  791. logger();
  792. }, false
  793. );
  794. }
  795.  
  796. // Naive ABP Style protector
  797. if ('ShadowRoot' in win) {
  798. let _removeChild = Function.prototype.call.bind(_Node.removeChild);
  799. let _appendChild = Function.prototype.call.bind(_Node.appendChild);
  800. let createShadow = () => _createElement('shadow');
  801. // Prevent adding fake content entry point
  802. _Node.appendChild = function appendChild(child) {
  803. if (this instanceof ShadowRoot &&
  804. child instanceof HTMLContentElement)
  805. return _appendChild(this, createShadow());
  806. return _appendChild(this, ...arguments);
  807. };
  808. {
  809. let _shadowSelector = Function.prototype.call.bind(ShadowRoot.prototype.querySelector);
  810. let _innerHTML = Object.getOwnPropertyDescriptor(ShadowRoot.prototype, 'innerHTML');
  811. let _parentNode = Object.getOwnPropertyDescriptor(_Node, 'parentNode');
  812. if (_innerHTML && _parentNode) {
  813. let _set = Function.prototype.call.bind(_innerHTML.set);
  814. let _getParent = Function.prototype.call.bind(_parentNode.get);
  815. _innerHTML.configurable = false;
  816. _innerHTML.set = function() {
  817. _set(this, ...arguments);
  818. let content = _shadowSelector(this, 'content');
  819. if (content) {
  820. let parent = _getParent(content);
  821. _removeChild(parent, content);
  822. _appendChild(parent, createShadow());
  823. }
  824. };
  825. }
  826. Object.defineProperty(ShadowRoot.prototype, 'innerHTML', _innerHTML);
  827. }
  828. // Locate and apply extra protection to a style on top of what ABP does
  829. let style;
  830. (new Promise(
  831. function(resolve, reject) {
  832. let getStyle = () => _querySelector('::shadow style');
  833. style = getStyle();
  834. if (style)
  835. return resolve(style);
  836. let intv = setInterval(
  837. function() {
  838. style = getStyle();
  839. if (!style)
  840. return;
  841. intv = clearInterval(intv);
  842. return resolve(style);
  843. }, 0
  844. );
  845. _document.addEventListener(
  846. 'DOMContentLoaded', () => {
  847. if (intv)
  848. clearInterval(intv);
  849. style = getStyle();
  850. return style ? resolve(style) : reject();
  851. }, false
  852. );
  853. }
  854. )).then(
  855. function(style) {
  856. let emptyArr = [],
  857. nullStr = {
  858. get: () => '',
  859. set: () => undefined
  860. };
  861. let shadow = style.parentNode;
  862. Object.defineProperties(shadow, {
  863. childElementCount: { value: 0 },
  864. styleSheets: { value: emptyArr },
  865. firstChild: { value: null },
  866. firstElementChild: { value: null },
  867. lastChild: { value: null },
  868. lastElementChild: { value: null },
  869. childNodes: { value: emptyArr },
  870. children: { value: emptyArr },
  871. innerHTML: { value: nullStr },
  872. });
  873. Object.defineProperties(style, {
  874. innerHTML: { value: nullStr },
  875. textContent: { value: nullStr },
  876. ownerDocument: { value: null },
  877. parentNode: {value: null },
  878. previousElementSibling: { value: null },
  879. previousSibling: { value: null },
  880. disabled: { get: () => true, set: () => null }
  881. });
  882. Object.defineProperties(style.sheet, {
  883. deleteRule: { value: () => null },
  884. disabled: { get: () => true, set: () => null },
  885. cssRules: { value: emptyArr },
  886. rules: { value: emptyArr }
  887. });
  888. }
  889. ).catch(()=>null);
  890. _Node.removeChild = function removeChild(child) {
  891. if (child === style)
  892. return;
  893. return _removeChild(this, ...arguments);
  894. };
  895. }
  896. }
  897.  
  898. if (/^https?:\/\/(mail\.yandex\.|music\.yandex\.|news\.yandex\.|(www\.)?yandex\.[^/]+\/(yand)?search[/?])/i.test(win.location.href) ||
  899. /^https?:\/\/tv\.yandex\./i.test(win.location.href)) {
  900. // https://greasyfork.org/en/scripts/809-no-yandex-ads
  901. let yadWord = /Яндекс.Директ/i,
  902. adWords = /Реклама|Ad/i;
  903. let _querySelector = _document.querySelector.bind(_document),
  904. _querySelectorAll = _document.querySelectorAll.bind(_document),
  905. _getAttribute = Function.prototype.call.bind(_Element.getAttribute),
  906. _setAttribute = Function.prototype.call.bind(_Element.setAttribute);
  907. // Function to attach an observer to monitor dynamic changes on the page
  908. let pageUpdateObserver = (func, obj, params) => {
  909. if (obj)
  910. (new MutationObserver(func))
  911. .observe(obj, (params || { childList:true, subtree:true }));
  912. };
  913. // Short name for parentNode.removeChild and setAttribute style to display:none
  914. let remove = (node) => {
  915. if (!node || !node.parentNode)
  916. return false;
  917. _console.log('Removed node.');
  918. node.parentNode.removeChild(node);
  919. };
  920. let hide = (node) => {
  921. if (!node)
  922. return false;
  923. _console.log('Hid node.');
  924. _setAttribute(node, 'style', 'display:none!important');
  925. };
  926. // Yandex search ads in Google Chrome
  927. if ('attachShadow' in _Element) {
  928. let _attachShadow = _Element.attachShadow;
  929. _Element.attachShadow = function() {
  930. let node = this,
  931. root = _attachShadow.apply(node, arguments);
  932. pageUpdateObserver(
  933. (ms) => {
  934. for (let m of ms) if (m.addedNodes.length)
  935. if (adWords.test(root.textContent))
  936. remove(node.closest('.serp-item'));
  937. }, root
  938. );
  939. return root;
  940. };
  941. }
  942. // Yandex Mail ads
  943. if (location.hostname.startsWith('mail.')) {
  944. let nt = new nullTools();
  945. let wrap = vl => {
  946. if (!vl)
  947. return vl;
  948. _console.log('Daria =', vl);
  949. nt.define(vl, 'AdBlock', nt.proxy({
  950. detect: nt.func(new Promise(() => null), 'Daria.AdBlock.detect'),
  951. enabled: false
  952. }));
  953. nt.define(vl, 'AdvPresenter', nt.proxy({
  954. _config: nt.proxy({
  955. banner: false,
  956. done: false,
  957. line: true
  958. })
  959. }));
  960. if (vl.Config) {
  961. delete vl.Config.adBlockDetector;
  962. delete vl.Config['adv-url'];
  963. delete vl.Config.cryprox;
  964. if (vl.Config.features) {
  965. delete vl.Config.features.web_adloader_with_cookie_cache;
  966. delete vl.Config.features.web_ads;
  967. delete vl.Config.features.web_ads_mute;
  968. }
  969. vl.Config.mayHaveAdv = false;
  970. }
  971. return vl;
  972. };
  973. let _Daria = wrap(win.Daria);
  974. if (_Daria)
  975. _console.log('Wrapped already existing object "Daria".');
  976. Object.defineProperty(win, 'Daria', {
  977. get: () => _Daria,
  978. set: vl => {
  979. if (vl === _Daria)
  980. return;
  981. _Daria = wrap(vl);
  982. }
  983. });
  984. }
  985. // prevent/defuse adblock detector
  986. setInterval(() => {
  987. localStorage.ic = '';
  988. localStorage._mt__data = '';
  989. }, 100);
  990. let yp_keepCookieParts = /\.(sp|ygo|ygu)\./; // ygo = city id; ygu = detect city automatically
  991. let _doc_proto = ('cookie' in _Document) ? _Document : Object.getPrototypeOf(_document);
  992. let _cookie = Object.getOwnPropertyDescriptor(_doc_proto, 'cookie');
  993. if (_cookie) {
  994. let _set_cookie = Function.prototype.call.bind(_cookie.set);
  995. _cookie.set = function(value) {
  996. if (/^(mda=|yp=|ys=|yabs-|__|bltsr=)/.test(value))
  997. // remove value, set expired
  998. if (!value.startsWith('yp=')) {
  999. value = value.replace(/^([^=]+=)[^;]+/,'$1').replace(/(expires=)[\w\s\d,]+/,'$1Thu, 01 Jan 1970 00');
  1000. _console.log('expire cookie', value.match(/^[^=]+/)[0]);
  1001. } else {
  1002. let parts = value.split(';');
  1003. let values = parts[0].split('#').filter(part => yp_keepCookieParts.test(part));
  1004. if (values.length)
  1005. values[0] = values[0].replace(/^yp=/, '');
  1006. let res = `yp=${values.join('#')}`;
  1007. _console.log(`set cookie ${res}, dropped ${parts[0].replace(res,'')}`);
  1008. parts[0] = res;
  1009. value = parts.join(';');
  1010. }
  1011. return _set_cookie(this, value);
  1012. };
  1013. Object.defineProperty(_doc_proto, 'cookie', _cookie);
  1014. }
  1015. // other ads
  1016. _document.addEventListener(
  1017. 'DOMContentLoaded', () => {
  1018.  
  1019. {
  1020. // Generic ads removal and fixes
  1021. let node = _querySelector('.serp-header');
  1022. if (node)
  1023. node.style.marginTop = '0';
  1024. for (node of _querySelectorAll(
  1025. '.serp-adv__head + .serp-item,'+
  1026. '#adbanner,'+
  1027. '.serp-adv,'+
  1028. '.b-spec-adv,'+
  1029. 'div[class*="serp-adv__"]:not(.serp-adv__found):not(.serp-adv__displayed)'
  1030. )) remove(node);
  1031. }
  1032. // Search ads
  1033. function removeSearchAds() {
  1034. for (let node of _querySelectorAll('.serp-item'))
  1035. if (_getAttribute(node, 'role') === 'complementary' ||
  1036. adWords.test((node.querySelector('.label')||{}).textContent))
  1037. hide(node);
  1038. }
  1039. // News ads
  1040. function removeNewsAds() {
  1041. let node, block, items, mask, classes,
  1042. masks = [
  1043. { class: '.ads__wrapper', regex: /[^,]*?,[^,]*?\.ads__wrapper/ },
  1044. { class: '.ads__pool', regex: /[^,]*?,[^,]*?\.ads__pool/ }
  1045. ];
  1046. for (node of _querySelectorAll('style[nonce]')) {
  1047. classes = node.innerText.replace(/\{[^}]+\}+/ig, '|').split('|');
  1048. for (block of classes) for (mask of masks)
  1049. if (block.includes(mask.class)) {
  1050. block = block.match(mask.regex)[0];
  1051. items = _querySelectorAll(block);
  1052. for (item of items)
  1053. remove(items[0]);
  1054. }
  1055. }
  1056. }
  1057. // Music ads
  1058. function removeMusicAds() {
  1059. for (let node of _querySelectorAll('.ads-block'))
  1060. remove(node);
  1061. }
  1062. // News fixes
  1063. function removePageAdsClass() {
  1064. if (_document.body.classList.contains("b-page_ads_yes")) {
  1065. _document.body.classList.remove("b-page_ads_yes");
  1066. _console.log('Page ads class removed.');
  1067. }
  1068. }
  1069. // TV fixes
  1070. function removeTVAds() {
  1071. for (let node of _querySelectorAll('div[class^="_"][data-reactid] > div'))
  1072. if (yadWord.test(node.textContent) || node.querySelector('iframe:not([src])')) {
  1073. if (node.offsetWidth) {
  1074. let pad = _document.createElement('div');
  1075. _setAttribute(pad, 'style', `width:${node.offsetWidth}px`);
  1076. node.parentNode.appendChild(pad);
  1077. }
  1078. remove(node);
  1079. }
  1080. }
  1081.  
  1082. if (location.hostname.startsWith('music.')) {
  1083. pageUpdateObserver(removeMusicAds, _querySelector('.sidebar'));
  1084. removeMusicAds();
  1085. } else if (location.hostname.startsWith('news.')) {
  1086. pageUpdateObserver(removeNewsAds, _document.body);
  1087. pageUpdateObserver(removePageAdsClass, _document.body, { attributes:true, attributesFilter:['class'] });
  1088. removeNewsAds();
  1089. removePageAdsClass();
  1090. } else if (location.hostname.startsWith('tv.')) {
  1091. pageUpdateObserver(removeTVAds, _document.body);
  1092. removeTVAds();
  1093. } else if (!location.hostname.startsWith('mail.')) {
  1094. pageUpdateObserver(removeSearchAds, _querySelector('.main__content'));
  1095. removeSearchAds();
  1096. }
  1097. }
  1098. );
  1099. }
  1100.  
  1101. // Generic Yandex Scripts
  1102. if (/^https?:\/\/([^.]+\.)*yandex\.[^/]+/i.test(win.location.href)) {
  1103. // remove banner on the start page
  1104. selectiveCookies();
  1105. scriptLander(() => {
  1106. let nt = new nullTools({log: false, trace: true});
  1107. let AwapsJsonAPI_Json = function(...args) {
  1108. _console.log('>> new AwapsJsonAPI.Json(', ...args, ')');
  1109. };
  1110. [
  1111. 'setID', 'addImageContent', 'sendCounts',
  1112. 'drawBanner', 'bannerIsInvisible', 'expand', 'refreshAd'
  1113. ].forEach(name => void(AwapsJsonAPI_Json.prototype[name] = nt.func(null, `AwapsJsonAPI.Json.${name}`)));
  1114. AwapsJsonAPI_Json.prototype.checkBannerVisibility = nt.func(true, 'AwapsJsonAPI.Json.checkBannerVisibility');
  1115. AwapsJsonAPI_Json.prototype.addIframeContent = nt.proxy(function(...args) {
  1116. try {
  1117. let frame = args[1][0].parentNode;
  1118. frame.parentNode.removeChild(frame);
  1119. _console.log(`Removed banner placeholder.`);
  1120. } catch(ignore) {
  1121. _console.log(`Can't locate frame object to remove.`);
  1122. }
  1123. });
  1124. AwapsJsonAPI_Json.prototype.getHTML = nt.func('', 'AwapsJsonAPI.Json.getHTML');
  1125. AwapsJsonAPI_Json.prototype = nt.proxy(AwapsJsonAPI_Json.prototype);
  1126. AwapsJsonAPI_Json = nt.proxy(AwapsJsonAPI_Json);
  1127. if ('AwapsJsonAPI' in win) {
  1128. _console.log('Oops! AwapsJsonAPI already defined.');
  1129. let f = win.AwapsJsonAPI.Json;
  1130. win.AwapsJsonAPI.Json = AwapsJsonAPI_Json;
  1131. if (f && f.prototype)
  1132. f.prototype = AwapsJsonAPI_Json.prototype;
  1133. } else
  1134. nt.define(win, 'AwapsJsonAPI', nt.proxy({
  1135. Json: AwapsJsonAPI_Json
  1136. }));
  1137.  
  1138. let parseExport = x => {
  1139. if (!x)
  1140. return x;
  1141. // remove banner placeholder
  1142. if (x.banner && x.banner.cls) {
  1143. let _parent = `.${x.banner.cls.banner__parent}`;
  1144. _document.addEventListener('DOMContentLoaded', () => {
  1145. for (let banner of _document.querySelectorAll(_parent)) {
  1146. _setAttribute(banner, 'style', 'display:none!important');
  1147. _console.log('Hid banner placeholder.');
  1148. }
  1149. }, false);
  1150. }
  1151.  
  1152. // remove banner data and some other stuff
  1153. delete x.banner;
  1154. delete x.consistency;
  1155. delete x['i-bannerid'];
  1156. delete x['i-counter'];
  1157. delete x['promo-curtain'];
  1158.  
  1159. // remove parts of ga-counter (complete removal break "ТВ Онлайн")
  1160. if (x['ga-counter'] && x['ga-counter'].data) {
  1161. x['ga-counter'].data.id = 0;
  1162. delete x['ga-counter'].data.ether;
  1163. delete x['ga-counter'].data.iframeSrc;
  1164. delete x['ga-counter'].data.iframeSrcEx;
  1165. }
  1166.  
  1167. return x;
  1168. };
  1169. // Yandex banner on main page and some other things
  1170. let _home = win.home,
  1171. _home_set = !!_home;
  1172. Object.defineProperty(win, 'home', {
  1173. get: () => _home,
  1174. set: vl => {
  1175. if (!_home_set && vl === _home)
  1176. return;
  1177. _home_set = false;
  1178. _console.log('home =', vl);
  1179. let _home_export = parseExport(vl.export);
  1180. Object.defineProperty(vl, 'export', {
  1181. get: () => _home_export,
  1182. set: vl => {
  1183. _home_export = parseExport(vl);
  1184. }
  1185. });
  1186. _home = vl;
  1187. }
  1188. });
  1189. // adblock circumvention on some Yandex domains (weather in particular)
  1190. nt.define(win, 'Raven', nt.proxy({
  1191. context: f => f(),
  1192. config: nt.func(nt.proxy({}, 'Raven.config()', null), 'Raven.config')
  1193. }, 'Raven', null));
  1194. }, nullTools, selectiveCookies, 'let _setAttribute = Function.prototype.call.bind(_Element.setAttribute)');
  1195.  
  1196. if ('attachShadow' in _Element) {
  1197. let fakeRoot = () => ({
  1198. firstChild: null,
  1199. appendChild: () => null,
  1200. querySelector: () => null,
  1201. querySelectorAll: () => null
  1202. });
  1203. _Element.createShadowRoot = fakeRoot;
  1204. let shadows = new WeakMap();
  1205. let _attachShadow = Object.getOwnPropertyDescriptor(_Element, 'attachShadow');
  1206. _attachShadow.value = function() {
  1207. return shadows.set(this, fakeRoot()).get(this);
  1208. };
  1209. Object.defineProperty(_Element, 'attachShadow', _attachShadow);
  1210. let _shadowRoot = Object.getOwnPropertyDescriptor(_Element, 'shadowRoot');
  1211. _shadowRoot.set = () => null;
  1212. _shadowRoot.get = function() {
  1213. return shadows.has(this) ? shadows.get(this) : void 0;
  1214. };
  1215. Object.defineProperty(_Element, 'shadowRoot', _shadowRoot);
  1216. }
  1217.  
  1218. // Disable banner styleSheet (on main page)
  1219. document.addEventListener('DOMContentLoaded', () => {
  1220. for (let sheet of document.styleSheets)
  1221. try {
  1222. for (let rule of sheet.cssRules)
  1223. if (rule.cssText.includes(' 728px 90px')) {
  1224. rule.parentStyleSheet.disabled = true;
  1225. _console.log('Disabled banner styleSheet:', rule.parentStyleSheet);
  1226. }
  1227. } catch(ignore) {}
  1228. }, false);
  1229.  
  1230. // Partially based on https://greasyfork.org/en/scripts/22737-remove-yandex-redirect
  1231. let selectors = (
  1232. 'A[onmousedown*="/jsredir"],'+
  1233. 'A[data-vdir-href],'+
  1234. 'A[data-counter]'
  1235. );
  1236. let removeTrackingAttributes = function(link) {
  1237. link.removeAttribute('onmousedown');
  1238. if (link.hasAttribute('data-vdir-href')) {
  1239. link.removeAttribute('data-vdir-href');
  1240. link.removeAttribute('data-orig-href');
  1241. }
  1242. if (link.hasAttribute('data-counter')) {
  1243. link.removeAttribute('data-counter');
  1244. link.removeAttribute('data-bem');
  1245. }
  1246. };
  1247. let removeTracking = function(scope) {
  1248. if (scope instanceof Element)
  1249. for (let link of scope.querySelectorAll(selectors))
  1250. removeTrackingAttributes(link);
  1251. };
  1252. _document.addEventListener('DOMContentLoaded', (e) => removeTracking(e.target));
  1253. (new MutationObserver(
  1254. function(ms) {
  1255. let m, node;
  1256. for (m of ms) for (node of m.addedNodes)
  1257. if (node instanceof HTMLAnchorElement && node.matches(selectors))
  1258. removeTrackingAttributes(node);
  1259. else
  1260. removeTracking(node);
  1261. }
  1262. )).observe(_de, { childList: true, subtree: true });
  1263. }
  1264.  
  1265. // https://greasyfork.org/en/scripts/21937-moonwalk-hdgo-kodik-fix v0.8 (adapted)
  1266. _document.addEventListener(
  1267. 'DOMContentLoaded', function() {
  1268. let log = name => _console.log(`Player FIX: Detected ${name} player in ${location.href}`);
  1269. function removeVast (data) {
  1270. if (data && typeof data === 'object') {
  1271. let keys = Object.getOwnPropertyNames(data);
  1272. let isVast = name => /vast|clickunder/.test(name);
  1273. if (!keys.some(isVast))
  1274. return data;
  1275. for (let key of keys)
  1276. if (key !== 'chain') {
  1277. _console.log(`Removed data.${key}`, data[key]);
  1278. delete data[key];
  1279. }
  1280. if (data.chain) {
  1281. let need = [],
  1282. drop = [],
  1283. links = data.chain.split('.');
  1284. for (let link of links)
  1285. if (!isVast(link))
  1286. need.push(link);
  1287. else
  1288. drop.push(link);
  1289. _console.log('Dropped from the chain:', ...drop);
  1290. data.chain = need.join('.');
  1291. }
  1292. }
  1293. return data;
  1294. }
  1295.  
  1296. if ('video_balancer_options' in win && 'event_callback' in win) {
  1297. log('Moonwalk');
  1298. if (video_balancer_options.adv)
  1299. removeVast(video_balancer_options.adv);
  1300. if ('_mw_adb' in win)
  1301. Object.defineProperty(win, '_mw_adb', {
  1302. get: () => false,
  1303. set: () => true
  1304. });
  1305. } else if (win.startKodikPlayer !== void 0) {
  1306. log('Kodik');
  1307. // skip attempt to block access to HD resolutions
  1308. let chainCall = new Proxy({}, { get: () => () => chainCall });
  1309. if ($ && $.prototype && $.prototype.addClass) {
  1310. let $addClass = $.prototype.addClass;
  1311. $.prototype.addClass = function (className) {
  1312. if (className === 'blocked')
  1313. return chainCall;
  1314. return $addClass.apply(this, arguments);
  1315. };
  1316. }
  1317. // remove ad links from the metadata
  1318. let _ajax = win.$.ajax;
  1319. win.$.ajax = (params, ...args) => {
  1320. if (params.success) {
  1321. let _s = params.success;
  1322. params.success = (data, ...args) => _s(removeVast(data), ...args);
  1323. }
  1324. return _ajax(params, ...args);
  1325. }
  1326. } else if (win.getnextepisode && win.uppodEvent) {
  1327. log('Share-Serials.net');
  1328. scriptLander(
  1329. function() {
  1330. let _setInterval = win.setInterval,
  1331. _setTimeout = win.setTimeout,
  1332. _toString = Function.prototype.call.bind(Function.prototype.toString);
  1333. win.setInterval = function(func) {
  1334. if (func instanceof Function && _toString(func).includes('_delay')) {
  1335. let intv = _setInterval.call(
  1336. this, function() {
  1337. _setTimeout.call(
  1338. this, function(intv) {
  1339. clearInterval(intv);
  1340. let timer = _document.querySelector('#timer');
  1341. if (timer)
  1342. timer.click();
  1343. }, 100, intv);
  1344. func.call(this);
  1345. }, 5
  1346. );
  1347.  
  1348. return intv;
  1349. }
  1350. return _setInterval.apply(this, arguments);
  1351. };
  1352. win.setTimeout = function(func) {
  1353. if (func instanceof Function && _toString(func).includes('adv_showed'))
  1354. return _setTimeout.call(this, func, 0);
  1355. return _setTimeout.apply(this, arguments);
  1356. };
  1357. }
  1358. );
  1359. } else if ('ADC' in win) {
  1360. log('vjs-creatives plugin in');
  1361. let replacer = (obj) => {
  1362. for (let name in obj)
  1363. if (obj[name] instanceof Function)
  1364. obj[name] = () => null;
  1365. };
  1366. replacer(win.ADC);
  1367. replacer(win.currentAdSlot);
  1368. }
  1369. UberVK: {
  1370. if (!inIFrame)
  1371. break UberVK;
  1372. let oddNames = 'HD' in win &&
  1373. !Object.getOwnPropertyNames(win).every(n => !n.startsWith('_0x'));
  1374. if (!oddNames)
  1375. break UberVK;
  1376. log('UberVK');
  1377. XMLHttpRequest.prototype.open = () => {
  1378. throw 404;
  1379. };
  1380. }
  1381. }, false
  1382. );
  1383.  
  1384. // Applies wrapper function on the current page and all newly created same-origin iframes
  1385. // This is used to prevent trick which allows to get fresh page API through newly created same-origin iframes
  1386. function deepWrapAPI(wrapper) {
  1387. let wrapped = new WeakSet(),
  1388. _get_contentWindow = () => null,
  1389. log = (...args) => false && _console.log(...args);
  1390. let wrapAPI = root => {
  1391. if (!root || wrapped.has(root))
  1392. return;
  1393. wrapped.add(root);
  1394. try {
  1395. wrapper(root instanceof HTMLIFrameElement ? _get_contentWindow(root) : root);
  1396. log('Wrapped API in', (root === win) ? "main window." : root);
  1397. } catch(e) {
  1398. log('Failed to wrap API in', (root === win) ? "main window." : root, '\n', e);
  1399. }
  1400. };
  1401.  
  1402. // wrap API on contentWindow access
  1403. let _apply = Function.prototype.apply;
  1404. let _contentWindow = Object.getOwnPropertyDescriptor(HTMLIFrameElement.prototype, 'contentWindow');
  1405. _get_contentWindow = _apply.bind(_contentWindow.get);
  1406. _contentWindow.get = function() {
  1407. wrapAPI(this);
  1408. return _get_contentWindow(this);;
  1409. };
  1410. Object.defineProperty(HTMLIFrameElement.prototype, 'contentWindow', _contentWindow);
  1411.  
  1412. // wrap API on contentDocument access
  1413. let _contentDocument = Object.getOwnPropertyDescriptor(HTMLIFrameElement.prototype, 'contentDocument');
  1414. let _get_contentDocument = _apply.bind(_contentDocument.get);
  1415. _contentDocument.get = function() {
  1416. wrapAPI(this);
  1417. return _get_contentDocument(this);
  1418. };
  1419. Object.defineProperty(HTMLIFrameElement.prototype, 'contentDocument', _contentDocument);
  1420.  
  1421. // manual children objects traverser to avoid issues
  1422. // with calling querySelectorAll on wrong types of objects
  1423. let _nodeType = _apply.bind(Object.getOwnPropertyDescriptor(_Node, 'nodeType').get);
  1424. let _childNodes = _apply.bind(Object.getOwnPropertyDescriptor(_Node, 'childNodes').get);
  1425. let _ELEMENT_NODE = _Node.ELEMENT_NODE;
  1426. let _DOCUMENT_FRAGMENT_NODE = _Node.DOCUMENT_FRAGMENT_NODE
  1427. let wrapFrames = root => {
  1428. if (_nodeType(root) !== _ELEMENT_NODE && _nodeType(root) !== _DOCUMENT_FRAGMENT_NODE)
  1429. return; // only process nodes which may contain an IFRAME or be one
  1430. if (root instanceof HTMLIFrameElement) {
  1431. wrapAPI(root);
  1432. return;
  1433. }
  1434. for (let child of _childNodes(root))
  1435. wrapFrames(child);
  1436. };
  1437.  
  1438. // wrap API in a newly appended iframe objects
  1439. let _appendChild = _apply.bind(Node.prototype.appendChild);
  1440. Node.prototype.appendChild = function appendChild() {
  1441. '[native code]';
  1442. let res = _appendChild(this, arguments);
  1443. wrapFrames(arguments[0]);
  1444. return res;
  1445. };
  1446.  
  1447. // wrap API in iframe objects created with innerHTML of element on page
  1448. let _innerHTML = Object.getOwnPropertyDescriptor(_Element, 'innerHTML');
  1449. let _set_innerHTML = _apply.bind(_innerHTML.set);
  1450. _innerHTML.set = function() {
  1451. _set_innerHTML(this, arguments);
  1452. if (_document.contains(this))
  1453. wrapFrames(this);
  1454. };
  1455. Object.defineProperty(_Element, 'innerHTML', _innerHTML);
  1456.  
  1457. wrapAPI(win);
  1458. }
  1459.  
  1460. // piguiqproxy.com / zmctrack.net circumvention and onerror callback prevention
  1461. scriptLander(
  1462. () => {
  1463. // onerror callback blacklist
  1464. let masks = [],
  1465. //blockAll = /(^|\.)(rutracker-org\.appspot\.com)$/,
  1466. isBlocked = url => masks.some(mask => mask.test(url));// || blockAll.test(location.hostname);
  1467. for (let filter of [// blacklist
  1468. // global
  1469. '/adv/www/',
  1470. // adservers
  1471. '||185.87.50.147^',
  1472. '||10root25.website^', '||24video.xxx^',
  1473. '||adlabs.ru^', '||adspayformymortgage.win^', '||amgload.net^', '||aviabay.ru^',
  1474. '||bgrndi.com^', '||brokeloy.com^',
  1475. '||cdnjs-aws.ru^','||cnamerutor.ru^',
  1476. '||directadvert.ru^', '||dsn-fishki.ru^', '||docfilms.info^', '||dreadfula.ru^',
  1477. '||et-cod.com^', '||et-code.ru^', '||etcodes.com^',
  1478. '||franecki.net^', '||film-doma.ru^',
  1479. '||free-torrent.org^', '||free-torrent.pw^',
  1480. '||free-torrents.org^', '||free-torrents.pw^',
  1481. '||game-torrent.info^', '||gocdn.ru^',
  1482. '||hdkinoshka.com^', '||hghit.com^', '||hindcine.net^',
  1483. '||kinotochka.net^', '||kinott.com^', '||kinott.ru^',
  1484. '||klcheck.com^', '||kuveres.com^',
  1485. '||lepubs.com^', '||luxadv.com^', '||luxup.ru^', '||luxupcdna.com^',
  1486. '||marketgid.com^', '||mebablo.com^', '||mixadvert.com^', '||mxtads.com^',
  1487. '||nickhel.com^',
  1488. '||oconner.biz^', '||oconner.link^', '||octoclick.net^', '||octozoon.org^',
  1489. '||piguiqproxy.com^', '||pkpojhc.com^',
  1490. '||psma01.com^', '||psma02.com^', '||psma03.com^',
  1491. '||rcdn.pro^', '||recreativ.ru^', '||redtram.com^', '||regpole.com^',
  1492. '||rootmedia.ws^', '||ruttwind.com^', '||rutvind.com^',
  1493. '||skidl.ru^', '||smi2.net^', '||smcheck.org^',
  1494. '||torvind.com^', '||traffic-media.co^', '||trafmag.com^', '||trustjs.net^', '||ttarget.ru^',
  1495. '||u-dot-id-adtool.appspot.com^', '||utarget.ru^',
  1496. '||webadvert-gid.ru^', '||webadvertgid.ru^',
  1497. '||xxuhter.ru^',
  1498. '||yuiout.online^',
  1499. '||zmctrack.net^', '||zoom-film.ru^'])
  1500. masks.push(new RegExp(
  1501. filter.replace(/([\\/[\].+?(){}$])/g, '\\$1')
  1502. .replace(/\*/g, '.*?')
  1503. .replace(/\^(?!$)/g,'\\.?[^\\w%._-]')
  1504. .replace(/\^$/,'\\.?([^\\w%._-]|$)')
  1505. .replace(/^\|\|/,'^(ws|http)s?:\\/+([^/.]+\\.)*?'),
  1506. 'i'));
  1507. // main script
  1508. deepWrapAPI(root => {
  1509. let _call = root.Function.prototype.call,
  1510. _defineProperty = root.Object.defineProperty,
  1511. _getOwnPropertyDescriptor = root.Object.getOwnPropertyDescriptor;
  1512. onerror: {
  1513. // 'onerror' handler for scripts from blacklisted sources
  1514. let scriptMap = new WeakMap();
  1515. let _Reflect_apply = root.Reflect.apply,
  1516. _HTMLScriptElement = root.HTMLScriptElement,
  1517. _HTMLImageElement = root.HTMLImageElement;
  1518. let _get_tagName = _call.bind(_getOwnPropertyDescriptor(root.Element.prototype, 'tagName').get),
  1519. _get_scr_src = _call.bind(_getOwnPropertyDescriptor(_HTMLScriptElement.prototype, 'src').get),
  1520. _get_img_src = _call.bind(_getOwnPropertyDescriptor(_HTMLImageElement.prototype, 'src').get);
  1521. let _get_src = node => {
  1522. if (node instanceof _HTMLScriptElement)
  1523. return _get_scr_src(node);
  1524. if (node instanceof _HTMLImageElement)
  1525. return _get_img_src(node);
  1526. return void 0
  1527. };
  1528. let _onerror = _getOwnPropertyDescriptor(root.HTMLElement.prototype, 'onerror'),
  1529. _set_onerror = _call.bind(_onerror.set);
  1530. _onerror.get = function() {
  1531. return scriptMap.get(this) || null;
  1532. };
  1533. _onerror.set = function(callback) {
  1534. if (typeof callback !== 'function') {
  1535. scriptMap.delete(this);
  1536. _set_onerror(this, callback);
  1537. return;
  1538. }
  1539. scriptMap.set(this, callback);
  1540. _set_onerror(this, function() {
  1541. let src = _get_src(this);
  1542. if (isBlocked(src)) {
  1543. _console.warn(`Blocked "onerror" callback from ${_get_tagName(this)}: ${src}`);
  1544. return;
  1545. }
  1546. _Reflect_apply(scriptMap.get(this), this, arguments);
  1547. });
  1548. };
  1549. _defineProperty(root.HTMLElement.prototype, 'onerror', _onerror);
  1550. }
  1551. // Simplistic WebSocket wrapper for Maxthon and Firefox before v58
  1552. WSWrap: { // once again seems required in Google Chrome and similar browsers due to zmctrack.net -_-
  1553. if (true /*/Maxthon/.test(navigator.appVersion) ||
  1554. 'InstallTrigger' in win && 'StopIteration' in win*/) {
  1555. let _ws = _getOwnPropertyDescriptor(root, 'WebSocket');
  1556. if (!_ws)
  1557. break WSWrap;
  1558. _ws.value = new Proxy(_ws.value, {
  1559. construct: (ws, args) => {
  1560. if (isBlocked(args[0])) {
  1561. _console.log('Blocked WS connection:', args[0]);
  1562. return {};
  1563. }
  1564. return new ws(...args);
  1565. }
  1566. });
  1567. _defineProperty(root, 'WebSocket', _ws);
  1568. }
  1569. }
  1570. untrustedClick: {
  1571. // Block popular method to open a new window in Google Chrome by dispatching a custom click
  1572. // event on a newly created anchor with _blank target. Untrusted events must not open new windows.
  1573. let _dispatchEvent = _call.bind(root.EventTarget.prototype.dispatchEvent);
  1574. root.EventTarget.prototype.dispatchEvent = function dispatchEvent(e) {
  1575. if (!e.isTrusted && e.type === 'click' && e.constructor.name === 'MouseEvent' &&
  1576. !this.parentNode && this.tagName === 'A' && this.target[0] === '_') {
  1577. _console.log('Blocked dispatching a click event on a parentless anchor:', this);
  1578. return;
  1579. }
  1580. return _dispatchEvent(this, ...arguments);
  1581. };
  1582. }
  1583. // XHR Wrapper
  1584. let _proto = void 0;
  1585. try {
  1586. _proto = root.XMLHttpRequest.prototype;
  1587. } catch(ignore) {
  1588. return;
  1589. };
  1590. // blacklist of domains where all third-party requests are ignored
  1591. let ondomains = /(^|[/.@])oane\.ws($|[:/])/i;
  1592. // highly suspicious URLs
  1593. let suspicious = /^(https?:)?\/\/(csp-)?([a-z0-9]{6}){1,2}\.ru\//i;
  1594. let on_get_ban = /^(https?:)?\/\/(csp-)?([a-z0-9]{6}){1,2}\.ru\/([a-z0-9/]{40,}|[a-z0-9]{8,}|ad\/banner\/.+|show\/\?\d+=\d+&.+)$/i;
  1595. let on_post_ban = /^(https?:)?\/\/(csp-)?([a-z0-9]{6}){1,2}\.ru\/([a-z0-9]{6,})$/i;
  1596. let yandex_direct = /^(https?:)?\/\/([^.]+\.)??yandex(\.[a-z]{2,3}){1,2}\/((images|weather)\/[a-z0-9/_-]{40,}|jstracer?|j?clck\/.*|set\/s\/rsya-tag-users\/data(\?.*)?|static\/main\.js(\?.*)?)$/i;
  1597. let more_y_direct = /^(https?:)?\/\/([^.]+\.)??(24smi\.org|(echo\.msk|kakprosto|liveinternet|razlozhi)\.ru)\/(.{290,}|[a-z0-9/_-]{100,})$/i;
  1598. let whitelist = /^(https?:)?\/\/yandex\.ru\/yobject$/;
  1599. let fabPatterns = /\/fuckadblock/i;
  1600.  
  1601. let blockedUrls = new Set();
  1602. function checkRequest(fname, method, url) {
  1603. if ((isBlocked(url) ||
  1604. ondomains.test(location.hostname) && !ondomains.test(url) ||
  1605. method !== 'POST' && on_get_ban.test(url) ||
  1606. method === 'POST' && on_post_ban.test(url) ||
  1607. yandex_direct.test(url) || more_y_direct.test(url)) && !whitelist.test(url)) {
  1608. if (!blockedUrls.has(url)) // don't repeat log if the same URL were blocked more than once
  1609. _console.warn(`Blocked ${fname} ${method} request:`, url);
  1610. blockedUrls.add(url);
  1611. return true;
  1612. }
  1613. if (suspicious.test(url))
  1614. _console.warn(`Suspicious ${fname} ${method} request:`, url);
  1615. return false;
  1616. }
  1617.  
  1618. // workaround for a broken weather mini-map on Yandex
  1619. let skip_xhr_check = false;
  1620. if (root.location.hostname.startsWith('yandex.') &&
  1621. root.location.pathname.startsWith('/pogoda/') ||
  1622. root.location.hostname.endsWith('.kakprosto.ru'))
  1623. skip_xhr_check = true;
  1624.  
  1625. let xhrStopList = new WeakSet();
  1626. let _open = root.Function.prototype.apply.bind(_proto.open);
  1627. _proto.open = function open() {
  1628. '[native code]';
  1629. return !skip_xhr_check && checkRequest('xhr', ...arguments) ?
  1630. (xhrStopList.add(this), void 0) : _open(this, arguments);
  1631. };
  1632. ['send', 'setRequestHeader', 'getAllResponseHeaders'].forEach(
  1633. name => {
  1634. let func = _proto[name];
  1635. _proto[name] = function(...args) {
  1636. return xhrStopList.has(this) ? null : func.apply(this, args);
  1637. };
  1638. }
  1639. );
  1640. // simulate readyState === 1 for blocked requests
  1641. let _readyState = Object.getOwnPropertyDescriptor(_proto, 'readyState');
  1642. let _get_readyState = root.Function.prototype.apply.bind(_readyState.get);
  1643. _readyState.get = function() {
  1644. return xhrStopList.has(this) ? 1 : _get_readyState(this, arguments);
  1645. }
  1646. Object.defineProperty(_proto, 'readyState', _readyState);
  1647.  
  1648. let _fetch = root.Function.prototype.apply.bind(root.fetch);
  1649. root.fetch = function fetch() {
  1650. '[native code]';
  1651. let url = arguments[0];
  1652. let method = arguments[1] ? arguments[1].method : void 0;
  1653. if (arguments[0] instanceof Request) {
  1654. method = url.method;
  1655. url = url.url;
  1656. }
  1657. if (checkRequest('fetch', method, url))
  1658. return new Promise(() => null);
  1659. return _fetch(root, arguments);
  1660. };
  1661.  
  1662. let _script_src = Object.getOwnPropertyDescriptor(root.HTMLScriptElement.prototype, 'src');
  1663. let _script_src_set = root.Function.prototype.apply.bind(_script_src.set);
  1664. _script_src.set = function(src) {
  1665. if (fabPatterns.test(src)) {
  1666. deployFAB();
  1667. setTimeout(() => this.onload(), 10);
  1668. return;
  1669. }
  1670. return checkRequest('set', 'script.src', src) || _script_src_set(this, arguments);
  1671. };
  1672. Object.defineProperty(root.HTMLScriptElement.prototype, 'src', _script_src);
  1673. });
  1674.  
  1675. win.stop = () => {
  1676. _console.warn('window.stop() ...y tho?');
  1677. for (let sheet of _document.styleSheets)
  1678. if (sheet.disabled) {
  1679. sheet.disabled = false;
  1680. _console.log('Re-enabled:', sheet);
  1681. }
  1682. }
  1683. }, deepWrapAPI
  1684. );
  1685.  
  1686. // === Helper functions ===
  1687.  
  1688. // function to search and remove nodes by content
  1689. // selector - standard CSS selector to define set of nodes to check
  1690. // words - regular expression to check content of the suspicious nodes
  1691. // params - object with multiple extra parameters:
  1692. // .log - display log in the console
  1693. // .hide - set display to none instead of removing from the page
  1694. // .parent - parent node to remove if content is found in the child node
  1695. // .siblings - number of simling nodes to remove (excluding text nodes)
  1696. let scRemove = (node) => node.parentNode.removeChild(node);
  1697. let scHide = function(node) {
  1698. let style = _getAttribute(node, 'style') || '',
  1699. hide = ';display:none!important;';
  1700. if (style.indexOf(hide) < 0)
  1701. _setAttribute(node, 'style', style + hide);
  1702. };
  1703.  
  1704. function scissors (selector, words, scope, params) {
  1705. let logger = (...args) => { if (params.log) _console.log(...args) };
  1706. if (!scope.contains(_document.body))
  1707. logger('[s] scope', scope);
  1708. let remFunc = (params.hide ? scHide : scRemove),
  1709. iterFunc = (params.siblings > 0 ? 'nextElementSibling' : 'previousElementSibling'),
  1710. toRemove = [],
  1711. siblings;
  1712. for (let node of scope.querySelectorAll(selector)) {
  1713. // drill up to a parent node if specified, break if not found
  1714. if (params.parent) {
  1715. let old = node;
  1716. node = node.closest(params.parent);
  1717. if (node === null || node.contains(scope)) {
  1718. logger('[s] went out of scope with', old);
  1719. continue;
  1720. }
  1721. }
  1722. logger('[s] processing', node);
  1723. if (toRemove.includes(node))
  1724. continue;
  1725. if (words.test(node.innerHTML)) {
  1726. // skip node if already marked for removal
  1727. logger('[s] marked for removal');
  1728. toRemove.push(node);
  1729. // add multiple nodes if defined more than one sibling
  1730. siblings = Math.abs(params.siblings) || 0;
  1731. while (siblings) {
  1732. node = node[iterFunc];
  1733. if (!node) break; // can't go any further - exit
  1734. logger('[s] adding sibling node', node);
  1735. toRemove.push(node);
  1736. siblings -= 1;
  1737. }
  1738. }
  1739. }
  1740. let toSkip = [];
  1741. for (let node of toRemove)
  1742. if (!toRemove.every(other => other === node || !node.contains(other)))
  1743. toSkip.push(node);
  1744. if (toRemove.length)
  1745. logger(`[s] proceeding with ${params.hide?'hide':'removal'} of`, toRemove, `skip`, toSkip);
  1746. for (let node of toRemove) if (!toSkip.includes(node))
  1747. remFunc(node);
  1748. }
  1749.  
  1750. // function to perform multiple checks if ads inserted with a delay
  1751. // by default does 30 checks withing a 3 seconds unless nonstop mode specified
  1752. // also does 1 extra check when a page completely loads
  1753. // selector and words - passed dow to scissors
  1754. // params - object with multiple extra parameters:
  1755. // .log - display log in the console
  1756. // .root - selector to narrow down scope to scan;
  1757. // .observe - if true then check will be performed continuously;
  1758. // Other parameters passed down to scissors.
  1759. function gardener(selector, words, params) {
  1760. let logger = (...args) => { if (params.log) _console.log(...args) };
  1761. params = params || {};
  1762. logger(`[gardener] selector: '${selector}' detector: ${words} options: ${JSON.stringify(params)}`);
  1763. let scope;
  1764. let globalScope = [_de];
  1765. let domLoaded = false;
  1766. let getScope = root => root ? _de.querySelectorAll(root) : globalScope;
  1767. let onevent = e => {
  1768. logger(`[gardener] cleanup on ${Object.getPrototypeOf(e)} "${e.type}"`);
  1769. for (let node of scope)
  1770. scissors(selector, words, node, params);
  1771. };
  1772. let repeater = n => {
  1773. if (!domLoaded && n) {
  1774. setTimeout(repeater, 500, n - 1);
  1775. scope = getScope(params.root);
  1776. if (!scope) // exit if the root element is not present on the page
  1777. return 0;
  1778. onevent({type: 'Repeater'});
  1779. }
  1780. };
  1781. repeater(20);
  1782. _document.addEventListener(
  1783. 'DOMContentLoaded', (e) => {
  1784. domLoaded = true;
  1785. // narrow down scope to a specific element
  1786. scope = getScope(params.root);
  1787. if (!scope) // exit if the root element is not present on the page
  1788. return 0;
  1789. logger('[g] scope', scope);
  1790. // add observe mode if required
  1791. if (params.observe) {
  1792. let params = { childList:true, subtree: true };
  1793. let observer = new MutationObserver(
  1794. function(ms) {
  1795. for (let m of ms)
  1796. if (m.addedNodes.length)
  1797. onevent(m);
  1798. }
  1799. );
  1800. for (let node of scope)
  1801. observer.observe(node, params);
  1802. logger('[g] observer enabled');
  1803. }
  1804. onevent(e);
  1805. }, false);
  1806. // wait for a full page load to do one extra cut
  1807. win.addEventListener('load', onevent, false);
  1808. }
  1809.  
  1810. // wrap popular methods to open a new tab to catch specific behaviours
  1811. function createWindowOpenWrapper(openFunc) {
  1812. let _createElement = _Document.createElement,
  1813. _appendChild = _Element.appendChild,
  1814. fakeNative = (f) => (f.toString = () => `function ${f.name}() { [native code] }`);
  1815.  
  1816. let nt = new nullTools();
  1817. fakeNative(openFunc);
  1818.  
  1819. let parser = _createElement.call(_document, 'a');
  1820. let openWhitelist = (url, parent) => {
  1821. parser.href = url;
  1822. return parser.hostname === 'www.imdb.com' || parser.hostname === 'www.kinopoisk.ru' ||
  1823. parent.hostname === 'radikal.ru' && url === void 0;
  1824. };
  1825.  
  1826. let redefineOpen = (root) => {
  1827. if ('open' in root) {
  1828. let _open = root.open.bind(root);
  1829. nt.define(root, 'open', (...args) => {
  1830. if (openWhitelist(args[0], location)) {
  1831. _console.log('Whitelisted popup:', ...args);
  1832. return _open(...args);
  1833. }
  1834. return openFunc(...args);
  1835. });
  1836. }
  1837. };
  1838. redefineOpen(win);
  1839.  
  1840. function createElement() {
  1841. '[native code]';
  1842. let el = _createElement.apply(this, arguments);
  1843. // redefine window.open in first-party frames
  1844. if (el instanceof HTMLIFrameElement || el instanceof HTMLObjectElement)
  1845. el.addEventListener('load', (e) => {
  1846. try {
  1847. redefineOpen(e.target.contentWindow);
  1848. } catch(ignore) {}
  1849. }, false);
  1850. return el;
  1851. }
  1852. fakeNative(createElement);
  1853.  
  1854. let redefineCreateElement = (obj) => {
  1855. for (let root of [obj.document, _Document]) if ('createElement' in root)
  1856. nt.define(root, 'createElement', createElement);
  1857. };
  1858. redefineCreateElement(win);
  1859.  
  1860. // wrap window.open in newly added first-party frames
  1861. _Element.appendChild = function appendChild() {
  1862. '[native code]';
  1863. let el = _appendChild.apply(this, arguments);
  1864. if (el instanceof HTMLIFrameElement)
  1865. try {
  1866. redefineOpen(el.contentWindow);
  1867. redefineCreateElement(el.contentWindow);
  1868. } catch(ignore) {}
  1869. return el;
  1870. };
  1871. fakeNative(_Element.appendChild);
  1872. }
  1873.  
  1874. // Function to catch and block various methods to open a new window with 3rd-party content.
  1875. // Some advertisement networks went way past simple window.open call to circumvent default popup protection.
  1876. // This funciton blocks window.open, ability to restore original window.open from an IFRAME object,
  1877. // ability to perform an untrusted (not initiated by user) click on a link, click on a link without a parent
  1878. // node or simply a link with piece of javascript code in the HREF attribute.
  1879. function preventPopups() {
  1880. // call sandbox-me if in iframe and not whitelisted
  1881. if (inIFrame) {
  1882. win.top.postMessage({ name: 'sandbox-me', href: win.location.href }, '*');
  1883. return;
  1884. }
  1885.  
  1886. scriptLander(() => {
  1887. let nt = new nullTools({log:true});
  1888. let open = (...args) => {
  1889. '[native code]';
  1890. _console.warn('Site attempted to open a new window', ...args);
  1891. return {
  1892. document: nt.proxy({
  1893. write: nt.func({}, 'write'),
  1894. writeln: nt.func({}, 'writeln')
  1895. }),
  1896. location: nt.proxy({})
  1897. };
  1898. };
  1899.  
  1900. createWindowOpenWrapper(open);
  1901.  
  1902. _console.log('Popup prevention enabled.');
  1903. }, nullTools, createWindowOpenWrapper);
  1904. }
  1905.  
  1906. // Helper function to close background tab if site opens itself in a new tab and then
  1907. // loads a 3rd-party page in the background one (thus performing background redirect).
  1908. function preventPopunders() {
  1909. // create "close_me" event to call high-level window.close()
  1910. let eventName = `close_me_${Math.random().toString(36).substr(2)}`;
  1911. let callClose = () => {
  1912. _console.log('close call');
  1913. window.close();
  1914. };
  1915. window.addEventListener(eventName, callClose, true);
  1916.  
  1917. scriptLander(() => {
  1918. // get host of a provided URL with help of an anchor object
  1919. // unfortunately new URL(url, window.location) generates wrong URL in some cases
  1920. let parseURL = _document.createElement('A');
  1921. let getHost = url => {
  1922. parseURL.href = url;
  1923. return parseURL.hostname
  1924. };
  1925. // site went to a new tab and attempts to unload
  1926. // call for high-level close through event
  1927. let closeWindow = () => window.dispatchEvent(new CustomEvent(eventName, {}));
  1928. // check is URL local or goes to different site
  1929. let isLocal = (url) => {
  1930. if (url === location.pathname || url === location.href)
  1931. return true; // URL points to current pathname or full address
  1932. let host = getHost(url);
  1933. let site = location.hostname;
  1934. return host !== '' && // URLs with unusual protocol may have empty 'host'
  1935. (site === host || site.endsWith(`.${host}`) || host.endsWith(`.${site}`));
  1936. };
  1937.  
  1938. let _open = window.open.bind(window);
  1939. let open = (...args) => {
  1940. '[native code]';
  1941. let url = args[0];
  1942. if (url && isLocal(url))
  1943. window.addEventListener('beforeunload', closeWindow, true);
  1944. return _open(...args);
  1945. };
  1946.  
  1947. createWindowOpenWrapper(open);
  1948.  
  1949. _console.log("Background redirect prevention enabled.");
  1950. }, `let eventName="${eventName}"`, nullTools, createWindowOpenWrapper);
  1951. }
  1952.  
  1953. // Mix between check for popups and popunders
  1954. // Significantly more agressive than both and can't be used as universal solution
  1955. function preventPopMix() {
  1956. if (inIFrame) {
  1957. win.top.postMessage({ name: 'sandbox-me', href: win.location.href }, '*');
  1958. return;
  1959. }
  1960.  
  1961. // create "close_me" event to call high-level window.close()
  1962. let eventName = `close_me_${Math.random().toString(36).substr(2)}`;
  1963. let callClose = () => {
  1964. _console.log('close call');
  1965. window.close();
  1966. };
  1967. window.addEventListener(eventName, callClose, true);
  1968.  
  1969. scriptLander(() => {
  1970. let _open = window.open,
  1971. parseURL = _document.createElement('A');
  1972. // get host of a provided URL with help of an anchor object
  1973. // unfortunately new URL(url, window.location) generates wrong URL in some cases
  1974. let getHost = (url) => {
  1975. parseURL.href = url;
  1976. return parseURL.host;
  1977. };
  1978. // site went to a new tab and attempts to unload
  1979. // call for high-level close through event
  1980. let closeWindow = () => {
  1981. _open(window.location,'_self');
  1982. window.dispatchEvent(new CustomEvent(eventName, {}));
  1983. };
  1984. // check is URL local or goes to different site
  1985. function isLocal(url) {
  1986. let loc = window.location;
  1987. if (url === loc.pathname || url === loc.href)
  1988. return true; // URL points to current pathname or full address
  1989. let host = getHost(url),
  1990. site = loc.host;
  1991. if (host === '')
  1992. return false; // URLs with unusual protocol may have empty 'host'
  1993. if (host.length > site.length)
  1994. [site, host] = [host, site];
  1995. return site.includes(host, site.length - host.length);
  1996. }
  1997.  
  1998. // add check for redirect for 5 seconds, then disable it
  1999. function checkRedirect() {
  2000. window.addEventListener('beforeunload', closeWindow, true);
  2001. setTimeout(closeWindow=>window.removeEventListener('beforeunload', closeWindow, true), 5000, closeWindow);
  2002. }
  2003.  
  2004. function open(url, name) {
  2005. '[native code]';
  2006. if (url && isLocal(url) && (!name || name === '_blank')) {
  2007. _console.warn('Suspicious local new window', arguments);
  2008. checkRedirect();
  2009. return _open.apply(this, arguments);
  2010. }
  2011. _console.warn('Blocked attempt to open a new window', arguments);
  2012. return {
  2013. document: {
  2014. write: () => {},
  2015. writeln: () => {}
  2016. }
  2017. };
  2018. }
  2019.  
  2020. function clickHandler(e) {
  2021. let link = e.target,
  2022. url = link.href||'';
  2023. if (e.targetParentNode && e.isTrusted || link.target !== '_blank') {
  2024. _console.log('Link', link, 'were created dinamically, but looks fine.');
  2025. return true;
  2026. }
  2027. if (isLocal(url) && link.target === '_blank') {
  2028. _console.log('Suspicious local link', link);
  2029. checkRedirect();
  2030. return;
  2031. }
  2032. _console.log('Blocked suspicious click on a link', link);
  2033. e.stopPropagation();
  2034. e.preventDefault();
  2035. }
  2036.  
  2037. createWindowOpenWrapper(open, clickHandler);
  2038.  
  2039. _console.log("Mixed popups prevention enabled.");
  2040. }, `let eventName="${eventName}"`, createWindowOpenWrapper);
  2041. }
  2042. // External listener for case when site known to open popups were loaded in iframe
  2043. // It will sandbox any iframe which will send message 'forbid.popups' (preventPopups sends it)
  2044. // Some sites replace frame's window.location with data-url to run in clean context
  2045. if (!inIFrame) window.addEventListener(
  2046. 'message', function(e) {
  2047. if (!e.data || e.data.name !== 'sandbox-me' || !e.data.href)
  2048. return;
  2049. let src = e.data.href;
  2050. for (let frame of _document.querySelectorAll('iframe'))
  2051. if (frame.contentWindow === e.source) {
  2052. if (frame.hasAttribute('sandbox')) {
  2053. if (!frame.sandbox.contains('allow-popups'))
  2054. return; // exit frame since it's already sandboxed and popups are blocked
  2055. // remove allow-popups if frame already sandboxed
  2056. frame.sandbox.remove('allow-popups');
  2057. } else
  2058. // set sandbox mode for troublesome frame and allow scripts, forms and a few other actions
  2059. // technically allowing both scripts and same-origin allows removal of the sandbox attribute,
  2060. // but to apply content must be reloaded and this script will re-apply it in the result
  2061. frame.setAttribute('sandbox','allow-forms allow-scripts allow-presentation allow-top-navigation allow-same-origin');
  2062. _console.log('Disallowed popups from iframe', frame);
  2063.  
  2064. // reload frame content to apply restrictions
  2065. if (!src) {
  2066. src = frame.src;
  2067. _console.log('Unable to get current iframe location, reloading from src', src);
  2068. } else
  2069. _console.log('Reloading iframe with URL', src);
  2070. frame.src = 'about:blank';
  2071. frame.src = src;
  2072. }
  2073. }, false
  2074. );
  2075.  
  2076. let evalPatternYandex = /{exports:{},id:r,loaded:!1}|containerId:(.|\r|\n)+params:/;
  2077. let evalPatternGeneric = /_0x|location\s*?=|location.href\s*?=|location.assign\(|open\(/i;
  2078. function selectiveEval(...patterns) {
  2079. if (patterns.length === 0)
  2080. patterns.push(evalPatternGeneric);
  2081. scriptLander(() => {
  2082. let _eval_def = Object.getOwnPropertyDescriptor(win, 'eval');
  2083. if (!_eval_def || !_eval_def.value) {
  2084. _console.warn('Unable to wrap window.eval.', _eval_def);
  2085. return;
  2086. }
  2087. let _eval_val = _eval_def.value;
  2088. _eval_def.value = function(...args) {
  2089. if (patterns.some(pattern => pattern.test(args[0]))) {
  2090. _console.warn(`Skipped eval of ${args[0].slice(0, 512)}\u2026`);
  2091. return null;
  2092. }
  2093. try {
  2094. return _eval_val.apply(this, args);
  2095. } catch(e) {
  2096. _console.log('Crash source:', args[0]);
  2097. throw e;
  2098. }
  2099. };
  2100. Object.defineProperty(win, 'eval', _eval_def);
  2101. }, `let patterns = [${patterns}];`);
  2102. }
  2103.  
  2104. // hides cookies by pattern and attempts to remove them if they already set
  2105. // also prevents setting new versions of such cookies
  2106. function selectiveCookies(scPattern = '', scPaths = []) {
  2107. scriptLander(() => {
  2108. let patterns = scPattern.split('|');
  2109. if (patterns[0] !== ';default') {
  2110. // Google Analytics cookies
  2111. patterns.push('_g(at?|id)|__utm[a-z]');
  2112. // Yandex ABP detection cookies
  2113. patterns.push('bltsr|blcrm');
  2114. } else
  2115. patterns.shift();
  2116. let blacklist = new RegExp(`(^|;\\s?)(${patterns.join('|')})($|=)`);
  2117. if (isFirefox && scPaths.length)
  2118. scPaths = scPaths.map(path => `${path}/`);
  2119. scPaths.push('/');
  2120. let _doc_proto = ('cookie' in _Document) ? _Document : Object.getPrototypeOf(_document);
  2121. let _cookie = Object.getOwnPropertyDescriptor(_doc_proto, 'cookie');
  2122. if (_cookie) {
  2123. let _set_cookie = Function.prototype.call.bind(_cookie.set);
  2124. let _get_cookie = Function.prototype.call.bind(_cookie.get);
  2125. let expireDate = 'Thu, 01 Jan 1970 00:00:01 UTC';
  2126. let expireAge = '-99999999';
  2127. let expireBase = `=;expires=${expireDate};Max-Age=${expireAge}`;
  2128. let expireAttempted = {};
  2129. // expire is called from cookie getter and doesn't know exact parameters used to set cookies present there
  2130. // so, it will use path=/ by default if scPaths wasn't set and attempt to set cookies on all parent domains
  2131. let expire = (cookie, that) => {
  2132. let domain = that.location.hostname.split('.'),
  2133. name = cookie.replace(/=.*/,'');
  2134. scPaths.forEach(path =>_set_cookie(that, `${name}${expireBase};path=${path}`));
  2135. while (domain.length > 1) {
  2136. try {
  2137. scPaths.forEach(
  2138. path => _set_cookie(that, `${name}${expireBase};domain=${domain.join('.')};path=${path}`)
  2139. );
  2140. } catch(e) { _console.warn(e); }
  2141. domain.shift();
  2142. }
  2143. expireAttempted[name] = true;
  2144. _console.log('Removing existing cookie:', cookie);
  2145. };
  2146. // skip setting unwanted cookies
  2147. _cookie.set = function(value) {
  2148. if (blacklist.test(value)) {
  2149. _console.warn('Ignored cookie:', value);
  2150. // try to remove same cookie if it already exists using exact values from the set string
  2151. if (blacklist.test(_get_cookie(this))) {
  2152. let parts = value.split(/;\s?/),
  2153. name = parts[0].replace(/=.*/,''),
  2154. newParts = [`${name}=`, `expires=${expireDate}`, `Max-Age=${expireAge}`],
  2155. skip = [name, 'expires', 'Max-Age'];
  2156. for (let part of parts)
  2157. if (!skip.includes(part.replace(/=.*/,'')))
  2158. newParts.push(part);
  2159. try {
  2160. _set_cookie(this, newParts.join(';'));
  2161. } catch(e) { _console.warn(e); }
  2162. _console.log('Removing existing cookie:', name);
  2163. }
  2164. return;
  2165. }
  2166. return _set_cookie(this, value);
  2167. };
  2168. // hide unwanted cookies from site
  2169. _cookie.get = function() {
  2170. let res = _get_cookie(this);
  2171. if (blacklist.test(res)) {
  2172. let stack = [];
  2173. for (let cookie of res.split(/;\s?/))
  2174. if (!blacklist.test(cookie))
  2175. stack.push(cookie);
  2176. else {
  2177. let name = cookie.replace(/=.*/,'');
  2178. if (expireAttempted[name]) {
  2179. _console.log('Unable to expire:', cookie);
  2180. expireAttempted[name] = false;
  2181. }
  2182. if (!(name in expireAttempted))
  2183. expire(cookie, this);
  2184. }
  2185. res = stack.join('; ');
  2186. }
  2187. return res;
  2188. };
  2189. Object.defineProperty(_doc_proto, 'cookie', _cookie);
  2190. }
  2191. _console.log('Active cookies:', document.cookie);
  2192. }, `let scPattern = "${scPattern}", scPaths = ${JSON.stringify(scPaths)}, isFirefox = ${isFirefox};`);
  2193. }
  2194.  
  2195. /*{ // simple toString wrapper, might be useful to prevent detection
  2196. '[native code]';
  2197. let _toString = Function.prototype.apply.bind(Function.prototype.toString);
  2198. let baseText = Function.prototype.toString.toString();
  2199. let protect = new WeakSet();
  2200. protect.add(_Document.createElement);
  2201. protect.add(_Node.appendChild);
  2202. protect.add(_Node.removeChild);
  2203. win.Function.prototype.toString = function() {
  2204. if (protect.has(this))
  2205. return baseText.replace('toString', this.name);
  2206. return _toString(this);
  2207. };
  2208. protect.add(Function.prototype.toString);
  2209. }*/
  2210.  
  2211. // Locates a node with specific text in Russian
  2212. // Uses table of substitutions for similar letters
  2213. let selectNodeByTextContent = (()=> {
  2214. let subs = {
  2215. // english & greek
  2216. 'А': 'AΑ', 'В': 'BΒ', 'Г':'Γ',
  2217. 'Е': 'EΕ', 'З': '3', 'К':'KΚ',
  2218. 'М': 'MΜ', 'Н': 'HΗ', 'О':'OΟ',
  2219. 'П': 'Π', 'Р': 'PΡ', 'С':'C',
  2220. 'Т': 'T', 'Ф': 'Φ', 'Х':'XΧ'
  2221. }
  2222. let regExpBuilder = text => new RegExp(
  2223. text.toUpperCase()
  2224. .split('')
  2225. .map(function(e){
  2226. return `${e in subs ? `[${e}${subs[e]}]` : (e === ' ' ? '\\s+' : e)}[\u200b\u200c\u200d]*`;
  2227. })
  2228. .join(''),
  2229. 'i');
  2230. let reMap = {};
  2231. return (re, opts = { root: _document.body }) => {
  2232. if (!re.test) {
  2233. if (!reMap[re])
  2234. reMap[re] = regExpBuilder(re);
  2235. re = reMap[re];
  2236. }
  2237.  
  2238. for (let child of opts.root.children)
  2239. if (re.test(child.textContent)) {
  2240. if (opts.shallow)
  2241. return child;
  2242. opts.root = child;
  2243. return selectNodeByTextContent(re, opts) || child;
  2244. }
  2245. }
  2246. })();
  2247.  
  2248. // === Scripts for specific domains ===
  2249.  
  2250. let scripts = {};
  2251. // prevent popups and redirects block
  2252. // Popups
  2253. scripts.preventPopups = {
  2254. other: [
  2255. 'biqle.ru',
  2256. 'chaturbate.com',
  2257. 'dfiles.ru',
  2258. 'eporner.eu',
  2259. 'hentaiz.org',
  2260. 'mirrorcreator.com',
  2261. 'online-multy.ru',
  2262. 'radikal.ru', 'rumedia.ws',
  2263. 'tapehub.tech', 'thepiratebay.org',
  2264. 'unionpeer.com',
  2265. 'zippyshare.com'
  2266. ],
  2267. now: preventPopups
  2268. };
  2269. // Popunders (background redirect)
  2270. scripts.preventPopunders = {
  2271. other: [
  2272. 'lostfilm-online.ru',
  2273. 'mediafire.com', 'megapeer.org', 'megapeer.ru',
  2274. 'perfectgirls.net'
  2275. ],
  2276. now: preventPopunders
  2277. };
  2278. // PopMix (both types of popups encountered on site)
  2279. scripts['openload.co'] = {
  2280. other: ['oload.tv', 'oload.info'],
  2281. now: () => {
  2282. let nt = new nullTools();
  2283. nt.define(win, 'CNight', win.CoinHive);
  2284. if (location.pathname.startsWith('/embed/')) {
  2285. nt.define(win, 'BetterJsPop', {
  2286. add: ((a, b) => _console.warn('BetterJsPop.add', a, b)),
  2287. config: ((o) => _console.warn('BetterJsPop.config', o)),
  2288. Browser: { isChrome: true }
  2289. });
  2290. nt.define(win, 'isSandboxed', nt.func(null));
  2291. nt.define(win, 'adblock', false);
  2292. nt.define(win, 'adblock2', false);
  2293. } else preventPopMix();
  2294. }
  2295. };
  2296. scripts['turbobit.net'] = preventPopMix;
  2297.  
  2298. scripts['tapochek.net'] = () => {
  2299. // workaround for moradu.com/apu.php load error handler script, not sure which ad network is this
  2300. let _appendChild = Object.getOwnPropertyDescriptor(_Node, 'appendChild');
  2301. let _appendChild_value = _appendChild.value;
  2302. _appendChild.value = function appendChild(node) {
  2303. if (this === _document.body)
  2304. if ((node instanceof HTMLScriptElement || node instanceof HTMLStyleElement) &&
  2305. /^https?:\/\/[0-9a-f]{15}\.com\/\d+(\/|\.css)$/.test(node.src) ||
  2306. node instanceof HTMLDivElement && node.style.zIndex > 900000 &&
  2307. node.style.backgroundImage.includes('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'))
  2308. throw '...eenope!';
  2309. return _appendChild_value.apply(this, arguments);
  2310. };
  2311. Object.defineProperty(_Node, 'appendChild', _appendChild);
  2312.  
  2313. // disable window focus tricks and changing location
  2314. let focusHandlerName = /\WfocusAchieved\(/
  2315. let _toString = Function.prototype.call.bind(Function.prototype.toString);
  2316. let _setInterval = win.setInterval;
  2317. win.setInterval = (...args) => {
  2318. if (args.length && focusHandlerName.test(_toString(args[0]))) {
  2319. _console.log('skip setInterval for', ...args);
  2320. return -1;
  2321. }
  2322. return _setInterval(...args);
  2323. };
  2324. let _addEventListener = win.addEventListener;
  2325. win.addEventListener = function(...args) {
  2326. if (args.length && args[0] === 'focus' && focusHandlerName.test(_toString(args[1]))) {
  2327. _console.log('skip addEventListener for', ...args);
  2328. return void 0;
  2329. }
  2330. return _addEventListener.apply(this, args);
  2331. };
  2332.  
  2333. // generic popup prevention
  2334. preventPopups();
  2335. };
  2336.  
  2337. scripts['rustorka.com'] = {
  2338. other: ['rustorka.club', 'rustorka.lib', 'rustorka.net'],
  2339. now: () => {
  2340. selectiveEval(evalPatternGeneric, /antiadblock/);
  2341. selectiveCookies('adblock|u_count|gophp|st2|st3', ['/forum']);
  2342. scriptLander(() => {
  2343. // wrap window.open to catch a popup if it triggers
  2344. win.open = (...args) => {
  2345. _console.warn(`Site attempted to open "${args[0]}" in a new window.`);
  2346. location.replace(location.href);
  2347. return null;
  2348. };
  2349. window.addEventListener('DOMContentLoaded', () => {
  2350. let link = void 0;
  2351. _document.body.addEventListener('mousedown', e => {
  2352. link = e.target.closest('a, select, #fancybox-title-wrap');
  2353. }, false);
  2354. let _open = window.open.bind(window);
  2355. let _getAttribute = Function.prototype.call.bind(_Element.getAttribute);
  2356. win.open = (...args) => {
  2357. let url = args[0];
  2358. if (link instanceof HTMLAnchorElement) {
  2359. // third-party post links
  2360. let href = _getAttribute(link, 'href');
  2361. if (link.classList.contains('postLink') &&
  2362. !link.matches(`a[href*="${location.hostname}"]`) &&
  2363. (href === url || link.href === url))
  2364. return _open(...args);
  2365. // onclick # links
  2366. if (href === '#' && /window\.open/.test(_getAttribute(link, 'onclick')))
  2367. return _open(...args);
  2368. // force local links to load in the current window
  2369. if (href[0] === '/' || href.startsWith('./') || href.includes(`//${location.hostname}/`))
  2370. location.assign(href);
  2371. }
  2372. // list of image hostings under upload picture button (new comment)
  2373. if (link instanceof HTMLSelectElement &&
  2374. !url.includes(location.hostname) &&
  2375. link.value === url)
  2376. return _open(...args);
  2377. // open screenshot in a new window
  2378. if (link instanceof HTMLSpanElement &&
  2379. link.id === 'fancybox-title-wrap')
  2380. return _open(...args);
  2381. // looks like tabunder
  2382. if (link === null && url === location.href)
  2383. location.replace(url); // reload current page
  2384. // other cases
  2385. _console.warn(`Site attempted to open "${url}" in a new window. Source: `, link);
  2386. return {};
  2387. };
  2388. }, true);
  2389. }, nullTools)
  2390. }
  2391. };
  2392.  
  2393. // = other ======================================================================================
  2394. scripts['1tv.ru'] = {
  2395. other: ['mediavitrina.ru'],
  2396. now: () => scriptLander(() => {
  2397. let nt = new nullTools();
  2398. nt.define(win, 'EUMPAntiblockConfig', nt.proxy({url: '//www.1tv.ru/favicon.ico'}));
  2399. let disablePlugins = {
  2400. 'antiblock': false,
  2401. 'stat1tv': false
  2402. };
  2403. let _EUMPConfig = void 0;
  2404. let _EUMPConfig_set = x => {
  2405. if (x.plugins) {
  2406. x.plugins = x.plugins.filter(plugin => (plugin in disablePlugins) ? !(disablePlugins[plugin] = true) : true);
  2407. _console.warn(`Player plugins: active [${x.plugins}], disabled [${Object.keys(disablePlugins).filter(x => disablePlugins[x])}]`);
  2408. }
  2409. _EUMPConfig = x;
  2410. };
  2411. if ('EUMPConfig' in win)
  2412. _EUMPConfig_set(win.EUMPConfig);
  2413. Object.defineProperty(win, 'EUMPConfig', {
  2414. enumerable: true,
  2415. get: () => _EUMPConfig,
  2416. set: _EUMPConfig_set
  2417. });
  2418. }, nullTools)
  2419. };
  2420.  
  2421. scripts['24smi.org'] = () => selectiveCookies('has_adblock');
  2422.  
  2423. scripts['2picsun.ru'] = {
  2424. other: [
  2425. 'pics2sun.ru', '3pics-img.ru'
  2426. ],
  2427. now: () => {
  2428. Object.defineProperty(navigator, 'userAgent', {value: 'googlebot'});
  2429. }
  2430. };
  2431.  
  2432. scripts['4pda.ru'] = {
  2433. now: () => {
  2434. // https://greasyfork.org/en/scripts/14470-4pda-unbrender
  2435. let isForum = location.pathname.startsWith('/forum/'),
  2436. remove = node => (node && node.parentNode.removeChild(node)),
  2437. hide = node => (node && (node.style.display = 'none'));
  2438.  
  2439. // clean a page
  2440. window.addEventListener(
  2441. 'DOMContentLoaded', function() {
  2442. let width = () => window.innerWidth || _de.clientWidth || _document.body.clientWidth || 0;
  2443. let height = () => window.innerHeight || _de.clientHeight || _document.body.clientHeight || 0;
  2444.  
  2445. HeaderAds: {
  2446. // hide ads above HEADER
  2447. let header = _document.querySelector('.drop-search');
  2448. if (!header) {
  2449. _console.warn('Unable to locate header element');
  2450. break HeaderAds;
  2451. }
  2452. header = header.parentNode.parentNode;
  2453. for (let itm of header.parentNode.children)
  2454. if (itm !== header)
  2455. hide(itm);
  2456. else break;
  2457. }
  2458.  
  2459. if (isForum) {
  2460. let itm = _document.querySelector('#logostrip');
  2461. if (itm)
  2462. remove(itm.parentNode.nextSibling);
  2463. // clear background in the download frame
  2464. if (location.pathname.startsWith('/forum/dl/')) {
  2465. let setBackground = node => _setAttribute(
  2466. node,
  2467. 'style', (_getAttribute(node, 'style') || '') +
  2468. ';background-color:#4ebaf6!important'
  2469. );
  2470. setBackground(_document.body);
  2471. for (let itm of _document.querySelectorAll('body > div'))
  2472. if (!itm.querySelector('.dw-fdwlink, .content') && !itm.classList.contains('footer'))
  2473. remove(itm);
  2474. else
  2475. setBackground(itm);
  2476. }
  2477. // exist from DOMContentLoaded since the rest is not for forum
  2478. return;
  2479. }
  2480.  
  2481. FixNavMenu: {
  2482. // restore DevDB link in the navigation
  2483. let itm = _document.querySelector('#nav li a[href$="/devdb/"]')
  2484. if (!itm) {
  2485. _console.warn('Unable to locate navigation menu');
  2486. break FixNavMenu;
  2487. }
  2488. itm.closest('li').style.display = 'block';
  2489. // hide ad link from the navigation
  2490. hide(_document.querySelector('#nav li a[data-dotrack]'));
  2491. }
  2492. SidebarAds: {
  2493. // remove ads from sidebar
  2494. let aside = _document.querySelectorAll('[class]:not([id]) > [id]:not([class]) > :first-child + :last-child');
  2495. if (!aside.length) {
  2496. _console.warn('Unable to locate sidebar');
  2497. break SidebarAds;
  2498. }
  2499. let post;
  2500. for (let side of aside) {
  2501. _console.log('Processing potential sidebar:', side);
  2502. for (let itm of Array.from(side.children)) {
  2503. post = itm.classList.contains('post');
  2504. if (itm.querySelector('iframe') && !post)
  2505. remove(itm);
  2506. if (itm.querySelector('script, a[target="_blank"] > img') && !post || !itm.children.length)
  2507. hide(itm);
  2508. }
  2509. }
  2510. }
  2511.  
  2512. _document.body.setAttribute('style', (_document.body.getAttribute('style')||'')+';background-color:#E6E7E9!important');
  2513.  
  2514. let extra = 'background-image:none!important;background-color:transparent!important',
  2515. fakeStyles = new WeakMap(),
  2516. styleProxy = {
  2517. get: (target, prop) => fakeStyles.get(target)[prop] || target[prop],
  2518. set: function(target, prop, value) {
  2519. let fakeStyle = fakeStyles.get(target);
  2520. ((prop in fakeStyle) ? fakeStyle : target)[prop] = value;
  2521. return true;
  2522. }
  2523. };
  2524. for (let itm of _document.querySelectorAll('[id]:not(A), A')) {
  2525. if (!(itm.offsetWidth > 0.95 * width() &&
  2526. itm.offsetHeight > 0.85 * height()))
  2527. continue;
  2528. if (itm.tagName !== 'A') {
  2529. fakeStyles.set(itm.style, {
  2530. 'backgroundImage': itm.style.backgroundImage,
  2531. 'backgroundColor': itm.style.backgroundColor
  2532. });
  2533.  
  2534. try {
  2535. Object.defineProperty(itm, 'style', {
  2536. value: new Proxy(itm.style, styleProxy),
  2537. enumerable: true
  2538. });
  2539. } catch (e) {
  2540. _console.log('Unable to protect style property.', e);
  2541. }
  2542.  
  2543. _setAttribute(itm, 'style', `${(_getAttribute(itm, 'style') || '')};${extra}`);
  2544. }
  2545. if (itm.tagName === 'A')
  2546. _setAttribute(itm, 'style', 'display:none!important');
  2547. }
  2548. }
  2549. );
  2550. }
  2551. };
  2552.  
  2553. scripts['adhands.ru'] = () => scriptLander(() => {
  2554. let nt = new nullTools();
  2555. try {
  2556. let _adv;
  2557. Object.defineProperty(win, 'adv', {
  2558. get: () => _adv,
  2559. set: (v) => {
  2560. _console.log('Blocked advert on adhands.ru.');
  2561. nt.define(v, 'advert', '');
  2562. _adv = v;
  2563. }
  2564. });
  2565. } catch (ignore) {
  2566. if (!win.adv)
  2567. _console.log('Unable to locate advert on adhands.ru.');
  2568. else {
  2569. _console.log('Blocked advert on adhands.ru.');
  2570. nt.define(win.adv, 'advert', '');
  2571. }
  2572. }
  2573. }, nullTools);
  2574.  
  2575. scripts['all-episodes.tv'] = () => {
  2576. let nt = new nullTools();
  2577. nt.define(win, 'perX1', 2);
  2578. createStyle('#advtss, #ad3, a[href*="/ad.admitad.com/"] { display:none!important }');
  2579. };
  2580.  
  2581. scripts['allhentai.ru'] = () => {
  2582. selectiveEval();
  2583. preventPopups();
  2584. scriptLander(() => {
  2585. let _onerror = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'onerror');
  2586. if (!_onerror)
  2587. return;
  2588. _onerror.set = (...args) => _console.log(args[0].toString());
  2589. Object.defineProperty(HTMLElement.prototype, 'onerror', _onerror);
  2590. });
  2591. };
  2592.  
  2593. scripts['allmovie.pro'] = {
  2594. other: ['rufilmtv.org'],
  2595. dom: function() {
  2596. // pretend to be Android to make site use different played for ads
  2597. if (isSafari)
  2598. return;
  2599. Object.defineProperty(navigator, 'userAgent', {
  2600. get: function(){
  2601. 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';
  2602. },
  2603. enumerable: true
  2604. });
  2605. }
  2606. };
  2607.  
  2608. scripts['anidub-online.ru'] = {
  2609. other: ['anime.anidub.com', 'online.anidub.com'],
  2610. dom: function() {
  2611. if (win.ogonekstart1)
  2612. win.ogonekstart1 = () => _console.log("Fire in the hole!");
  2613. },
  2614. now: () => createStyle([
  2615. '.background {background: none!important;}',
  2616. '.background > script + div,'+
  2617. '.background > script ~ div:not([id]):not([class]) + div[id][class]'+
  2618. '{display:none!important}'
  2619. ])
  2620. };
  2621.  
  2622. scripts['audioportal.su'] = {
  2623. now: () => createStyle('#blink2 { display: none !important }'),
  2624. dom: () => {
  2625. let links = _document.querySelectorAll('a[onclick*="clickme("]');
  2626. if (!links) return;
  2627. for (let link of links)
  2628. clickme(link);
  2629. }
  2630. };
  2631.  
  2632. scripts['avito.ru'] = () => selectiveCookies('abp|cmtchd|crookie|is_adblock');
  2633.  
  2634. scripts['di.fm'] = () => scriptLander(() => {
  2635. let log = false;
  2636. // wrap global app object to catch registration of specific modules
  2637. let _di = void 0;
  2638. Object.defineProperty(win, 'di', {
  2639. get: () => _di,
  2640. set: vl => {
  2641. if (vl === _di)
  2642. return;
  2643. log && _console.log('di =', vl);
  2644. _di = new Proxy(vl, {
  2645. set: (di, name, vl) => {
  2646. if (vl === di[name])
  2647. return true;
  2648. if (name === 'app') {
  2649. log && _console.log('di.app =', vl);
  2650. if ('module' in vl)
  2651. vl.module = new Proxy(vl.module, {
  2652. apply: (module, that, args) => {
  2653. if (/Wall|Banner|Detect|WebplayerApp\.Ads/.test(args[0])) {
  2654. let name = args[0];
  2655. log && _console.warn('wrap', name, 'module');
  2656. if (typeof args[1] === 'function')
  2657. args[1] = new Proxy(args[1], {
  2658. apply: (fun, that, args) => {
  2659. if (args[0]) // module object
  2660. args[0].start = () => _console.log('Skipped start of', name);
  2661. return Reflect.apply(fun, that, args);
  2662. }
  2663. });
  2664. }// else log && _console.log('loading module', args[0]);
  2665. if (args[0] === 'Modals') {
  2666. log && _console.warn('wrap', name, 'module');
  2667. if (typeof args[1] === 'function')
  2668. args[1] = new Proxy(args[1], {
  2669. apply: (fun, that, args) => {
  2670. if ('commands' in args[1] && 'setHandlers' in args[1].commands &&
  2671. !Object.hasOwnProperty.call(args[1].commands, 'setHandlers')) {
  2672. let _commands = args[1].commands;
  2673. _commands.setHandlers = new Proxy(_commands.setHandlers, {
  2674. apply: (fun, that, args) => {
  2675. for (let name in args[0])
  2676. if (name === 'modal:streaminterrupt' ||
  2677. name === 'modal:midroll')
  2678. args[0][name] = () => _console.log('Skipped', name, 'window');
  2679. delete _commands.setHandlers;
  2680. return Reflect.apply(fun, that, args);
  2681. }
  2682. });
  2683. }
  2684. return Reflect.apply(fun, that, args);
  2685. }
  2686. });
  2687. }
  2688. return Reflect.apply(module, that, args);
  2689. }
  2690. });
  2691. }
  2692. di[name] = vl;
  2693. return true;
  2694. }
  2695. });
  2696. }
  2697. });
  2698. // don't send errorception logs
  2699. Object.defineProperty(win, 'onerror', {
  2700. set: vl => log && _console.warn('Skipped global onerror callback', vl)
  2701. });
  2702. });
  2703.  
  2704. scripts['draug.ru'] = {
  2705. other: ['vargr.ru'],
  2706. now: () => scriptLander(() => {
  2707. if (location.pathname === '/pop.html')
  2708. win.close();
  2709. createStyle([
  2710. '#timer_1 { display: none !important }',
  2711. '#timer_2 { display: block !important }'
  2712. ]);
  2713. let _contentWindow = Object.getOwnPropertyDescriptor(HTMLIFrameElement.prototype, 'contentWindow');
  2714. let _get_contentWindow = Function.prototype.apply.bind(_contentWindow.get);
  2715. _contentWindow.get = function() {
  2716. let res = _get_contentWindow(this);
  2717. if (res.location.href === 'about:blank')
  2718. res.document.write = (...args) => _console.log('Skipped iframe.write(', ...args, ')');
  2719. return res;
  2720. };
  2721. Object.defineProperty(HTMLIFrameElement.prototype, 'contentWindow', _contentWindow);
  2722. }),
  2723. dom: () => {
  2724. let list = _querySelectorAll('div[id^="yandex_rtb_"], .adsbygoogle');
  2725. list.forEach(node => _console.log('Removed:', node.parentNode.parentNode.removeChild(node.parentNode)));
  2726. }
  2727. };
  2728.  
  2729. scripts['drive2.ru'] = () => {
  2730. selectiveCookies();
  2731. gardener('.c-block:not([data-metrika="recomm"]),.o-grid__item', />Реклама<\//i);
  2732. scriptLander(() => {
  2733. let _d2 = void 0;
  2734. Object.defineProperty(win, 'd2', {
  2735. get: () => _d2,
  2736. set: o => {
  2737. if (o === _d2)
  2738. return true;
  2739. _d2 = new Proxy(o, {
  2740. set: (tgt, prop, val) => {
  2741. if (['brandingRender', 'dvReveal', '__dv'].includes(prop))
  2742. val = () => null;
  2743. tgt[prop] = val;
  2744. return true;
  2745. }
  2746. });
  2747. }
  2748. });
  2749. });
  2750. };
  2751.  
  2752. scripts['echo.msk.ru'] = () => selectiveEval(evalPatternYandex, /^document\.write/, /callAdblock/);
  2753.  
  2754. scripts['fastpic.ru'] = () => {
  2755. let nt = new nullTools();
  2756. // Had to obfuscate property name to avoid triggering anti-obfuscation on greasyfork.org -_- (Exception 403012)
  2757. nt.define(win, `_0x${'4955'}`, []);
  2758. };
  2759.  
  2760. scripts['fishki.net'] = () => {
  2761. scriptLander(() => {
  2762. let nt = new nullTools();
  2763. let fishki = {};
  2764. nt.define(fishki, 'adv', nt.proxy({
  2765. afterAdblockCheck: nt.func(null),
  2766. refreshFloat: nt.func(null)
  2767. }));
  2768. nt.define(fishki, 'is_adblock', false);
  2769. nt.define(win, 'fishki', fishki);
  2770. }, nullTools);
  2771. gardener('.drag_list > .drag_element, .list-view > .paddingtop15, .post-wrap', /543769|Новости\sпартнеров|Полезная\sреклама/);
  2772. };
  2773.  
  2774. scripts['friends.in.ua'] = () => scriptLander(() => {
  2775. Object.defineProperty(win, 'need_warning', {
  2776. get: () => 0, set: () => null
  2777. });
  2778. });
  2779.  
  2780. scripts['gidonline.club'] = () => createStyle('.tray > div[style] {display: none!important}');
  2781.  
  2782. scripts['hdgo.cc'] = {
  2783. other: ['46.30.43.38', 'couber.be'],
  2784. now: () => (new MutationObserver(
  2785. (ms) => {
  2786. let m, node;
  2787. for (m of ms) for (node of m.addedNodes)
  2788. if (node.tagName instanceof HTMLScriptElement && _getAttribute(node, 'onerror') !== null)
  2789. node.removeAttribute('onerror');
  2790. }
  2791. )).observe(_document.documentElement, { childList:true, subtree: true })
  2792. };
  2793.  
  2794. scripts['gismeteo.ru'] = {
  2795. other: ['gismeteo.by', 'gismeteo.kz', 'gismeteo.ua'],
  2796. now: () => {
  2797. selectiveCookies('ab_[^=]*|redirect|_gab');
  2798. gardener('div > script', /AdvManager/i, { observe: true, parent: 'div' })
  2799. }
  2800. };
  2801.  
  2802. scripts['hdrezka.ag'] = () => {
  2803. Object.defineProperty(win, 'ab', { value: false, enumerable: true });
  2804. gardener('div[id][onclick][onmouseup][onmousedown]', /onmouseout/i);
  2805. };
  2806.  
  2807. scripts['hqq.tv'] = () => scriptLander(() => {
  2808. // disable anti-debugging in hqq.tv player
  2809. let isObfuscated = text => /[^a-z0-9]([a-z0-9]{1,2}\.[a-z0-9]{1,2}\(|[a-z0-9]{4}\.[a-z]\(\d+\)|[a-z0-9]\[[a-z0-9]{1,2}\]\[[a-z0-9]{1,2}\])/i.test(text);
  2810. deepWrapAPI(root => {
  2811. // skip obfuscated stuff and a few other calls
  2812. let _setInterval = root.setInterval,
  2813. _setTimeout = root.setTimeout,
  2814. _toString = root.Function.prototype.call.bind(root.Function.prototype.toString);
  2815. root.setInterval = (...args) => {
  2816. let fun = args[0];
  2817. if (fun instanceof Function) {
  2818. let text = _toString(fun),
  2819. skip = text.includes('check();') || isObfuscated(text);
  2820. _console.warn('setInterval', text, 'skip', skip);
  2821. if (skip) return -1;
  2822. }
  2823. return _setInterval.apply(this, args);
  2824. };
  2825. let wrappedST = new WeakSet();
  2826. root.setTimeout = (...args) => {
  2827. let fun = args[0];
  2828. if (fun instanceof Function) {
  2829. let text = _toString(fun),
  2830. skip = fun.name === 'check' || isObfuscated(text);
  2831. if (!wrappedST.has(fun)) {
  2832. _console.warn('setTimeout', text, 'skip', skip);
  2833. wrappedST.add(fun);
  2834. }
  2835. if (skip) return;
  2836. }
  2837. return _setTimeout.apply(this, args);
  2838. };
  2839. // skip 'debugger' call
  2840. let _eval = root.eval;
  2841. root.eval = text => {
  2842. if (typeof text === 'string' && text.includes('debugger;')) {
  2843. _console.warn('skip eval', text);
  2844. return;
  2845. }
  2846. _eval(text);
  2847. };
  2848. // Prevent RegExpt + toString trick
  2849. let _proto = void 0;
  2850. try {
  2851. _proto = root.RegExp.prototype;
  2852. } catch(ignore) {
  2853. return;
  2854. }
  2855. let _RE_tS = Object.getOwnPropertyDescriptor(_proto, 'toString');
  2856. let _RE_tSV = _RE_tS.value || _RE_tS.get();
  2857. Object.defineProperty(_proto, 'toString', {
  2858. enumerable: _RE_tS.enumerable,
  2859. configurable: _RE_tS.configurable,
  2860. get: () => _RE_tSV,
  2861. set: val => _console.warn('Attempt to change toString for', this, 'with', _toString(val))
  2862. });
  2863. });
  2864. }, deepWrapAPI);
  2865.  
  2866. scripts['hideip.me'] = {
  2867. now: () => scriptLander(() => {
  2868. let _innerHTML = Object.getOwnPropertyDescriptor(_Element, 'innerHTML');
  2869. let _set_innerHTML = _innerHTML.set;
  2870. let _innerText = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'innerText');
  2871. let _get_innerText = _innerText.get;
  2872. let div = _document.createElement('div');
  2873. _innerHTML.set = function(...args) {
  2874. _set_innerHTML.call(div, args[0].replace('i','a'));
  2875. if (args[0] && /[рp][еe]кл/.test(_get_innerText.call(div))||
  2876. /(\d\d\d?\.){3}\d\d\d?:\d/.test(_get_innerText.call(this)) ) {
  2877. _console.log('Anti-Adblock killed.');
  2878. return true;
  2879. }
  2880. _set_innerHTML.apply(this, args);
  2881. };
  2882. Object.defineProperty(_Element, 'innerHTML', _innerHTML);
  2883. Object.defineProperty(win, 'adblock', {
  2884. get: () => false,
  2885. set: () => null,
  2886. enumerable: true
  2887. });
  2888. let _$ = {};
  2889. let _$_map = new WeakMap();
  2890. let _gOPD = Object.getOwnPropertyDescriptor(Object, 'getOwnPropertyDescriptor');
  2891. let _val_gOPD = _gOPD.value;
  2892. _gOPD.value = function(...args) {
  2893. let _res = _val_gOPD.apply(this, args);
  2894. if (args[0] instanceof Window && (args[1] === '$' || args[1] === 'jQuery')) {
  2895. delete _res.get;
  2896. delete _res.set;
  2897. _res.value = win[args[1]];
  2898. }
  2899. return _res;
  2900. };
  2901. Object.defineProperty(Object, 'getOwnPropertyDescriptor', _gOPD);
  2902. let getJQWrap = (n) => {
  2903. let name = n;
  2904. return {
  2905. enumerable: true,
  2906. get: () => _$[name],
  2907. set: x => {
  2908. if (_$_map.has(x)) {
  2909. _$[name] = _$_map.get(x);
  2910. return true;
  2911. }
  2912. if (x === _$.$ || x === _$.jQuery) {
  2913. _$[name] = x;
  2914. return true;
  2915. }
  2916. _$[name] = new Proxy(x, {
  2917. apply: (t, o, args) => {
  2918. let _res = t.apply(o, args);
  2919. if (_$_map.has(_res.is))
  2920. _res.is = _$_map.get(_res.is);
  2921. else {
  2922. let _is = _res.is;
  2923. _res.is = function(...args) {
  2924. if (args[0] === ':hidden')
  2925. return false;
  2926. return _is.apply(this, args);
  2927. };
  2928. _$_map.set(_is, _res.is);
  2929. }
  2930. return _res;
  2931. }
  2932. });
  2933. _$_map.set(x, _$[name]);
  2934. return true;
  2935. }
  2936. };
  2937. };
  2938. Object.defineProperty(win, '$', getJQWrap('$'));
  2939. Object.defineProperty(win, 'jQuery', getJQWrap('jQuery'));
  2940. let _dP = Object.defineProperty;
  2941. Object.defineProperty = function(...args) {
  2942. if (args[0] instanceof Window && (args[1] === '$' || args[1] === 'jQuery'))
  2943. return void 0;
  2944. return _dP.apply(this, args);
  2945. };
  2946. })
  2947. };
  2948.  
  2949. scripts['igra-prestoloff.cx'] = () => scriptLander(() => {
  2950. let nt = new nullTools();
  2951. /*jslint evil: true */ // yes, evil, I know
  2952. let _write = _document.write.bind(_document);
  2953. /*jslint evil: false */
  2954. nt.define(_document, 'write', t => {
  2955. let id = t.match(/jwplayer\("(\w+)"\)/i);
  2956. if (id && id[1])
  2957. return _write(`<div id="${id[1]}"></div>${t}`);
  2958. return _write('');
  2959. });
  2960. });
  2961.  
  2962. scripts['imageban.ru'] = () => { Object.defineProperty(win, 'V7x1J', { get: () => null }); };
  2963.  
  2964. scripts['inoreader.com'] = () => scriptLander(() => {
  2965. let i = setInterval(() => {
  2966. if ('adb_detected' in win) {
  2967. win.adb_detected = () => adb_not_detected();
  2968. clearInterval(i);
  2969. }
  2970. }, 10);
  2971. _document.addEventListener('DOMContentLoaded', () => clearInterval(i), false);
  2972. });
  2973.  
  2974. scripts['ivi.ru'] = () => {
  2975. let _xhr_open = win.XMLHttpRequest.prototype.open;
  2976. win.XMLHttpRequest.prototype.open = function(method, url, ...args) {
  2977. if (typeof url === 'string')
  2978. if (url.endsWith('/track'))
  2979. return;
  2980. return _xhr_open.call(this, method, url, ...args);
  2981. };
  2982. let _responseText = Object.getOwnPropertyDescriptor(XMLHttpRequest.prototype, 'responseText');
  2983. let _responseText_get = _responseText.get;
  2984. _responseText.get = function() {
  2985. if (this.__responseText__)
  2986. return this.__responseText__;
  2987. let res = _responseText_get.apply(this, arguments);
  2988. let o;
  2989. try {
  2990. if (res)
  2991. o = JSON.parse(res);
  2992. } catch(ignore) {};
  2993. let changed = false;
  2994. if (o && o.result) {
  2995. if (o.result instanceof Array &&
  2996. 'adv_network_logo_url' in o.result[0]) {
  2997. o.result = [];
  2998. changed = true;
  2999. }
  3000. if (o.result.show_adv) {
  3001. o.result.show_adv = false;
  3002. changed = true;
  3003. }
  3004. }
  3005. if (changed) {
  3006. _console.log('changed response >>', o);
  3007. res = JSON.stringify(o);
  3008. }
  3009. this.__responseText__ = res;
  3010. return res;
  3011. };
  3012. Object.defineProperty(XMLHttpRequest.prototype, 'responseText', _responseText);
  3013. };
  3014.  
  3015. scripts['kinopoisk.ru'] = () => {
  3016. selectiveCookies('cmtchd|crookie|kpunk');
  3017. // set no-branding body style and adjust other blocks on the page
  3018. let style = [
  3019. '.app__header.app__header_margin-bottom_brand, #top { margin-bottom: 20px !important }',
  3020. '.app__branding { display: none !important}'
  3021. ];
  3022. if (location.hostname === 'www.kinopoisk.ru' && !location.pathname.startsWith('/games/'))
  3023. style.push('html:not(#id), body:not(#id), .app-container { background: #d5d5d5 url(/images/noBrandBg.jpg) 50% 0 no-repeat !important }');
  3024. createStyle(style);
  3025. // catch branding and other things
  3026. let _KP = void 0;
  3027. Object.defineProperty(win, 'KP', {
  3028. get: () => _KP,
  3029. set: val => {
  3030. if (_KP === val)
  3031. return true;
  3032. _KP = new Proxy(val, {
  3033. set: (kp, name, val) => {
  3034. if (name === 'branding') {
  3035. kp[name] = new Proxy({ weborama: {} }, {
  3036. get: (kp, name) => name in kp ? kp[name] : '',
  3037. set: () => true
  3038. });
  3039. return true;
  3040. }
  3041. if (name === 'config')
  3042. val = new Proxy(val, {
  3043. set: (cfg, name, val) => {
  3044. if (name === 'anContextUrl')
  3045. return true;
  3046. if (name === 'adfoxEnabled' || name === 'hasBranding')
  3047. val = false;
  3048. if (name === 'adfoxVideoAdUrls')
  3049. val = {flash:{}, html:{}};
  3050. cfg[name] = val;
  3051. return true;
  3052. }
  3053. });
  3054. kp[name] = val;
  3055. return true;
  3056. }
  3057. });
  3058. _console.log('KP =', val);
  3059. }
  3060. });
  3061. // skip branding and some other junk
  3062. Object.defineProperty(win, 'advBlock', {
  3063. get: () => () => null,
  3064. set: () => true
  3065. });
  3066. // skip timeout check for blocked requests
  3067. let _setTimeout = Function.prototype.apply.bind(win.setTimeout);
  3068. let _toString = Function.prototype.apply.bind(Function.prototype.toString);
  3069. win.setTimeout = function(...args) {
  3070. if (args[1] === 100) {
  3071. let str = _toString(args[0]);
  3072. if (str.endsWith('{a()}') || str.endsWith('{n()}'))
  3073. return;
  3074. }
  3075. return _setTimeout(this, args);
  3076. };
  3077. };
  3078.  
  3079. scripts['korrespondent.net'] = {
  3080. now: () => scriptLander(() => {
  3081. let nt = new nullTools();
  3082. nt.define(win, 'holder', function(id) {
  3083. let div = _document.getElementById(id);
  3084. if (!div)
  3085. return;
  3086. if (div.parentNode.classList.contains('col__sidebar')) {
  3087. div.parentNode.appendChild(div);
  3088. div.style.height = '300px';
  3089. }
  3090. });
  3091. }, nullTools),
  3092. dom: () => {
  3093. for (let frame of _document.querySelectorAll('.unit-side-informer > iframe'))
  3094. frame.parentNode.style.width = '1px';
  3095. }
  3096. };
  3097.  
  3098. scripts['liveinternet.ru'] = () => selectiveEval(evalPatternYandex);
  3099.  
  3100. scripts['mail.ru'] = {
  3101. other: ['ok.ru'],
  3102. now: () => {
  3103. selectiveCookies('act|testcookie');
  3104. scriptLander(() => {
  3105. let nt = new nullTools();
  3106. // Trick to prevent mail.ru from removing 3rd-party styles
  3107. nt.define(Object.prototype, 'restoreVisibility', nt.func(null), false);
  3108. // Disable some of their counters
  3109. nt.define(win, 'rb_counter', nt.func(null, 'rb_counter'));
  3110. if (location.hostname === 'e.mail.ru')
  3111. nt.define(win, 'aRadar', nt.func(null, 'aRadar'));
  3112. else
  3113. nt.define(win, 'createRadar', nt.func(nt.func(null, 'aRadar'), 'createRadar'));
  3114.  
  3115. // Disable page scrambler on mail.ru to let extensions easily block ads there
  3116. let logger = {
  3117. apply: (target, thisArg, args) => {
  3118. let res = target.apply(thisArg, args);
  3119. _console.log(`${target._name}(`, ...args, `) >>`, res);
  3120. return res;
  3121. }
  3122. };
  3123.  
  3124. function wrapLocator(locator) {
  3125. if ('setup' in locator) {
  3126. let _setup = locator.setup;
  3127. locator.setup = function(o) {
  3128. if ('enable' in o) {
  3129. o.enable = false;
  3130. _console.log('Disable mimic mode.');
  3131. }
  3132. if ('links' in o) {
  3133. o.links = [];
  3134. _console.log('Call with empty list of sheets.');
  3135. }
  3136. return _setup.call(this, o);
  3137. };
  3138. locator.insertSheet = () => false;
  3139. locator.wrap = () => false;
  3140. }
  3141. try {
  3142. let names = [];
  3143. for (let name in locator)
  3144. if (locator[name] instanceof Function && name !== 'transform') {
  3145. locator[name]._name = "locator." + name;
  3146. locator[name] = new Proxy(locator[name], logger);
  3147. names.push(name);
  3148. }
  3149. _console.log(`[locator] wrapped properties: ${names.length ? names.join(', ') : '[empty]'}`);
  3150. } catch(e) {
  3151. _console.log(e);
  3152. }
  3153. return locator;
  3154. }
  3155.  
  3156. function defineLocator(root) {
  3157. let _locator = root.locator;
  3158. let wrapLocatorSetter = vl => _locator = wrapLocator(vl);
  3159. let loc_desc = Object.getOwnPropertyDescriptor(root, 'locator');
  3160. if (!loc_desc || loc_desc.set !== wrapLocatorSetter)
  3161. try {
  3162. Object.defineProperty(root, 'locator', {
  3163. set: wrapLocatorSetter,
  3164. get: () => _locator
  3165. });
  3166. } catch (err) {
  3167. _console.log('Unable to redefine "locator" object!!!', err);
  3168. }
  3169. if (loc_desc.value)
  3170. _locator = wrapLocator(loc_desc.value);
  3171. }
  3172.  
  3173. {
  3174. let missingCheck = {
  3175. get: (obj, name) => {
  3176. if (!(name in obj))
  3177. _console.warn(obj, 'missing:', name);
  3178. return obj[name];
  3179. }
  3180. };
  3181. let skipLog = (name, ret) => (...args) => (_console.log(`Skip ${name}(`, ...args, ')'), ret);
  3182. let createSkipLogObject = (baseName, list) => list.reduce(
  3183. (acc, cur) => (acc[cur] = skipLog(`${baseName}.${cur}`), acc),
  3184. {}
  3185. );
  3186. let redefiner = {
  3187. apply: (target, thisArg, args) => {
  3188. let res = void 0;
  3189. if (target._name === 'mrg-smokescreen/Welter')
  3190. res = {
  3191. isWelter: () => true,
  3192. wrap: skipLog(`${target._name}.wrap`)
  3193. };
  3194. if (target._name === 'mrg-smokescreen/StyleSheets')
  3195. res = createSkipLogObject(target._name, ['update', 'remove', 'insert', 'setup']);
  3196. if (target._name === 'mrg-honeypot/main')
  3197. res = { check: skipLog(`${target._name}.check`, false) };
  3198. if (target._name.startsWith('advert/rb/slot')) {
  3199. res = createSkipLogObject(target._name, ['get', 'getHTML', 'createBlock', 'onRedirect']);
  3200. res.slot = '0';
  3201. }
  3202. if (target._name.startsWith('OK/banners/'))
  3203. res = createSkipLogObject(target._name, ['activate', 'deactivate']);
  3204. if (target._name === 'advert/adman/adman')
  3205. res = createSkipLogObject(target._name, ['refresh', 'getBlock', 'init']);
  3206. if (res)
  3207. res = new Proxy(res, missingCheck);
  3208. else
  3209. res = target.apply(thisArg, args);
  3210. if (target._name === 'mimic')
  3211. res = new Proxy(res, {
  3212. construct: (...args) => {
  3213. function wrap(o) {
  3214. if ('locator' in o)
  3215. defineLocator(o);
  3216. for (let name in o)
  3217. if (typeof o[name] === 'object' && name !== 'locator')
  3218. wrap(o[name]);
  3219. return o;
  3220. }
  3221. let res = wrap(Reflect.construct(...args));
  3222. _console.warn('new mimic', res);
  3223. return res;
  3224. }
  3225. });
  3226. if (target._name === 'mrg-smokescreen/Utils')
  3227. res.extend = function(...args) {
  3228. let res = {
  3229. enable: false,
  3230. match: [],
  3231. links: []
  3232. };
  3233. _console.log(`${target._name}.extend(`, ...args, ') >>', res );
  3234. return res;
  3235. };
  3236. if (target._name === 'advert/RB') {
  3237. res.getSlots = () => [];
  3238. res.load._name = target._name + '.load';
  3239. res.load = new Proxy(res.load, redefiner);
  3240. }
  3241. _console.log(target._name, '(',...args,') >>', res);
  3242. return res;
  3243. }
  3244. };
  3245.  
  3246. let wrapAdFuncs = {
  3247. apply: (target, thisArg, args) => {
  3248. let module = args[0];
  3249. if (typeof module === 'string')
  3250. if (module.startsWith('mrg-smoke') ||
  3251. module.startsWith('mrg-context') ||
  3252. module.startsWith('mrg-honeypot') ||
  3253. module.startsWith('advert') ||
  3254. module.startsWith('mimic') ||
  3255. module.startsWith('OK/banner') ||
  3256. module === 'OK/Smokescreen') {
  3257. let fun = args[args.length-1];
  3258. fun._name = module;
  3259. args[args.length-1] = new Proxy(fun, redefiner);
  3260. }// else
  3261. // _console.log('Define:', args[0]);
  3262. return target.apply(thisArg, args);
  3263. }
  3264. };
  3265. let wrapDefine = def => {
  3266. if (!def)
  3267. return;
  3268. _console.log('define =', def);
  3269. def = new Proxy(def, wrapAdFuncs);
  3270. def._name = 'define';
  3271. return def;
  3272. };
  3273. let _define = wrapDefine(win.define);
  3274. Object.defineProperty(win, 'define', {
  3275. get: () => _define,
  3276. set: x => {
  3277. if (_define === x)
  3278. return true;
  3279. _define = wrapDefine(x);
  3280. return true;
  3281. }
  3282. });
  3283. }
  3284.  
  3285. let _honeyPot;
  3286. function defineDetector(mr) {
  3287. let __ = mr._ || {};
  3288. let setHoneyPot = o => {
  3289. if (!o || o === _honeyPot) return;
  3290. _console.log('[honeyPot]', o);
  3291. _honeyPot = function() {
  3292. this.check = new Proxy(() => {
  3293. __.STUCK_IN_POT = false;
  3294. return false;
  3295. }, logger);
  3296. this.check._name = 'honeyPot.check';
  3297. this.destroy = () => null;
  3298. };
  3299. };
  3300. if ('honeyPot' in mr)
  3301. setHoneyPot(mr.honeyPot);
  3302. else
  3303. Object.defineProperty(mr, 'honeyPot', {
  3304. get: () => _honeyPot,
  3305. set: setHoneyPot
  3306. });
  3307.  
  3308. __ = new Proxy(__, {
  3309. get: (t, p) => t[p],
  3310. set: (t, p, v) => {
  3311. _console.log(`mr._.${p} =`, v);
  3312. t[p] = v;
  3313. return true;
  3314. }
  3315. });
  3316. mr._ = __;
  3317. }
  3318.  
  3319. function defineAdd(mr) {
  3320. let _add;
  3321. let addWrapper = {
  3322. apply: (tgt, that, args) => {
  3323. let module = args[0];
  3324. if (typeof module === 'string' && module.startsWith('ad')) {
  3325. _console.log('Skip module:', module);
  3326. return;
  3327. }
  3328. if (typeof module === 'object' && module.name.startsWith('ad'))
  3329. _console.log('Loaded module:', module);
  3330. return logger.apply(tgt, that, args);
  3331. }
  3332. };
  3333. let setMrAdd = v => {
  3334. if (!v) return;
  3335. v._name = 'mr.add';
  3336. v = new Proxy(v, addWrapper);
  3337. _add = v;
  3338. };
  3339. if ('add' in mr)
  3340. setMrAdd(mr.add);
  3341. Object.defineProperty(mr, 'add', {
  3342. get: () => _add,
  3343. set: setMrAdd
  3344. });
  3345.  
  3346. }
  3347.  
  3348. let _mr_wrapper = vl => {
  3349. defineLocator(vl.mimic ? vl.mimic : vl);
  3350. defineDetector(vl);
  3351. defineAdd(vl);
  3352. return vl;
  3353. };
  3354. if ('mr' in win) {
  3355. _console.log('Found existing "mr" object.');
  3356. win.mr = _mr_wrapper(win.mr);
  3357. } else {
  3358. let _mr = void 0;
  3359. Object.defineProperty(win, 'mr', {
  3360. get: () => _mr,
  3361. set: vl => { _mr = _mr_wrapper(vl) },
  3362. configurable: true
  3363. });
  3364. let _defineProperty = Function.prototype.apply.bind(Object.defineProperty);
  3365. Object.defineProperty = function defineProperty(o, name, conf) {
  3366. if (name === 'mr' && o instanceof Window) {
  3367. _console.warn('Object.defineProperty(', ...arguments, ')');
  3368. conf.set(_mr_wrapper(conf.get()));
  3369. }
  3370. if ((name === 'honeyPot' || name === 'add') && _mr === o && conf.set)
  3371. return;
  3372. return _defineProperty(this, arguments);
  3373. };
  3374. }
  3375.  
  3376. // smokyTools wrapper for news.mail.ru
  3377. nt.define(win, 'smokyTools', nt.proxy({
  3378. getDict: nt.func(nt.proxy({}, 'smokyTools.getDict', null), 'smokyTools.getDict'),
  3379. CSS: nt.func(nt.proxy({}, 'smokyTools.CSS', null), 'smokyTools.CSS')
  3380. }, 'smokyTools', null));
  3381. nt.define(win, 'smoky', nt.func(null, 'smoky'));
  3382. nt.define(win, 'smokySingleElement', nt.func(null, 'smokySingleElement'));
  3383. nt.define(win, 'smokyByClass', nt.func(null, 'smokyByClass'));
  3384. }, nullTools);
  3385. }
  3386. };
  3387.  
  3388. scripts['oms.matchat.online'] = () => scriptLander(() => {
  3389. let _rmpGlobals = void 0;
  3390. Object.defineProperty(win, 'rmpGlobals', {
  3391. get: () => _rmpGlobals,
  3392. set: x => {
  3393. if (x === _rmpGlobals)
  3394. return true;
  3395. _rmpGlobals = new Proxy(x, {
  3396. get: (obj, name) => {
  3397. if (name === 'adBlockerDetected')
  3398. return false;
  3399. return obj[name];
  3400. },
  3401. set: (obj, name, val) => {
  3402. if (name === 'adBlockerDetected')
  3403. _console.warn('rmpGlobals.adBlockerDetected =', val)
  3404. else
  3405. obj[name] = val;
  3406. return true;
  3407. }
  3408. });
  3409. }
  3410. });
  3411. });
  3412.  
  3413. scripts['megogo.net'] = {
  3414. now: () => {
  3415. let nt = new nullTools();
  3416. nt.define(win, 'adBlock', false);
  3417. nt.define(win, 'showAdBlockMessage', nt.func(null));
  3418. }
  3419. };
  3420.  
  3421. scripts['naruto-base.su'] = () => gardener('div[id^="entryID"],.block', /href="http.*?target="_blank"/i);
  3422.  
  3423. scripts['newdeaf-online.net'] = {
  3424. dom: () => {
  3425. let adNodes = _document.querySelectorAll('.ads');
  3426. if (!adNodes)
  3427. return;
  3428. let getter = x => {
  3429. let val = x;
  3430. return () => (_console.warn('read .ads', name, val), val);
  3431. };
  3432. let setter = x => _console.warn('skip write .ads', name, x);
  3433. for (let adNode of adNodes)
  3434. for (let name of ['innerHTML'])
  3435. Object.defineProperty(adNode, name, {
  3436. get: getter(ads[name]),
  3437. set: setter
  3438. });
  3439. }
  3440. };
  3441.  
  3442. scripts['overclockers.ru'] = {
  3443. dom: () => scriptLander(() => {
  3444. let killed = () => _console.warn('Anti-Adblock killed.');
  3445. if ('$' in win)
  3446. win.$ = new Proxy($, {
  3447. apply: (tgt, that, args) => {
  3448. let res = tgt.apply(that, args);
  3449. if (res[0] && res[0] === _document.body) {
  3450. res.html = killed;
  3451. res.empty = killed;
  3452. }
  3453. return res;
  3454. }
  3455. });
  3456. })
  3457. };
  3458. scripts['forums.overclockers.ru'] = {
  3459. now: () => {
  3460. createStyle('.needblock {position: fixed; left: -10000px}');
  3461. Object.defineProperty(win, 'adblck', {
  3462. get: () => 'no',
  3463. set: () => undefined,
  3464. enumerable: true
  3465. });
  3466. }
  3467. };
  3468.  
  3469. scripts['pb.wtf'] = {
  3470. other: ['piratbit.org', 'piratbit.ru'],
  3471. dom: () => {
  3472. // line above topic content and images in the slider in the header
  3473. let remove = node => (_console.log('removed', node), node.parentNode.removeChild(node));
  3474. for (let el of _document.querySelectorAll('.release-block-img a, #page_content a')) {
  3475. if (location.hostname === el.hostname &&
  3476. /^\/(\w{3}|exit)\/[\w=/]{20,}$/.test(el.pathname)) {
  3477. remove(el.closest('div, tr'));
  3478. continue;
  3479. }
  3480. // ads in the topic header in case filter above wasn't enough
  3481. let parent = el.closest('tr');
  3482. if (parent) {
  3483. let span = (parent.querySelector('span') || {}).textContent;
  3484. span && span.startsWith('YO!') && remove(parent);
  3485. }
  3486. }
  3487. // casino ad button in random places
  3488. for (let el of _document.querySelectorAll('.btn-group')) {
  3489. el = el.parentNode;
  3490. if (el.tagName === 'CENTER')
  3491. remove(el.parentNode);
  3492. }
  3493. // ads in comments
  3494. let el = _document.querySelector('thead + tbody[id^="post_"] + tbody[class*=" "]');
  3495. if (el && el.parentNode.children[2] == el)
  3496. remove(el);
  3497. }
  3498. };
  3499.  
  3500. scripts['pikabu.ru'] = () => gardener('.story', /story__author[^>]+>ads</i, {root: '.inner_wrap', observe: true});
  3501.  
  3502. scripts['peka2.tv'] = () => {
  3503. let bodyClass = 'body--branding';
  3504. let checkNode = node => {
  3505. for (let className of node.classList)
  3506. if (className.includes('banner') || className === bodyClass) {
  3507. _removeAttribute(node, 'style');
  3508. node.classList.remove(className);
  3509. for (let attr of Array.from(node.attributes))
  3510. if (attr.name.startsWith('advert'))
  3511. _removeAttribute(node, attr.name);
  3512. }
  3513. };
  3514. (new MutationObserver(ms => {
  3515. let m, node;
  3516. for (m of ms) for (node of m.addedNodes)
  3517. if (node instanceof HTMLElement)
  3518. checkNode(node);
  3519. })).observe(_de, {childList: true, subtree: true});
  3520. (new MutationObserver(ms => {
  3521. for (let m of ms)
  3522. checkNode(m.target);
  3523. })).observe(_de, {attributes: true, subtree: true, attributeFilter: ['class']});
  3524. };
  3525.  
  3526. scripts['qrz.ru'] = {
  3527. now: () => {
  3528. let nt = new nullTools();
  3529. nt.define(win, 'ab', false);
  3530. nt.define(win, 'tryMessage', nt.func(null));
  3531. }
  3532. };
  3533.  
  3534. scripts['razlozhi.ru'] = {
  3535. now: () => {
  3536. let nt = new nullTools();
  3537. nt.define(win, 'cadb', false);
  3538. for (let func of ['createShadowRoot', 'attachShadow'])
  3539. if (func in _Element)
  3540. _Element[func] = function(){
  3541. return this.cloneNode();
  3542. };
  3543. }
  3544. };
  3545.  
  3546. scripts['rbc.ru'] = {
  3547. other: ['autonews.ru', 'rbcplus.ru', 'sportrbc.ru'],
  3548. now: () => {
  3549. selectiveCookies('adb_on');
  3550. let _RA = void 0;
  3551. let setArgs = {
  3552. 'showBanners': true,
  3553. 'showAds': true,
  3554. 'banners.staticPath': '',
  3555. 'paywall.staticPath': '',
  3556. 'banners.dfp.config': [],
  3557. 'banners.dfp.pageTargeting': () => null,
  3558. };
  3559. Object.defineProperty(win, 'RA', {
  3560. get: () => _RA,
  3561. set: vl => {
  3562. _console.log('RA =', vl);
  3563. if ('repo' in vl) {
  3564. _console.log('RA.repo =', vl.repo);
  3565. vl.repo = new Proxy(vl.repo, {
  3566. set: (o, name, val) => {
  3567. if (name === 'banner') {
  3568. _console.log(`RA.repo.${name} =`, val);
  3569. val = new Proxy(val, {
  3570. get: (o, name) => {
  3571. let res = o[name];
  3572. if (typeof o[name] === 'function') {
  3573. res = () => null;
  3574. res.toString = o[name].toString.bind(o[name]);
  3575. }
  3576. if (name === 'isInited')
  3577. res = true;
  3578. _console.warn(`get RA.repo.banner.${name}`, res);
  3579. return res;
  3580. }
  3581. });
  3582. }
  3583. o[name] = val;
  3584. return true;
  3585. }
  3586. });
  3587. } else
  3588. _console.log('Unable to locate RA.repo');
  3589. _RA = new Proxy(vl, {
  3590. set: (o, name, val) => {
  3591. if (name === 'config') {
  3592. _console.log('RA.config =', val);
  3593. if ('set' in val) {
  3594. val.set = new Proxy(val.set, {
  3595. apply: (set, that, args) => {
  3596. let name = args[0];
  3597. if (name in setArgs)
  3598. args[1] = setArgs[name];
  3599. if (name in setArgs || name === 'checkad')
  3600. _console.log('RA.config.set(', ...args, ')');
  3601. return Reflect.apply(set, that, args);
  3602. }
  3603. });
  3604. val.set('showAds', true); // pretend ads already were shown
  3605. }
  3606. }
  3607. o[name] = val;
  3608. return true;
  3609. }
  3610. });
  3611. }
  3612. });
  3613. Object.defineProperty(win, 'bannersConfig', {
  3614. get: () => [], set: () => null
  3615. });
  3616. // pretend there is a paywall landing on screen already
  3617. let pwl = _document.createElement('div');
  3618. pwl.style.display = 'none';
  3619. pwl.className = 'js-paywall-landing';
  3620. _document.documentElement.appendChild(pwl);
  3621. // detect and skip execution of one of the ABP detectors
  3622. let _setTimeout = Function.prototype.apply.bind(win.setTimeout);
  3623. let _toString = Function.prototype.call.bind(Function.prototype.toString);
  3624. win.setTimeout = function setTimeout() {
  3625. if (typeof arguments[0] === 'function') {
  3626. let fts = _toString(arguments[0]);
  3627. if (/\.length\s*>\s*0\s*&&/.test(fts) && /:hidden/.test(fts)) {
  3628. _console.log('Skipped setTimout(', fts, arguments[1], ')');
  3629. return;
  3630. }
  3631. }
  3632. return _setTimeout(this, arguments);
  3633. };
  3634. // hide banner placeholders
  3635. createStyle('[data-banner-id], .banner__container, .banners__yandex__article { display: none !important }');
  3636. },
  3637. dom: () => {
  3638. // hide sticky banner place at the top of the page
  3639. for (let itm of _document.querySelectorAll('.l-sticky'))
  3640. if (itm.querySelector('.banner__container__link'))
  3641. itm.style.display = 'none';
  3642. }
  3643. };
  3644.  
  3645. scripts['rp5.ru'] = {
  3646. other: ['rp5.by', 'rp5.kz', 'rp5.ua'],
  3647. now: () => {
  3648. Object.defineProperty(win, 'sContentBottom', {
  3649. get: () => '',
  3650. set: () => true
  3651. });
  3652. },
  3653. dom: () => {
  3654. let node = selectNodeByTextContent('Разместить текстовое объявление', { root: _de.querySelector('#content-wrapper'), shallow: true });
  3655. if (node)
  3656. node.style.display = 'none';
  3657. }
  3658. };
  3659.  
  3660. scripts['rutube.ru'] = () => scriptLander(() => {
  3661. let _parse = JSON.parse;
  3662. let _skip_enabled = false;
  3663. JSON.parse = (...args) => {
  3664. let res = _parse(...args),
  3665. log = false;
  3666. if (!res)
  3667. return res;
  3668. // parse player configuration
  3669. if ('appearance' in res || 'video_balancer' in res) {
  3670. log = true;
  3671. if (res.appearance) {
  3672. if ('forbid_seek' in res.appearance && res.appearance.forbid_seek)
  3673. res.appearance.forbid_seek = false;
  3674. if ('forbid_timeline_preview' in res.appearance && res.appearance.forbid_timeline_preview)
  3675. res.appearance.forbid_timeline_preview = false;
  3676. }
  3677. _skip_enabled = !!res.remove_unseekable_blocks;
  3678. //res.advert = [];
  3679. delete res.advert;
  3680. //for (let limit of res.limits)
  3681. // limit.limit = 0;
  3682. delete res.limits;
  3683. //res.yast = null;
  3684. //res.yast_live_online = null;
  3685. delete res.yast;
  3686. delete res.yast_live_online;
  3687. Object.defineProperty(res, 'stat', {
  3688. get: () => [],
  3689. set: () => true,
  3690. enumerable: true
  3691. });
  3692. }
  3693.  
  3694. // parse video configuration
  3695. if ('video_url' in res) {
  3696. log = true;
  3697. if (res.cuepoints && !_skip_enabled)
  3698. for (let point of res.cuepoints) {
  3699. point.is_pause = false;
  3700. point.show_navigation = true;
  3701. point.forbid_seek = false;
  3702. }
  3703. }
  3704.  
  3705. if (log)
  3706. _console.log('[rutube]', res);
  3707. return res;
  3708. };
  3709. });
  3710.  
  3711. scripts['simpsonsua.com.ua'] = {
  3712. other: ['simpsonsua.tv'],
  3713. now: () => scriptLander(() => {
  3714. let _addEventListener = _Document.addEventListener;
  3715. _document.addEventListener = function(event, callback) {
  3716. if (event === 'DOMContentLoaded' && callback.toString().includes('show_warning'))
  3717. return;
  3718. return _addEventListener.apply(this, arguments);
  3719. };
  3720. let nt = new nullTools();
  3721. nt.define(win, 'need_warning', 0);
  3722. }, nullTools)
  3723. };
  3724.  
  3725. scripts['smotretanime.ru'] = () => scriptLander(() => {
  3726. deepWrapAPI(root => {
  3727. let _pause = root.Function.prototype.call.bind(root.Audio.prototype.pause);
  3728. let _addEventListener = root.Function.prototype.call.bind(root.Element.prototype.addEventListener);
  3729. let stopper = e => _pause(e.target);
  3730. root.Audio = new Proxy(root.Audio, {
  3731. construct: (audio, args) => {
  3732. let res = new audio(...args);
  3733. _addEventListener(res, 'play', stopper, true);
  3734. return res;
  3735. }
  3736. });
  3737. _createElement = root.Document.prototype.createElement;
  3738. root.Document.prototype.createElement = function createElement() {
  3739. let res = _createElement.apply(this, arguments);
  3740. if (res instanceof HTMLAudioElement)
  3741. _addEventListener(res, 'play', stopper, true);
  3742. return res;
  3743. };
  3744. });
  3745. }, deepWrapAPI);
  3746.  
  3747. scripts['spaces.ru'] = () => {
  3748. gardener('div:not(.f-c_fll) > a[href*="spaces.ru/?Cl="]', /./, { parent: 'div' });
  3749. gardener('.js-banner_rotator', /./, { parent: '.widgets-group' });
  3750. };
  3751.  
  3752. scripts['spam-club.blogspot.co.uk'] = () => {
  3753. let _clientHeight = Object.getOwnPropertyDescriptor(_Element, 'clientHeight'),
  3754. _clientWidth = Object.getOwnPropertyDescriptor(_Element, 'clientWidth');
  3755. let wrapGetter = (getter) => {
  3756. let _getter = getter;
  3757. return function() {
  3758. let _size = _getter.apply(this, arguments);
  3759. return _size ? _size : 1;
  3760. };
  3761. };
  3762. _clientHeight.get = wrapGetter(_clientHeight.get);
  3763. _clientWidth.get = wrapGetter(_clientWidth.get);
  3764. Object.defineProperty(_Element, 'clientHeight', _clientHeight);
  3765. Object.defineProperty(_Element, 'clientWidth', _clientWidth);
  3766. let _onload = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'onload'),
  3767. _set_onload = _onload.set;
  3768. _onload.set = function() {
  3769. if (this instanceof HTMLImageElement)
  3770. return true;
  3771. _set_onload.apply(this, arguments);
  3772. };
  3773. Object.defineProperty(HTMLElement.prototype, 'onload', _onload);
  3774. };
  3775.  
  3776. scripts['sport-express.ru'] = () => gardener('.js-relap__item',/>Реклама\s+<\//, {root:'.container', observe: true});
  3777.  
  3778. scripts['sports.ru'] = {
  3779. now: () => {
  3780. gardener('.aside-news-list__item', /aside-news-list__advert/i, {root:'.columns-layout__left', observe: true});
  3781. gardener('.material-list__item', /Реклама/i, {root:'.columns-layout', observe: true});
  3782. // extra functionality: shows/hides panel at the top depending on scroll direction
  3783. createStyle([
  3784. '.user-panel__fixed { transition: top 0.2s ease-in-out!important; }',
  3785. '.user-panel-up { top: -40px!important }'
  3786. ], {id: 'userPanelSlide'}, false);
  3787. },
  3788. dom: () => {
  3789. (function lookForPanel() {
  3790. let panel = _document.querySelector('.user-panel__fixed');
  3791. if (!panel)
  3792. setTimeout(lookForPanel, 100);
  3793. else
  3794. window.addEventListener(
  3795. 'wheel', function(e) {
  3796. if (e.deltaY > 0 && !panel.classList.contains('user-panel-up'))
  3797. panel.classList.add('user-panel-up');
  3798. else if (e.deltaY < 0 && panel.classList.contains('user-panel-up'))
  3799. panel.classList.remove('user-panel-up');
  3800. }, false
  3801. );
  3802. })();
  3803. }
  3804. };
  3805.  
  3806. scripts['stealthz.ru'] = {
  3807. dom: () => {
  3808. // skip timeout
  3809. let $ = _document.querySelector.bind(_document);
  3810. let [timer_1, timer_2] = [$('#timer_1'), $('#timer_2')];
  3811. if (!timer_1 || !timer_2)
  3812. return;
  3813. timer_1.style.display = 'none';
  3814. timer_2.style.display = 'block';
  3815. }
  3816. };
  3817.  
  3818. scripts['xittv.net'] = () => scriptLander(() => {
  3819. let logNames = ['setup', 'trigger', 'on', 'off', 'onReady', 'onError', 'getConfig', 'addPlugin', 'getAdBlock'];
  3820. let skipEvents = ['adComplete', 'adSkipped', 'adBlock', 'adRequest', 'adMeta', 'adImpression', 'adError', 'adTime', 'adStarted', 'adClick'];
  3821. let _jwplayer = void 0;
  3822. Object.defineProperty(win, 'jwplayer', {
  3823. get: () => _jwplayer,
  3824. set: x => {
  3825. _jwplayer = new Proxy(x, {
  3826. apply: (fun, that, args) => {
  3827. let res = fun.apply(that, args);
  3828. res = new Proxy(res, {
  3829. get: (obj, name) => {
  3830. if (logNames.includes(name) && obj[name] instanceof Function)
  3831. return new Proxy(obj[name], {
  3832. apply: (fun, that, args) => {
  3833. if (name === 'setup') {
  3834. let o = args[0];
  3835. if (o)
  3836. delete o.advertising;
  3837. }
  3838. if (name === 'on' || name === 'trigger') {
  3839. let events = typeof args[0] === 'string' ? args[0].split(" ") : null;
  3840. if (events.length === 1 && skipEvents.includes(events[0]))
  3841. return res;
  3842. if (events.length > 1) {
  3843. let names = [];
  3844. for (let event of events)
  3845. if (!skipEvents.includes(event))
  3846. names.push(event);
  3847. if (names.length > 0)
  3848. args[0] = names.join(" ");
  3849. else
  3850. return res;
  3851. }
  3852. }
  3853. let subres = fun.apply(that, args);
  3854. _console.warn(`jwplayer().${name}(`, ...args, `) >>`, res);
  3855. return subres;
  3856. }
  3857. });
  3858. return obj[name];
  3859. }
  3860. });
  3861. return res;
  3862. }
  3863. });
  3864. _console.log('jwplayer =', x);
  3865. }
  3866. });
  3867. });
  3868.  
  3869. scripts['yap.ru'] = {
  3870. other: ['yaplakal.com'],
  3871. now: () => {
  3872. gardener('form > table[id^="p_row_"]:nth-of-type(2)', /member1438|Administration/);
  3873. gardener('.icon-comments', /member1438|Administration|\/go\/\?http/, {parent:'tr', siblings:-2});
  3874. }
  3875. };
  3876.  
  3877. scripts['rambler.ru'] = {
  3878. other: ['championat.com', 'gazeta.ru', 'lenta.ru', 'media.eagleplatform.com', 'quto.ru', 'rns.online'],
  3879. now: () => {
  3880. selectiveCookies('detect_count');
  3881. scriptLander(() => {
  3882. // Prevent autoplay
  3883. if (!('EaglePlayer' in win)) {
  3884. let _EaglePlayer = void 0;
  3885. Object.defineProperty(win, 'EaglePlayer', {
  3886. enumerable: true,
  3887. get: () => _EaglePlayer,
  3888. set: x => {
  3889. if (x === _EaglePlayer)
  3890. return true;
  3891. _EaglePlayer = new Proxy(x, {
  3892. construct: (targ, args) => {
  3893. let player = new targ(...args);
  3894. if (!player.options) {
  3895. _console.log('EaglePlayer: no options', EaglePlayer);
  3896. return player;
  3897. }
  3898. Object.defineProperty(player.options, 'autoplay', {
  3899. get: () => false,
  3900. set: () => true
  3901. });
  3902. Object.defineProperty(player.options, 'scroll', {
  3903. get: () => false,
  3904. set: () => true
  3905. });
  3906. return player;
  3907. }
  3908. });
  3909. }
  3910. });
  3911. let _setAttribute = Function.prototype.apply.bind(_Element.setAttribute);
  3912. let isAutoplay = /^autoplay$/i;
  3913. _Element.setAttribute = function setAttribute(name) {
  3914. if (!this._stopped && isAutoplay.test(name)) {
  3915. _console.log('Prevented assigning autoplay attribute.');
  3916. return null;
  3917. }
  3918. return _setAttribute(this, arguments);
  3919. };
  3920. } else {
  3921. _console.log('EaglePlayer function already exists.');
  3922. if (inIFrame) {
  3923. let _setAttribute = Function.prototype.apply.bind(_Element.setAttribute);
  3924. let isAutoplay = /^autoplay$/i;
  3925. _Element.setAttribute = function setAttribute(name) {
  3926. if (!this._stopped && isAutoplay.test(name)) {
  3927. _console.log('Prevented assigning autoplay attribute.');
  3928. this._stopped = true;
  3929. this.play = () => {
  3930. _console.log('Prevented attempt to force-start playback.');
  3931. delete this.play;
  3932. };
  3933. return null;
  3934. }
  3935. return _setAttribute(this, arguments);
  3936. };
  3937. }
  3938. }
  3939. if (location.hostname.endsWith('.media.eagleplatform.com'))
  3940. return;
  3941. let nt = new nullTools();
  3942. // Adblock Detector
  3943. let flamethrower = () => { throw 'Adblock Detector' };
  3944. Object.defineProperty(win, 'QW50aS1BZEJsb2Nr', { set: flamethrower, get: flamethrower });
  3945. // prevent ads from loading
  3946. let blockPatterns = /\[[a-z]{4}\("0x[\da-f]+"\)\]|\.(rnet\.plus|24smi\.net|infox\.sg|lentainform\.com)\//i;
  3947. let _toString = Function.prototype.call.bind(Function.prototype.toString);
  3948. let _setTimeout = win.setTimeout;
  3949. win.setTimeout = function(f) {
  3950. if (blockPatterns.test(_toString(f))) {
  3951. _console.warn('Stopped setTimeout for:', _toString(f).slice(0,100), '\u2026');
  3952. return null;
  3953. };
  3954. return _setTimeout.apply(this, arguments);
  3955. };
  3956. // fake global Adf object
  3957. let Adf_banner = {};
  3958. [
  3959. 'reloadssp', 'sspScroll',
  3960. 'sspRich', 'ssp'
  3961. ].forEach(name => void(Adf_banner[name] = nt.proxy(() => new Promise(r => r({status: true})))));
  3962. nt.define(win, 'Adf', nt.proxy({
  3963. banner: nt.proxy(Adf_banner)
  3964. }));
  3965. // extra script to remove partner news on gazeta.ru
  3966. if (!location.hostname.includes('gazeta.ru'))
  3967. return;
  3968. (new MutationObserver(
  3969. (ms) => {
  3970. let m, node, header;
  3971. for (m of ms) for (node of m.addedNodes)
  3972. if (node instanceof HTMLDivElement && node.matches('.sausage')) {
  3973. header = node.querySelector('.sausage-header');
  3974. if (header && /новости\s+партн[её]ров/i.test(header.textContent))
  3975. node.style.display = 'none';
  3976. }
  3977. }
  3978. )).observe(_document.documentElement, { childList:true, subtree: true });
  3979. }, `let inIFrame = ${inIFrame}`, nullTools)
  3980. }
  3981. };
  3982.  
  3983. scripts['reactor.cc'] = {
  3984. other: ['joyreactor.cc', 'pornreactor.cc'],
  3985. now: () => {
  3986. selectiveEval();
  3987. scriptLander(() => {
  3988. let nt = new nullTools();
  3989. win.open = function(){
  3990. throw new Error('Redirect prevention.');
  3991. };
  3992. nt.define(win, 'Worker', function(){});
  3993. nt.define(win, 'JRCH', win.CoinHive);
  3994. }, nullTools);
  3995. },
  3996. click: function(e) {
  3997. let node = e.target;
  3998. if (node.nodeType === _Node.ELEMENT_NODE &&
  3999. node.style.position === 'absolute' &&
  4000. node.style.zIndex > 0)
  4001. node.parentNode.removeChild(node);
  4002. },
  4003. dom: function() {
  4004. let tid = void 0;
  4005. function probe() {
  4006. let node = selectNodeByTextContent('блокировщик рекламы');
  4007. if (!node) return;
  4008. while (node.parentNode.offsetHeight < 750 && node !== _document.body)
  4009. node = node.parentNode;
  4010. _setAttribute(node, 'style', 'background:none!important');
  4011. // stop observer
  4012. if (!tid) tid = setTimeout(() => this.disconnect(), 1000);
  4013. }
  4014. (new MutationObserver(probe))
  4015. .observe(_document, { childList:true, subtree:true });
  4016. }
  4017. };
  4018.  
  4019. scripts['auto.ru'] = () => {
  4020. let words = /Реклама|Яндекс.Директ|yandex_ad_/;
  4021. let userAdsListAds = (
  4022. '.listing-list > .listing-item,'+
  4023. '.listing-item_type_fixed.listing-item'
  4024. );
  4025. let catalogAds = (
  4026. 'div[class*="layout_catalog-inline"],'+
  4027. 'div[class$="layout_horizontal"]'
  4028. );
  4029. let otherAds = (
  4030. '.advt_auto,'+
  4031. '.sidebar-block,'+
  4032. '.pager-listing + div[class],'+
  4033. '.card > div[class][style],'+
  4034. '.sidebar > div[class],'+
  4035. '.main-page__section + div[class],'+
  4036. '.listing > tbody'
  4037. );
  4038. gardener(userAdsListAds, words, {root:'.listing-wrap', observe:true});
  4039. gardener(catalogAds, words, {root:'.catalog__page,.content__wrapper', observe:true});
  4040. gardener(otherAds, words);
  4041. };
  4042.  
  4043. scripts['rsload.net'] = {
  4044. load: () => {
  4045. let dis = _document.querySelector('label[class*="cb-disable"]');
  4046. if (dis)
  4047. dis.click();
  4048. },
  4049. click: e => {
  4050. let t = e.target;
  4051. if (t && t.href && (/:\/\/\d+\.\d+\.\d+\.\d+\//.test(t.href)))
  4052. t.href = t.href.replace('://','://rsload.net:rsload.net@');
  4053. }
  4054. };
  4055.  
  4056. let domain;
  4057. // add alternative domain names if present and wrap functions into objects
  4058. for (let name in scripts) {
  4059. if (scripts[name] instanceof Function)
  4060. scripts[name] = { now: scripts[name] };
  4061. for (domain of (scripts[name].other||[])) {
  4062. if (domain in scripts)
  4063. _console.log('Error in scripts list. Script for', name, 'replaced script for', domain);
  4064. scripts[domain] = scripts[name];
  4065. }
  4066. delete scripts[name].other;
  4067. }
  4068. // look for current domain in the list and run appropriate code
  4069. domain = _document.domain;
  4070. while (domain.includes('.')) {
  4071. if (domain in scripts) for (let when in scripts[domain])
  4072. switch(when) {
  4073. case 'now':
  4074. scripts[domain][when]();
  4075. break;
  4076. case 'dom':
  4077. _document.addEventListener('DOMContentLoaded', scripts[domain][when], false);
  4078. break;
  4079. default:
  4080. _document.addEventListener (when, scripts[domain][when], false);
  4081. }
  4082. domain = domain.slice(domain.indexOf('.') + 1);
  4083. }
  4084.  
  4085. // Batch script lander
  4086. if (!skipLander)
  4087. landScript(batchLand, batchPrepend);
  4088.  
  4089. { // JS Fixes Tools Menu
  4090. let openOptions = function() {
  4091. let ovl = _createElement('div'),
  4092. inner = _createElement('div');
  4093. ovl.style = (
  4094. 'position: fixed;'+
  4095. 'top:0; left:0;'+
  4096. 'bottom: 0; right: 0;'+
  4097. 'background: rgba(0,0,0,0.85);'+
  4098. 'z-index: 2147483647;'+
  4099. 'padding: 5em'
  4100. );
  4101. inner.style = (
  4102. 'background: whitesmoke;'+
  4103. 'font-size: 10pt;'+
  4104. 'color: black;'+
  4105. 'padding: 1em'
  4106. );
  4107. inner.textContent = 'JS Fixes Tools';
  4108. inner.appendChild(_createElement('br'));
  4109. inner.appendChild(_createElement('br'));
  4110. ovl.addEventListener(
  4111. 'click', function(e) {
  4112. if (e.target === ovl) {
  4113. ovl.parentNode.removeChild(ovl);
  4114. e.preventDefault();
  4115. }
  4116. e.stopPropagation();
  4117. }, false
  4118. );
  4119.  
  4120. let sObjBtn = _createElement('button');
  4121. sObjBtn.onclick = getStrangeObjectsList;
  4122. sObjBtn.textContent = 'Print (in console) list of unusual window properties';
  4123. inner.appendChild(_createElement('br'));
  4124. inner.appendChild(sObjBtn);
  4125.  
  4126. _document.body.appendChild(ovl);
  4127. ovl.appendChild(inner);
  4128. };
  4129.  
  4130. // monitor keys pressed for Ctrl+Alt+Shift+J > s > f code
  4131. let opPos = 0, opKey = ['KeyJ','KeyS','KeyF'];
  4132. _document.addEventListener(
  4133. 'keydown', function(e) {
  4134. if ((e.code === opKey[opPos] || e.location) &&
  4135. (!!opPos || e.altKey && e.ctrlKey && e.shiftKey)) {
  4136. opPos += e.location ? 0 : 1;
  4137. e.stopPropagation();
  4138. e.preventDefault();
  4139. } else
  4140. opPos = 0;
  4141. if (opPos === opKey.length) {
  4142. opPos = 0;
  4143. openOptions();
  4144. }
  4145. }, false
  4146. );
  4147. }
  4148. })();