RU AdList JS Fixes

try to take over the world!

当前为 2020-01-09 提交的版本,查看 最新版本

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