RU AdList JS Fixes

try to take over the world!

目前为 2019-06-18 提交的版本,查看 最新版本

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