RU AdList JS Fixes

try to take over the world!

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

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