RU AdList JS Fixes

try to take over the world!

目前為 2019-07-30 提交的版本,檢視 最新版本

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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址