RU AdList JS Fixes

try to take over the world!

当前为 2019-07-16 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name RU AdList JS Fixes
  3. // @namespace ruadlist_js_fixes
  4. // @version 20190716.0
  5. // @description try to take over the world!
  6. // @author lainverse & dimisa
  7. // @supportURL https://greasyfork.org/en/scripts/19993-ru-adlist-js-fixes/feedback
  8. // @match *://*/*
  9. // @exclude *://auth.wi-fi.ru/*
  10. // @exclude *://*.alfabank.ru/*
  11. // @exclude *://alfabank.ru/*
  12. // @exclude *://*.unicreditbanking.net/*
  13. // @exclude *://unicreditbanking.net/*
  14. // @exclude *://*.telegram.org/*
  15. // @exclude *://telegram.org/*
  16. // @grant unsafeWindow
  17. // @grant window.close
  18. // @run-at document-start
  19. // ==/UserScript==
  20.  
  21. (function() {
  22. 'use strict';
  23.  
  24. let win = (unsafeWindow || window);
  25.  
  26. // MooTools are crazy enough to replace standard browser object window.Document: https://mootools.net/core
  27. // Occasionally their code runs before my script on some domains and causes all kinds of havoc.
  28. let _Document = Object.getPrototypeOf(HTMLDocument.prototype);
  29. let _Element = Object.getPrototypeOf(HTMLElement.prototype);
  30. // dTree 2.05 in some cases replaces Node object
  31. let _Node = Object.getPrototypeOf(_Element);
  32. let _console = {};
  33. for (let name in win.console) _console[name] = console[name];
  34. Object.defineProperty(win.console, 'clear', { value: () => null });
  35.  
  36. // http://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser
  37. let isOpera = (!!window.opr && !!window.opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0,
  38. isChrome = !!window.chrome && !!window.chrome.webstore,
  39. isSafari =
  40. Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0 ||
  41. (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window.safari || window.safari.pushNotification);
  42. let isFirefox = 'InstallTrigger' in win;
  43. let inIFrame = (win.self !== win.top);
  44. let _getAttribute = Function.prototype.call.bind(_Element.getAttribute),
  45. _setAttribute = Function.prototype.call.bind(_Element.setAttribute),
  46. _removeAttribute = Function.prototype.call.bind(_Element.removeAttribute);
  47. let _document = win.document,
  48. _de = _document.documentElement,
  49. _appendChild = _Document.appendChild.bind(_de),
  50. _removeChild = _Document.removeChild.bind(_de),
  51. _createElement = _Document.createElement.bind(_document),
  52. _querySelector = _Document.querySelector.bind(_document),
  53. _querySelectorAll = _Document.querySelectorAll.bind(_document);
  54.  
  55. if (isFirefox && // Exit on image pages in Fx
  56. _document.constructor.prototype.toString() === '[object ImageDocumentPrototype]')
  57. return;
  58.  
  59. // NodeList and HTMLCollection iterator polyfill
  60. // required for old versions of Safari and Chrome 49 (last available for WinXP)
  61. // https://jakearchibald.com/2014/iterators-gonna-iterate/
  62. if (!NodeList.prototype[Symbol.iterator])
  63. NodeList.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
  64. if (!HTMLCollection.prototype[Symbol.iterator])
  65. HTMLCollection.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
  66.  
  67. // Wrapper to run scripts designed to override objects available to other scripts
  68. // Required in old versions of Firefox (<58) or when running with Greasemonkey
  69. let skipLander = true;
  70. try {
  71. skipLander = !(isFirefox && ('StopIteration' in win || GM.info.scriptHandler === 'Greasemonkey'));
  72. } catch(ignore){}
  73. let batchLand = [];
  74. let batchPrepend = [];
  75. let _APIString = 'let win = window, _console = {}; for (let name in win.console) _console[name] = console[name]; '+
  76. 'let _document = win.document, _Document = Object.getPrototypeOf(HTMLDocument.prototype),'+
  77. ' _Element = Object.getPrototypeOf(HTMLElement.prototype), _Node = Object.getPrototypeOf(_Element);';
  78. let landScript = (f, pre) => {
  79. let script = _createElement('script');
  80. script.textContent = `(()=>{${_APIString}${(
  81. (pre.length > 0 ? pre.join(';') : '')
  82. )};(${f.join(')();(')})();})();`;
  83. _appendChild(script);
  84. _removeChild(script);
  85. };
  86. let scriptLander = f => f();
  87. if (!skipLander) {
  88. scriptLander = (func, ...prepend) => {
  89. prepend.forEach(
  90. x => batchPrepend.includes(x) ? null : batchPrepend.push(x)
  91. );
  92. batchLand.push(func);
  93. };
  94. _document.addEventListener(
  95. 'DOMContentLoaded', () => void (scriptLander = (f, ...prep) => landScript([f], prep)), false
  96. );
  97. }
  98.  
  99. function nullTools(opts) {
  100. let nt = this;
  101. opts = opts || {};
  102. let log = (...args) => opts.log && _console.log(...args);
  103. let warn = (...args) => _console.warn(...args);
  104. let trace = (...args) => (opts.log || opts.trace) && warn(...args);
  105.  
  106. nt.destroy = function(o, destroy) {
  107. if (!opts.destroy && !destroy && o instanceof Object)
  108. return;
  109. log('cleaning', o);
  110. try {
  111. for (let item in o) {
  112. if (item instanceof Object)
  113. nt.destroy(item);
  114. delete o[item];
  115. }
  116. } catch (e) {
  117. log('Error in object destructor', e);
  118. }
  119. };
  120.  
  121. nt.define = function(obj, prop, val, enumerable = true) {
  122. try {
  123. Object.defineProperty(
  124. obj, prop, {
  125. get: () => val,
  126. set: v => {
  127. if (v !== val) {
  128. log(`set ${prop} of`, obj, 'to', v);
  129. nt.destroy(v);
  130. }
  131. },
  132. enumerable: enumerable
  133. }
  134. );
  135. } catch (err) {
  136. _console.log(`Unable to redefine "${prop}" in `, obj, err);
  137. }
  138. };
  139. nt.proxy = function(obj, missingFuncParentName, missingFuncValue) {
  140. return new Proxy(
  141. obj, {
  142. get: (t, p) => {
  143. if (p in t)
  144. return t[p];
  145. if (typeof p === 'symbol') {
  146. if (p === Symbol.toPrimitive)
  147. t[p] = function(hint) {
  148. if (hint === 'string')
  149. return Object.prototype.toString.call(this);
  150. return `[missing toPrimitive] ${name} ${hint}`;
  151. };
  152. else {
  153. t[p] = void 0;
  154. _console.warn('Missing', p, missingFuncParentName ? `in ${missingFuncParentName}` : '', '>>', t[p]);
  155. }
  156. return t[p];
  157. }
  158. if (missingFuncParentName) {
  159. t[p] = nt.func(missingFuncValue, `${missingFuncParentName}.${p}`);
  160. return t[p];
  161. }
  162. _console.warn(`Missing ${p} in`, t);
  163. },
  164. set: (t, p, v) => {
  165. if (v !== t[p]) {
  166. log(`set ${p} of`, t, 'to', v);
  167. nt.destroy(v);
  168. }
  169. return true;
  170. }
  171. }
  172. );
  173. };
  174. nt.func = (val, name = '', force_log = false) => nt.proxy((...args) => {
  175. (force_log ? warn : trace)(`call ${name}(`, ...args,`) return`, val);
  176. return val;
  177. });
  178. }
  179.  
  180. // Creates and return protected style (unless protection is manually disabled).
  181. // Protected style will re-add itself on removal and remaind enabled on attempt to disable it.
  182. function createStyle(rules, props, skip_protect) {
  183. props = props || {};
  184. props.type = 'text/css';
  185.  
  186. function _protect(style) {
  187. if (skip_protect)
  188. return;
  189.  
  190. Object.defineProperty(style, 'sheet', {
  191. value: null,
  192. enumerable: true
  193. });
  194. Object.defineProperty(style, 'disabled', {
  195. get: () => true, //pretend to be disabled
  196. set: () => undefined,
  197. enumerable: true
  198. });
  199. (new MutationObserver(
  200. (ms) => _removeChild(ms[0].target)
  201. )).observe(style, { childList: true });
  202. }
  203.  
  204.  
  205. function _create() {
  206. let style = _appendChild(_createElement('style'));
  207. Object.assign(style, props);
  208.  
  209. function insertRules(rule) {
  210. if (rule.forEach)
  211. rule.forEach(insertRules);
  212. else try {
  213. style.sheet.insertRule(rule, 0);
  214. } catch (e) {
  215. _console.error(e);
  216. }
  217. }
  218.  
  219. insertRules(rules);
  220. _protect(style);
  221.  
  222. return style;
  223. }
  224.  
  225. let style = _create();
  226. if (skip_protect)
  227. return style;
  228.  
  229. (new MutationObserver(
  230. function(ms) {
  231. let m, node;
  232. let createStyleInANewThread = resolve => setTimeout(
  233. resolve => resolve(_create()),
  234. 0, resolve
  235. );
  236. let setStyle = st => void(style = st);
  237. for (m of ms) for (node of m.removedNodes)
  238. if (node === style)
  239. (new Promise(createStyleInANewThread))
  240. .then(setStyle);
  241. }
  242. )).observe(_de, { childList: true });
  243.  
  244. return style;
  245. }
  246.  
  247. // Fake objects of advertisement networks to break their workflow
  248. // Popular adblock detector
  249. function deployFABStub(root) {
  250. let nt = new nullTools();
  251. if (!('fuckAdBlock' in root)) {
  252. let FuckAdBlock = function(options) {
  253. let self = this;
  254. self._options = {
  255. checkOnLoad: false,
  256. resetOnEnd: false,
  257. checking: false
  258. };
  259. self.setOption = function(opt, val) {
  260. if (val)
  261. self._options[opt] = val;
  262. else
  263. Object.assign(self._options, opt);
  264. };
  265. if (options)
  266. self.setOption(options);
  267.  
  268. self._var = { event: {} };
  269. self.clearEvent = function() {
  270. self._var.event.detected = [];
  271. self._var.event.notDetected = [];
  272. };
  273. self.clearEvent();
  274.  
  275. self.on = function(detected, fun) {
  276. self._var.event[detected?'detected':'notDetected'].push(fun);
  277. return self;
  278. };
  279. self.onDetected = function(cb) {
  280. return self.on(true, cb);
  281. };
  282. self.onNotDetected = function(cb) {
  283. return self.on(false, cb);
  284. };
  285. self.emitEvent = function() {
  286. for (let fun of self._var.event.notDetected)
  287. fun();
  288. if (self._options.resetOnEnd)
  289. self.clearEvent();
  290. return self;
  291. };
  292. self._creatBait = () => null;
  293. self._destroyBait = () => null;
  294. self._checkBait = function() {
  295. setTimeout((() => self.emitEvent()), 1);
  296. };
  297. self.check = function() {
  298. self._checkBait();
  299. return true;
  300. };
  301.  
  302. let callback = function() {
  303. if (self._options.checkOnLoad)
  304. setTimeout(self.check, 1);
  305. };
  306. root.addEventListener('load', callback, false);
  307. };
  308. nt.define(root, 'FuckAdBlock', FuckAdBlock);
  309. nt.define(root, 'fuckAdBlock', new FuckAdBlock({
  310. checkOnLoad: true,
  311. resetOnEnd: true
  312. }));
  313. }
  314. }
  315. // new version of fAB adapting to fake API
  316. // scriptLander(() => deployFABStub(win), nullTools); // so it's disabled by default for now
  317.  
  318. scriptLander(() => {
  319. let nt = new nullTools();
  320.  
  321. // CoinHive miner stub. Continuous 100% CPU load can easily kill some CPU with overheat.
  322. if (!('CoinHive' in win))
  323. if (location.hostname !== 'cnhv.co') {
  324. // CoinHive stub for cases when it doesn't affect site functionality
  325. let CoinHiveConstructor = function() {
  326. _console.warn('Fake CoinHive miner created.');
  327. this.setThrottle = nt.func(null);
  328. this.start = nt.func(null);
  329. this.on = nt.func(null);
  330. this.getHashesPerSecond = nt.func(Infinity);
  331. this.getTotalHashes = nt.func(Infinity);
  332. this.getAcceptedHashes = nt.func(Infinity);
  333. };
  334. let CoinHiveStub = nt.proxy({
  335. Anonymous: CoinHiveConstructor,
  336. User: CoinHiveConstructor,
  337. Token: CoinHiveConstructor,
  338. JobThread: nt.func(null),
  339. Res: nt.func(null),
  340. IF_EXCLUSIVE_TAB: false,
  341. CONFIG: nt.proxy({})
  342. });
  343. nt.define(win, 'CoinHive', CoinHiveStub);
  344. } else {
  345. // CoinHive wrapper to fool sites which expect it to actually work and return results
  346. let CoinHiveObject;
  347. Object.defineProperty(win, 'CoinHive', {
  348. set: function(obj) {
  349. if ('Token' in obj) {
  350. _console.log('[CoinHive] Token wrapper applied.');
  351. let _Token = obj.Token.bind(obj);
  352. obj.Token = function(siteKey, goal, params) {
  353. let _goal = goal;
  354. goal = goal > 256 ? 256 : goal;
  355. _console.log(`[CoinHive] Original goal: ${_goal}, new smaller goal ${goal}.`);
  356. _console.log(`With smaller goals server may return 'invalid_goal' error and stop working.`);
  357. let miner = _Token(siteKey, goal, params);
  358. miner.setThrottle(0.99);
  359. miner.setThrottle = () => null;
  360. let _start = miner.start.bind(miner);
  361. miner.start = function() {
  362. let res = _start(window.CoinHive.FORCE_EXCLUSIVE_TAB);
  363. return res;
  364. };
  365. let _getTotalHashes = miner.getTotalHashes;
  366. miner.getTotalHashes = function() {
  367. return Math.trunc(_getTotalHashes.call(this) / goal * _goal);
  368. };
  369. let __emit = miner._emit;
  370. miner._emit = function(state, props) {
  371. let _self = this;
  372. _console.log('[CoinHive] state:', state, props);
  373. if (state === 'job')
  374. setTimeout(() => {
  375. _self.stop();
  376. _self._emit('accepted', { hashes: goal });
  377. }, 1000);
  378. return __emit.apply(_self, arguments);
  379. };
  380. let _on = miner.on.bind(miner);
  381. miner.on = function(type, callback) {
  382. if (type === 'accepted') {
  383. _console.log('[CoinHive] "accepted" callback wrapper applied.');
  384. let _callback = callback;
  385. callback = function(params) {
  386. _console.log('[CoinHive] "accepted" callback is called, imitating original goal being reached.');
  387. params.hashes = _goal;
  388. return _callback.apply(this, arguments);
  389. };
  390. miner.stop();
  391. }
  392. return _on(type, callback);
  393. };
  394. return miner;
  395. };
  396. }
  397. CoinHiveObject = obj;
  398. },
  399. get: () => CoinHiveObject
  400. });
  401. }
  402.  
  403. // VideoJS player wrapper
  404. VideoJS: {
  405. let _videojs = win.videojs || void 0;
  406. Object.defineProperty(win, 'videojs', {
  407. get: () => _videojs,
  408. set: f => {
  409. if (f === _videojs)
  410. return true;
  411. _console.log('videojs =', f);
  412. _videojs = new Proxy(f, {
  413. apply: (tgt, ths, args) => {
  414. _console.log('videojs(', ...args, ')');
  415. let params = args[1];
  416. if (params) {
  417. if (params.hasAd)
  418. params.hasAd = false;
  419. if (params.autoplay)
  420. params.autoplay = false;
  421. if (params.plugins && params.plugins.vastClient)
  422. delete params.plugins.vastClient;
  423. }
  424. let res = tgt.apply(ths, args);
  425. if (res && res.seed)
  426. res.seed = () => null;
  427. _console.log('player = ', res);
  428. return res;
  429. }
  430. });
  431. }
  432. });
  433. }
  434.  
  435. // Set a little trap for BodyClick ads
  436. Object.defineProperty(win, '__BC_domain', {
  437. set: () => { throw 'BodyClick trap' }
  438. });
  439.  
  440. // Yandex API (ADBTools, Metrika)
  441. let hostname = location.hostname;
  442. if (// Thank you, Greasemonkey, now I have to check for this. -_-
  443. location.protocol === 'about:' ||
  444. // Google likes to define odd global variables like Ya
  445. hostname.startsWith('google.') || hostname.includes('.google.') ||
  446. // Also, Yandex uses their Ya object for a lot of things on their pages and
  447. // wrapping it may cause problems. It's better to skip it in some cases.
  448. ((hostname.startsWith('yandex.') || hostname.includes('.yandex.')) &&
  449. /^\/((yand)?search|images)/i.test(location.pathname) && !hostname.startsWith('news.')) ||
  450. // Also skip on these following sites since they use
  451. // code minification which generated global Ya variable.
  452. hostname.endsWith('chatango.com') || hostname.endsWith('github.io') ||
  453. hostname.endsWith('grimtools.com') || hostname.endsWith('poeplanner.com'))
  454. return;
  455.  
  456. let YaProps = new Set();
  457. function setObfuscatedProperty(Ya, rootProp, obj, name) {
  458. if (YaProps.has(rootProp))
  459. return;
  460. _console.warn(`Ya.${rootProp} = Ya.${name}`);
  461. nt.define(Ya, rootProp, Ya[name]);
  462. YaProps.add(rootProp);
  463. for (let prop in obj)
  464. delete obj[prop];
  465. for (let prop in Ya[name])
  466. obj[prop] = Ya[name][prop];
  467. }
  468. function onObfuscatedProperty (Ya, rootProp, obj) {
  469. if ('AdvManager' in obj || '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://greasyfork.org/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://greasyfork.org/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://greasyfork.org/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://greasyfork.org/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,})$/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. if (allow) {
  1624. block = false;
  1625. _console.warn(`Allowed ${fname} ${method} request:`, url, 'from', root.location.href);
  1626. }
  1627. if (block) {
  1628. if (!blockedUrls.has(url)) // don't repeat log if the same URL were blocked more than once
  1629. _console.warn(`Blocked ${fname} ${method} request:`, url, 'from', root.location.href);
  1630. blockedUrls.add(url);
  1631. return true;
  1632. }
  1633. if (!allow && suspicious.test(url))
  1634. _console.warn(`Suspicious ${fname} ${method} request:`, url, 'from', root.location.href);
  1635. return false;
  1636. }
  1637.  
  1638. // workaround for a broken weather mini-map on Yandex
  1639. let skip_xhr_check = false;
  1640. if (root.location.hostname.startsWith('yandex.') &&
  1641. root.location.pathname.startsWith('/pogoda/') ||
  1642. root.location.hostname.endsWith('.kakprosto.ru'))
  1643. skip_xhr_check = true;
  1644.  
  1645. let xhrStopList = new WeakSet();
  1646. let _open = root.Function.prototype.apply.bind(_proto.open);
  1647. _proto.open = function open() {
  1648. '[native code]';
  1649. return !skip_xhr_check && checkRequest('xhr', ...arguments) ?
  1650. (xhrStopList.add(this), void 0) : _open(this, arguments);
  1651. };
  1652. ['send', 'setRequestHeader', 'getAllResponseHeaders'].forEach(
  1653. name => {
  1654. let func = _proto[name];
  1655. _proto[name] = function(...args) {
  1656. return xhrStopList.has(this) ? null : func.apply(this, args);
  1657. };
  1658. }
  1659. );
  1660. // simulate readyState === 1 for blocked requests
  1661. let _readyState = Object.getOwnPropertyDescriptor(_proto, 'readyState');
  1662. let _get_readyState = root.Function.prototype.apply.bind(_readyState.get);
  1663. _readyState.get = function() {
  1664. return xhrStopList.has(this) ? 1 : _get_readyState(this, arguments);
  1665. }
  1666. Object.defineProperty(_proto, 'readyState', _readyState);
  1667.  
  1668. let _fetch = root.Function.prototype.apply.bind(root.fetch);
  1669. root.fetch = function fetch() {
  1670. '[native code]';
  1671. let url = arguments[0];
  1672. let method = arguments[1] ? arguments[1].method : void 0;
  1673. if (arguments[0] instanceof Request) {
  1674. method = url.method;
  1675. url = url.url;
  1676. }
  1677. if (checkRequest('fetch', method, url))
  1678. return new Promise(() => null);
  1679. return _fetch(root, arguments);
  1680. };
  1681.  
  1682. let _script_src = Object.getOwnPropertyDescriptor(root.HTMLScriptElement.prototype, 'src');
  1683. let _script_src_set = root.Function.prototype.apply.bind(_script_src.set);
  1684. let _dispatchEvent = root.Function.prototype.call.bind(root.EventTarget.prototype.dispatchEvent);
  1685. _script_src.set = function(src) {
  1686. if (fabPatterns.test(src)) {
  1687. _console.warn(`Blocked set script.src request:`, src);
  1688. deployFABStub(root);
  1689. setTimeout(() => {
  1690. let e = root.document.createEvent('Event');
  1691. e.initEvent('load', false, false);
  1692. _dispatchEvent(this, e);
  1693. }, 0);
  1694. return;
  1695. }
  1696. return checkRequest('set', 'script.src', src) || _script_src_set(this, arguments);
  1697. };
  1698. Object.defineProperty(root.HTMLScriptElement.prototype, 'src', _script_src);
  1699.  
  1700. let adregain_pattern = /ggg==" alt="advertisement"/;
  1701. if (root.self !== root.top) { // in IFrame
  1702. let _write = Function.prototype.call.bind(root.document.write);
  1703. root.document.write = function write(text, ...args) {
  1704. "[native code]";
  1705. if (adregain_pattern.test(text)) {
  1706. _console.log('Skipped AdRegain frame.');
  1707. return _write(this, '');
  1708. }
  1709. return _write(this, text, ...args);
  1710. };
  1711. }
  1712. });
  1713.  
  1714. win.stop = () => {
  1715. _console.warn('window.stop() ...y tho?');
  1716. for (let sheet of _document.styleSheets)
  1717. if (sheet.disabled) {
  1718. sheet.disabled = false;
  1719. _console.log('Re-enabled:', sheet);
  1720. }
  1721. }
  1722. }, deepWrapAPI
  1723. );
  1724.  
  1725. // === Helper functions ===
  1726.  
  1727. // function to search and remove nodes by content
  1728. // selector - standard CSS selector to define set of nodes to check
  1729. // words - regular expression to check content of the suspicious nodes
  1730. // params - object with multiple extra parameters:
  1731. // .log - display log in the console
  1732. // .hide - set display to none instead of removing from the page
  1733. // .parent - parent node to remove if content is found in the child node
  1734. // .siblings - number of simling nodes to remove (excluding text nodes)
  1735. let scRemove = (node) => node.parentNode.removeChild(node);
  1736. let scHide = function(node) {
  1737. let style = _getAttribute(node, 'style') || '',
  1738. hide = ';display:none!important;';
  1739. if (style.indexOf(hide) < 0)
  1740. _setAttribute(node, 'style', style + hide);
  1741. };
  1742.  
  1743. function scissors (selector, words, scope, params) {
  1744. let logger = (...args) => { if (params.log) _console.log(...args) };
  1745. if (!scope.contains(_document.body))
  1746. logger('[s] scope', scope);
  1747. let remFunc = (params.hide ? scHide : scRemove),
  1748. iterFunc = (params.siblings > 0 ? 'nextElementSibling' : 'previousElementSibling'),
  1749. toRemove = [],
  1750. siblings;
  1751. for (let node of scope.querySelectorAll(selector)) {
  1752. // drill up to a parent node if specified, break if not found
  1753. if (params.parent) {
  1754. let old = node;
  1755. node = node.closest(params.parent);
  1756. if (node === null || node.contains(scope)) {
  1757. logger('[s] went out of scope with', old);
  1758. continue;
  1759. }
  1760. }
  1761. logger('[s] processing', node);
  1762. if (toRemove.includes(node))
  1763. continue;
  1764. if (words.test(node.innerHTML)) {
  1765. // skip node if already marked for removal
  1766. logger('[s] marked for removal');
  1767. toRemove.push(node);
  1768. // add multiple nodes if defined more than one sibling
  1769. siblings = Math.abs(params.siblings) || 0;
  1770. while (siblings) {
  1771. node = node[iterFunc];
  1772. if (!node) break; // can't go any further - exit
  1773. logger('[s] adding sibling node', node);
  1774. toRemove.push(node);
  1775. siblings -= 1;
  1776. }
  1777. }
  1778. }
  1779. let toSkip = [];
  1780. for (let node of toRemove)
  1781. if (!toRemove.every(other => other === node || !node.contains(other)))
  1782. toSkip.push(node);
  1783. if (toRemove.length)
  1784. logger(`[s] proceeding with ${params.hide?'hide':'removal'} of`, toRemove, `skip`, toSkip);
  1785. for (let node of toRemove) if (!toSkip.includes(node))
  1786. remFunc(node);
  1787. }
  1788.  
  1789. // function to perform multiple checks if ads inserted with a delay
  1790. // by default does 30 checks withing a 3 seconds unless nonstop mode specified
  1791. // also does 1 extra check when a page completely loads
  1792. // selector and words - passed dow to scissors
  1793. // params - object with multiple extra parameters:
  1794. // .log - display log in the console
  1795. // .root - selector to narrow down scope to scan;
  1796. // .observe - if true then check will be performed continuously;
  1797. // Other parameters passed down to scissors.
  1798. function gardener(selector, words, params) {
  1799. let logger = (...args) => { if (params.log) _console.log(...args) };
  1800. params = params || {};
  1801. logger(`[gardener] selector: '${selector}' detector: ${words} options: ${JSON.stringify(params)}`);
  1802. let scope;
  1803. let globalScope = [_de];
  1804. let domLoaded = false;
  1805. let getScope = root => root ? _de.querySelectorAll(root) : globalScope;
  1806. let onevent = e => {
  1807. logger(`[gardener] cleanup on ${Object.getPrototypeOf(e)} "${e.type}"`);
  1808. for (let node of scope)
  1809. scissors(selector, words, node, params);
  1810. };
  1811. let repeater = n => {
  1812. if (!domLoaded && n) {
  1813. setTimeout(repeater, 500, n - 1);
  1814. scope = getScope(params.root);
  1815. if (!scope) // exit if the root element is not present on the page
  1816. return 0;
  1817. onevent({type: 'Repeater'});
  1818. }
  1819. };
  1820. repeater(20);
  1821. _document.addEventListener(
  1822. 'DOMContentLoaded', (e) => {
  1823. domLoaded = true;
  1824. // narrow down scope to a specific element
  1825. scope = getScope(params.root);
  1826. if (!scope) // exit if the root element is not present on the page
  1827. return 0;
  1828. logger('[g] scope', scope);
  1829. // add observe mode if required
  1830. if (params.observe) {
  1831. let params = { childList:true, subtree: true };
  1832. let observer = new MutationObserver(
  1833. function(ms) {
  1834. for (let m of ms)
  1835. if (m.addedNodes.length)
  1836. onevent(m);
  1837. }
  1838. );
  1839. for (let node of scope)
  1840. observer.observe(node, params);
  1841. logger('[g] observer enabled');
  1842. }
  1843. onevent(e);
  1844. }, false);
  1845. // wait for a full page load to do one extra cut
  1846. win.addEventListener('load', onevent, false);
  1847. }
  1848.  
  1849. // wrap popular methods to open a new tab to catch specific behaviours
  1850. function createWindowOpenWrapper(openFunc) {
  1851. let _createElement = _Document.createElement,
  1852. _appendChild = _Element.appendChild,
  1853. fakeNative = (f) => (f.toString = () => `function ${f.name}() { [native code] }`);
  1854.  
  1855. let nt = new nullTools();
  1856. fakeNative(openFunc);
  1857.  
  1858. let parser = _createElement.call(_document, 'a');
  1859. let openWhitelist = (url, parent) => {
  1860. parser.href = url;
  1861. return parser.hostname === 'www.imdb.com' || parser.hostname === 'www.kinopoisk.ru' ||
  1862. parent.hostname === 'radikal.ru' && url === void 0;
  1863. };
  1864.  
  1865. let redefineOpen = (root) => {
  1866. if ('open' in root) {
  1867. let _open = root.open.bind(root);
  1868. nt.define(root, 'open', (...args) => {
  1869. if (openWhitelist(args[0], location)) {
  1870. _console.log('Whitelisted popup:', ...args);
  1871. return _open(...args);
  1872. }
  1873. return openFunc(...args);
  1874. });
  1875. }
  1876. };
  1877. redefineOpen(win);
  1878.  
  1879. function createElement() {
  1880. '[native code]';
  1881. let el = _createElement.apply(this, arguments);
  1882. // redefine window.open in first-party frames
  1883. if (el instanceof HTMLIFrameElement || el instanceof HTMLObjectElement)
  1884. el.addEventListener('load', (e) => {
  1885. try {
  1886. redefineOpen(e.target.contentWindow);
  1887. } catch(ignore) {}
  1888. }, false);
  1889. return el;
  1890. }
  1891. fakeNative(createElement);
  1892.  
  1893. let redefineCreateElement = (obj) => {
  1894. for (let root of [obj.document, _Document]) if ('createElement' in root)
  1895. nt.define(root, 'createElement', createElement);
  1896. };
  1897. redefineCreateElement(win);
  1898.  
  1899. // wrap window.open in newly added first-party frames
  1900. _Element.appendChild = function appendChild() {
  1901. '[native code]';
  1902. let el = _appendChild.apply(this, arguments);
  1903. if (el instanceof HTMLIFrameElement)
  1904. try {
  1905. redefineOpen(el.contentWindow);
  1906. redefineCreateElement(el.contentWindow);
  1907. } catch(ignore) {}
  1908. return el;
  1909. };
  1910. fakeNative(_Element.appendChild);
  1911. }
  1912.  
  1913. // Function to catch and block various methods to open a new window with 3rd-party content.
  1914. // Some advertisement networks went way past simple window.open call to circumvent default popup protection.
  1915. // This funciton blocks window.open, ability to restore original window.open from an IFRAME object,
  1916. // ability to perform an untrusted (not initiated by user) click on a link, click on a link without a parent
  1917. // node or simply a link with piece of javascript code in the HREF attribute.
  1918. function preventPopups() {
  1919. // call sandbox-me if in iframe and not whitelisted
  1920. if (inIFrame) {
  1921. win.top.postMessage({ name: 'sandbox-me', href: win.location.href }, '*');
  1922. return;
  1923. }
  1924.  
  1925. scriptLander(() => {
  1926. let nt = new nullTools({log:true});
  1927. let open = (...args) => {
  1928. '[native code]';
  1929. _console.warn('Site attempted to open a new window', ...args);
  1930. return {
  1931. document: nt.proxy({
  1932. write: nt.func({}, 'write'),
  1933. writeln: nt.func({}, 'writeln')
  1934. }),
  1935. location: nt.proxy({})
  1936. };
  1937. };
  1938.  
  1939. createWindowOpenWrapper(open);
  1940.  
  1941. _console.log('Popup prevention enabled.');
  1942. }, nullTools, createWindowOpenWrapper);
  1943. }
  1944.  
  1945. // Helper function to close background tab if site opens itself in a new tab and then
  1946. // loads a 3rd-party page in the background one (thus performing background redirect).
  1947. function preventPopunders() {
  1948. // create "close_me" event to call high-level window.close()
  1949. let eventName = `close_me_${Math.random().toString(36).substr(2)}`;
  1950. let callClose = () => {
  1951. _console.log('close call');
  1952. window.close();
  1953. };
  1954. window.addEventListener(eventName, callClose, true);
  1955.  
  1956. scriptLander(() => {
  1957. // get host of a provided URL with help of an anchor object
  1958. // unfortunately new URL(url, window.location) generates wrong URL in some cases
  1959. let parseURL = _document.createElement('A');
  1960. let getHost = url => {
  1961. parseURL.href = url;
  1962. return parseURL.hostname
  1963. };
  1964. // site went to a new tab and attempts to unload
  1965. // call for high-level close through event
  1966. let closeWindow = () => window.dispatchEvent(new CustomEvent(eventName, {}));
  1967. // check is URL local or goes to different site
  1968. let isLocal = (url) => {
  1969. if (url === location.pathname || url === location.href)
  1970. return true; // URL points to current pathname or full address
  1971. let host = getHost(url);
  1972. let site = location.hostname;
  1973. return host !== '' && // URLs with unusual protocol may have empty 'host'
  1974. (site === host || site.endsWith(`.${host}`) || host.endsWith(`.${site}`));
  1975. };
  1976.  
  1977. let _open = window.open.bind(window);
  1978. let open = (...args) => {
  1979. '[native code]';
  1980. let url = args[0];
  1981. if (url && isLocal(url))
  1982. window.addEventListener('beforeunload', closeWindow, true);
  1983. return _open(...args);
  1984. };
  1985.  
  1986. createWindowOpenWrapper(open);
  1987.  
  1988. _console.log("Background redirect prevention enabled.");
  1989. }, `let eventName="${eventName}"`, nullTools, createWindowOpenWrapper);
  1990. }
  1991.  
  1992. // Mix between check for popups and popunders
  1993. // Significantly more agressive than both and can't be used as universal solution
  1994. function preventPopMix() {
  1995. if (inIFrame) {
  1996. win.top.postMessage({ name: 'sandbox-me', href: win.location.href }, '*');
  1997. return;
  1998. }
  1999.  
  2000. // create "close_me" event to call high-level window.close()
  2001. let eventName = `close_me_${Math.random().toString(36).substr(2)}`;
  2002. let callClose = () => {
  2003. _console.log('close call');
  2004. window.close();
  2005. };
  2006. window.addEventListener(eventName, callClose, true);
  2007.  
  2008. scriptLander(() => {
  2009. let _open = window.open,
  2010. parseURL = _document.createElement('A');
  2011. // get host of a provided URL with help of an anchor object
  2012. // unfortunately new URL(url, window.location) generates wrong URL in some cases
  2013. let getHost = (url) => {
  2014. parseURL.href = url;
  2015. return parseURL.host;
  2016. };
  2017. // site went to a new tab and attempts to unload
  2018. // call for high-level close through event
  2019. let closeWindow = () => {
  2020. _open(window.location,'_self');
  2021. window.dispatchEvent(new CustomEvent(eventName, {}));
  2022. };
  2023. // check is URL local or goes to different site
  2024. function isLocal(url) {
  2025. let loc = window.location;
  2026. if (url === loc.pathname || url === loc.href)
  2027. return true; // URL points to current pathname or full address
  2028. let host = getHost(url),
  2029. site = loc.host;
  2030. if (host === '')
  2031. return false; // URLs with unusual protocol may have empty 'host'
  2032. if (host.length > site.length)
  2033. [site, host] = [host, site];
  2034. return site.includes(host, site.length - host.length);
  2035. }
  2036.  
  2037. // add check for redirect for 5 seconds, then disable it
  2038. function checkRedirect() {
  2039. window.addEventListener('beforeunload', closeWindow, true);
  2040. setTimeout(closeWindow=>window.removeEventListener('beforeunload', closeWindow, true), 5000, closeWindow);
  2041. }
  2042.  
  2043. function open(url, name) {
  2044. '[native code]';
  2045. if (url && isLocal(url) && (!name || name === '_blank')) {
  2046. _console.warn('Suspicious local new window', arguments);
  2047. checkRedirect();
  2048. return _open.apply(this, arguments);
  2049. }
  2050. _console.warn('Blocked attempt to open a new window', arguments);
  2051. return {
  2052. document: {
  2053. write: () => {},
  2054. writeln: () => {}
  2055. }
  2056. };
  2057. }
  2058.  
  2059. function clickHandler(e) {
  2060. let link = e.target,
  2061. url = link.href||'';
  2062. if (e.targetParentNode && e.isTrusted || link.target !== '_blank') {
  2063. _console.log('Link', link, 'were created dinamically, but looks fine.');
  2064. return true;
  2065. }
  2066. if (isLocal(url) && link.target === '_blank') {
  2067. _console.log('Suspicious local link', link);
  2068. checkRedirect();
  2069. return;
  2070. }
  2071. _console.log('Blocked suspicious click on a link', link);
  2072. e.stopPropagation();
  2073. e.preventDefault();
  2074. }
  2075.  
  2076. createWindowOpenWrapper(open, clickHandler);
  2077.  
  2078. _console.log("Mixed popups prevention enabled.");
  2079. }, `let eventName="${eventName}"`, createWindowOpenWrapper);
  2080. }
  2081. // External listener for case when site known to open popups were loaded in iframe
  2082. // It will sandbox any iframe which will send message 'forbid.popups' (preventPopups sends it)
  2083. // Some sites replace frame's window.location with data-url to run in clean context
  2084. if (!inIFrame) window.addEventListener(
  2085. 'message', function(e) {
  2086. if (!e.data || e.data.name !== 'sandbox-me' || !e.data.href)
  2087. return;
  2088. let src = e.data.href;
  2089. for (let frame of _document.querySelectorAll('iframe'))
  2090. if (frame.contentWindow === e.source) {
  2091. if (frame.hasAttribute('sandbox')) {
  2092. if (!frame.sandbox.contains('allow-popups'))
  2093. return; // exit frame since it's already sandboxed and popups are blocked
  2094. // remove allow-popups if frame already sandboxed
  2095. frame.sandbox.remove('allow-popups');
  2096. } else
  2097. // set sandbox mode for troublesome frame and allow scripts, forms and a few other actions
  2098. // technically allowing both scripts and same-origin allows removal of the sandbox attribute,
  2099. // but to apply content must be reloaded and this script will re-apply it in the result
  2100. frame.setAttribute('sandbox','allow-forms allow-scripts allow-presentation allow-top-navigation allow-same-origin');
  2101. _console.log('Disallowed popups from iframe', frame);
  2102.  
  2103. // reload frame content to apply restrictions
  2104. if (!src) {
  2105. src = frame.src;
  2106. _console.log('Unable to get current iframe location, reloading from src', src);
  2107. } else
  2108. _console.log('Reloading iframe with URL', src);
  2109. frame.src = 'about:blank';
  2110. frame.src = src;
  2111. }
  2112. }, false
  2113. );
  2114.  
  2115. let evalPatternYandex = /{exports:{},id:r,loaded:!1}|containerId:(.|\r|\n)+params:/;
  2116. let evalPatternGeneric = /_0x|location\s*?=|location.href\s*?=|location.assign\(|open\(/i;
  2117. function selectiveEval(...patterns) {
  2118. if (patterns.length === 0)
  2119. patterns.push(evalPatternGeneric);
  2120. scriptLander(() => {
  2121. let _eval_def = Object.getOwnPropertyDescriptor(win, 'eval');
  2122. if (!_eval_def || !_eval_def.value) {
  2123. _console.warn('Unable to wrap window.eval.', _eval_def);
  2124. return;
  2125. }
  2126. let _eval_val = _eval_def.value;
  2127. _eval_def.value = function(...args) {
  2128. if (patterns.some(pattern => pattern.test(args[0]))) {
  2129. _console.warn(`Skipped eval of ${args[0].slice(0, 512)}\u2026`);
  2130. return null;
  2131. }
  2132. try {
  2133. return _eval_val.apply(this, args);
  2134. } catch(e) {
  2135. _console.log('Crash source:', args[0]);
  2136. throw e;
  2137. }
  2138. };
  2139. Object.defineProperty(win, 'eval', _eval_def);
  2140. }, `let patterns = [${patterns}];`);
  2141. }
  2142.  
  2143. // hides cookies by pattern and attempts to remove them if they already set
  2144. // also prevents setting new versions of such cookies
  2145. function selectiveCookies(scPattern = '', scPaths = []) {
  2146. scriptLander(() => {
  2147. let patterns = scPattern.split('|');
  2148. if (patterns[0] !== ';default') {
  2149. // Google Analytics cookies
  2150. patterns.push('_g(at?|id)|__utm[a-z]');
  2151. // Yandex ABP detection cookies
  2152. patterns.push('bltsr|blcrm');
  2153. } else
  2154. patterns.shift();
  2155. let blacklist = new RegExp(`(^|;\\s?)(${patterns.join('|')})($|=)`);
  2156. if (isFirefox && scPaths.length)
  2157. scPaths = scPaths.map(path => `${path}/`);
  2158. scPaths.push('/');
  2159. let _doc_proto = ('cookie' in _Document) ? _Document : Object.getPrototypeOf(_document);
  2160. let _cookie = Object.getOwnPropertyDescriptor(_doc_proto, 'cookie');
  2161. if (_cookie) {
  2162. let _set_cookie = Function.prototype.call.bind(_cookie.set);
  2163. let _get_cookie = Function.prototype.call.bind(_cookie.get);
  2164. let expireDate = 'Thu, 01 Jan 1970 00:00:01 UTC';
  2165. let expireAge = '-99999999';
  2166. let expireBase = `=;expires=${expireDate};Max-Age=${expireAge}`;
  2167. let expireAttempted = {};
  2168. // expire is called from cookie getter and doesn't know exact parameters used to set cookies present there
  2169. // so, it will use path=/ by default if scPaths wasn't set and attempt to set cookies on all parent domains
  2170. let expire = (cookie, that) => {
  2171. let domain = that.location.hostname.split('.'),
  2172. name = cookie.replace(/=.*/,'');
  2173. scPaths.forEach(path =>_set_cookie(that, `${name}${expireBase};path=${path}`));
  2174. while (domain.length > 1) {
  2175. try {
  2176. scPaths.forEach(
  2177. path => _set_cookie(that, `${name}${expireBase};domain=${domain.join('.')};path=${path}`)
  2178. );
  2179. } catch(e) { _console.warn(e); }
  2180. domain.shift();
  2181. }
  2182. expireAttempted[name] = true;
  2183. _console.log('Removing existing cookie:', cookie);
  2184. };
  2185. // skip setting unwanted cookies
  2186. _cookie.set = function(value) {
  2187. if (blacklist.test(value)) {
  2188. _console.warn('Ignored cookie:', value);
  2189. // try to remove same cookie if it already exists using exact values from the set string
  2190. if (blacklist.test(_get_cookie(this))) {
  2191. let parts = value.split(/;\s?/),
  2192. name = parts[0].replace(/=.*/,''),
  2193. newParts = [`${name}=`, `expires=${expireDate}`, `Max-Age=${expireAge}`],
  2194. skip = [name, 'expires', 'Max-Age'];
  2195. for (let part of parts)
  2196. if (!skip.includes(part.replace(/=.*/,'')))
  2197. newParts.push(part);
  2198. try {
  2199. _set_cookie(this, newParts.join(';'));
  2200. } catch(e) { _console.warn(e); }
  2201. _console.log('Removing existing cookie:', name);
  2202. }
  2203. return;
  2204. }
  2205. return _set_cookie(this, value);
  2206. };
  2207. // hide unwanted cookies from site
  2208. _cookie.get = function() {
  2209. let res = _get_cookie(this);
  2210. if (blacklist.test(res)) {
  2211. let stack = [];
  2212. for (let cookie of res.split(/;\s?/))
  2213. if (!blacklist.test(cookie))
  2214. stack.push(cookie);
  2215. else {
  2216. let name = cookie.replace(/=.*/,'');
  2217. if (expireAttempted[name]) {
  2218. _console.log('Unable to expire:', cookie);
  2219. expireAttempted[name] = false;
  2220. }
  2221. if (!(name in expireAttempted))
  2222. expire(cookie, this);
  2223. }
  2224. res = stack.join('; ');
  2225. }
  2226. return res;
  2227. };
  2228. Object.defineProperty(_doc_proto, 'cookie', _cookie);
  2229. _console.log('Active cookies:', win.document.cookie);
  2230. }
  2231. }, `let scPattern = "${scPattern}", scPaths = ${JSON.stringify(scPaths)}, isFirefox = ${isFirefox};`);
  2232. }
  2233.  
  2234. /*{ // simple toString wrapper, might be useful to prevent detection
  2235. '[native code]';
  2236. let _toString = Function.prototype.apply.bind(Function.prototype.toString);
  2237. let baseText = Function.prototype.toString.toString();
  2238. let protect = new WeakSet();
  2239. protect.add(_Document.createElement);
  2240. protect.add(_Node.appendChild);
  2241. protect.add(_Node.removeChild);
  2242. win.Function.prototype.toString = function() {
  2243. if (protect.has(this))
  2244. return baseText.replace('toString', this.name);
  2245. return _toString(this);
  2246. };
  2247. protect.add(Function.prototype.toString);
  2248. }*/
  2249.  
  2250. // Locates a node with specific text in Russian
  2251. // Uses table of substitutions for similar letters
  2252. let selectNodeByTextContent = (()=> {
  2253. let subs = {
  2254. // english & greek
  2255. 'А': 'AΑ', 'В': 'BΒ', 'Г':'Γ',
  2256. 'Е': 'EΕ', 'З': '3', 'К':'KΚ',
  2257. 'М': 'MΜ', 'Н': 'HΗ', 'О':'OΟ',
  2258. 'П': 'Π', 'Р': 'PΡ', 'С':'C',
  2259. 'Т': 'T', 'Ф': 'Φ', 'Х':'XΧ'
  2260. }
  2261. let regExpBuilder = text => new RegExp(
  2262. text.toUpperCase()
  2263. .split('')
  2264. .map(function(e){
  2265. return `${e in subs ? `[${e}${subs[e]}]` : (e === ' ' ? '\\s+' : e)}[\u200b\u200c\u200d]*`;
  2266. })
  2267. .join(''),
  2268. 'i');
  2269. let reMap = {};
  2270. return (re, opts = { root: _document.body }) => {
  2271. if (!re.test) {
  2272. if (!reMap[re])
  2273. reMap[re] = regExpBuilder(re);
  2274. re = reMap[re];
  2275. }
  2276.  
  2277. for (let child of opts.root.children)
  2278. if (re.test(child.textContent)) {
  2279. if (opts.shallow)
  2280. return child;
  2281. opts.root = child;
  2282. return selectNodeByTextContent(re, opts) || child;
  2283. }
  2284. }
  2285. })();
  2286.  
  2287. // webpackJsonp filter
  2288. function webpackJsonpFilter(blacklist, log = false) {
  2289. let _apply = Reflect.apply;
  2290. let _toString = Function.prototype.call.bind(Function.prototype.toString);
  2291. function wrapPush(webpack) {
  2292. let _push = webpack.push.bind(webpack);
  2293. Object.defineProperty(webpack, 'push', {
  2294. get: () => _push,
  2295. set: vl => {
  2296. _push = new Proxy(vl, {
  2297. apply: (push, obj, args) => {
  2298. wrapper: {
  2299. if (!(args[0] instanceof Array))
  2300. break wrapper;
  2301. let mainName;
  2302. if (args[0][2] instanceof Array && args[0][2][0] instanceof Array)
  2303. mainName = args[0][2][0][0];
  2304. let funs = args[0][1];
  2305. if (!(funs instanceof Object && !(funs instanceof Array)))
  2306. break wrapper;
  2307. for (let name in funs) {
  2308. if (typeof funs[name] !== 'function')
  2309. continue;
  2310. if (blacklist.test(_toString(funs[name])) && name !== mainName) {
  2311. let text = log ? _toString(funs[name]) : '';
  2312. funs[name] = () => _console.log(`Skip webpack ${name}`, text);
  2313. }
  2314. }
  2315. }
  2316. _console.log('webpack.push()');
  2317. return _apply(push, obj, args);
  2318. }
  2319. });
  2320. return true;
  2321. }
  2322. });
  2323. return webpack
  2324. }
  2325. let _webpackJsonp = wrapPush([]);
  2326. Object.defineProperty(win, 'webpackJsonp', {
  2327. get: () => _webpackJsonp,
  2328. set: vl => {
  2329. if (vl === _webpackJsonp)
  2330. return;
  2331. _console.log('new webpackJsonp', vl);
  2332. _webpackJsonp = wrapPush(vl);
  2333. return true;
  2334. }
  2335. });
  2336. }
  2337.  
  2338. // === Scripts for specific domains ===
  2339.  
  2340. let scripts = {};
  2341. // prevent popups and redirects block
  2342. // Popups
  2343. scripts.preventPopups = {
  2344. other: [
  2345. 'biqle.ru',
  2346. 'chaturbate.com',
  2347. 'dfiles.ru',
  2348. 'eporner.eu',
  2349. 'hentaiz.org',
  2350. 'mirrorcreator.com',
  2351. 'online-multy.ru',
  2352. 'radikal.ru', 'rumedia.ws',
  2353. 'tapehub.tech', 'thepiratebay.org',
  2354. 'unionpeer.com',
  2355. 'zippyshare.com'
  2356. ],
  2357. now: preventPopups
  2358. };
  2359. // Popunders (background redirect)
  2360. scripts.preventPopunders = {
  2361. other: [
  2362. 'lostfilm-online.ru',
  2363. 'mediafire.com', 'megapeer.org', 'megapeer.ru',
  2364. 'perfectgirls.net'
  2365. ],
  2366. now: preventPopunders
  2367. };
  2368. // PopMix (both types of popups encountered on site)
  2369. scripts['openload.co'] = {
  2370. other: ['oload.tv', 'oload.info'],
  2371. now: () => {
  2372. let nt = new nullTools();
  2373. nt.define(win, 'CNight', win.CoinHive);
  2374. if (location.pathname.startsWith('/embed/')) {
  2375. nt.define(win, 'BetterJsPop', {
  2376. add: ((a, b) => _console.warn('BetterJsPop.add', a, b)),
  2377. config: ((o) => _console.warn('BetterJsPop.config', o)),
  2378. Browser: { isChrome: true }
  2379. });
  2380. nt.define(win, 'isSandboxed', nt.func(null));
  2381. nt.define(win, 'adblock', false);
  2382. nt.define(win, 'adblock2', false);
  2383. } else preventPopMix();
  2384. }
  2385. };
  2386. scripts['turbobit.net'] = preventPopMix;
  2387.  
  2388. scripts['tapochek.net'] = () => {
  2389. // workaround for moradu.com/apu.php load error handler script, not sure which ad network is this
  2390. let _appendChild = Object.getOwnPropertyDescriptor(_Node, 'appendChild');
  2391. let _appendChild_value = _appendChild.value;
  2392. _appendChild.value = function appendChild(node) {
  2393. if (this === _document.body)
  2394. if ((node instanceof HTMLScriptElement || node instanceof HTMLStyleElement) &&
  2395. /^https?:\/\/[0-9a-f]{15}\.com\/\d+(\/|\.css)$/.test(node.src) ||
  2396. node instanceof HTMLDivElement && node.style.zIndex > 900000 &&
  2397. node.style.backgroundImage.includes('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'))
  2398. throw '...eenope!';
  2399. return _appendChild_value.apply(this, arguments);
  2400. };
  2401. Object.defineProperty(_Node, 'appendChild', _appendChild);
  2402.  
  2403. // disable window focus tricks and changing location
  2404. let focusHandlerName = /\WfocusAchieved\(/
  2405. let _toString = Function.prototype.call.bind(Function.prototype.toString);
  2406. let _setInterval = win.setInterval;
  2407. win.setInterval = (...args) => {
  2408. if (args.length && focusHandlerName.test(_toString(args[0]))) {
  2409. _console.log('skip setInterval for', ...args);
  2410. return -1;
  2411. }
  2412. return _setInterval(...args);
  2413. };
  2414. let _addEventListener = win.addEventListener;
  2415. win.addEventListener = function(...args) {
  2416. if (args.length && args[0] === 'focus' && focusHandlerName.test(_toString(args[1]))) {
  2417. _console.log('skip addEventListener for', ...args);
  2418. return void 0;
  2419. }
  2420. return _addEventListener.apply(this, args);
  2421. };
  2422.  
  2423. // generic popup prevention
  2424. preventPopups();
  2425. };
  2426.  
  2427. scripts['rustorka.com'] = {
  2428. other: ['rustorka.club', 'rustorka.innal.top', 'rustorka.lib', 'rustorka.net'],
  2429. now: () => {
  2430. selectiveEval(evalPatternGeneric, /antiadblock/);
  2431. selectiveCookies('adblock|u_count|gophp|st2|st3', ['/forum']);
  2432. scriptLander(() => {
  2433. // wrap window.open to catch a popup if it triggers
  2434. win.open = (...args) => {
  2435. _console.warn(`Site attempted to open "${args[0]}" in a new window.`);
  2436. location.replace(location.href);
  2437. return null;
  2438. };
  2439. window.addEventListener('DOMContentLoaded', () => {
  2440. let link = void 0;
  2441. _document.body.addEventListener('mousedown', e => {
  2442. link = e.target.closest('a, select, #fancybox-title-wrap');
  2443. }, false);
  2444. let _open = window.open.bind(window);
  2445. let _getAttribute = Function.prototype.call.bind(_Element.getAttribute);
  2446. win.open = (...args) => {
  2447. let url = args[0];
  2448. if (link instanceof HTMLAnchorElement) {
  2449. // third-party post links
  2450. let href = _getAttribute(link, 'href');
  2451. if (link.classList.contains('postLink') &&
  2452. !link.matches(`a[href*="${location.hostname}"]`) &&
  2453. (href === url || link.href === url))
  2454. return _open(...args);
  2455. // onclick # links
  2456. if (href === '#' && /window\.open/.test(_getAttribute(link, 'onclick')))
  2457. return _open(...args);
  2458. // force local links to load in the current window
  2459. if (href[0] === '/' || href.startsWith('./') || href.includes(`//${location.hostname}/`))
  2460. location.assign(href);
  2461. }
  2462. // list of image hostings under upload picture button (new comment)
  2463. if (link instanceof HTMLSelectElement &&
  2464. !url.includes(location.hostname) &&
  2465. link.value === url)
  2466. return _open(...args);
  2467. // open screenshot in a new window
  2468. if (link instanceof HTMLSpanElement &&
  2469. link.id === 'fancybox-title-wrap')
  2470. return _open(...args);
  2471. // looks like tabunder
  2472. if (link === null && url === location.href)
  2473. location.replace(url); // reload current page
  2474. // other cases
  2475. _console.warn(`Site attempted to open "${url}" in a new window. Source: `, link);
  2476. return {};
  2477. };
  2478. }, true);
  2479. }, nullTools)
  2480. }
  2481. };
  2482.  
  2483. // = other ======================================================================================
  2484. scripts['1tv.ru'] = {
  2485. other: ['mediavitrina.ru'],
  2486. now: () => scriptLander(() => {
  2487. let nt = new nullTools();
  2488. nt.define(win, 'EUMPAntiblockConfig', nt.proxy({url: '//www.1tv.ru/favicon.ico'}));
  2489. let disablePlugins = {
  2490. 'antiblock': false,
  2491. 'stat1tv': false
  2492. };
  2493. let _EUMPConfig = void 0;
  2494. let _EUMPConfig_set = x => {
  2495. if (x.plugins) {
  2496. x.plugins = x.plugins.filter(plugin => (plugin in disablePlugins) ? !(disablePlugins[plugin] = true) : true);
  2497. _console.warn(`Player plugins: active [${x.plugins}], disabled [${Object.keys(disablePlugins).filter(x => disablePlugins[x])}]`);
  2498. }
  2499. _EUMPConfig = x;
  2500. };
  2501. if ('EUMPConfig' in win)
  2502. _EUMPConfig_set(win.EUMPConfig);
  2503. Object.defineProperty(win, 'EUMPConfig', {
  2504. enumerable: true,
  2505. get: () => _EUMPConfig,
  2506. set: _EUMPConfig_set
  2507. });
  2508. }, nullTools)
  2509. };
  2510.  
  2511. scripts['24smi.org'] = () => selectiveCookies('has_adblock');
  2512.  
  2513. scripts['2picsun.ru'] = {
  2514. other: [
  2515. 'pics2sun.ru', '3pics-img.ru'
  2516. ],
  2517. now: () => {
  2518. Object.defineProperty(navigator, 'userAgent', {value: 'googlebot'});
  2519. }
  2520. };
  2521.  
  2522. scripts['4pda.ru'] = {
  2523. now: () => {
  2524. // https://greasyfork.org/en/scripts/14470-4pda-unbrender
  2525. let isForum = location.pathname.startsWith('/forum/'),
  2526. remove = node => (node && node.parentNode.removeChild(node)),
  2527. hide = node => (node && (node.style.display = 'none'));
  2528.  
  2529. // clean a page
  2530. window.addEventListener(
  2531. 'DOMContentLoaded', function() {
  2532. let width = () => window.innerWidth || _de.clientWidth || _document.body.clientWidth || 0;
  2533. let height = () => window.innerHeight || _de.clientHeight || _document.body.clientHeight || 0;
  2534.  
  2535. HeaderAds: {
  2536. // hide ads above HEADER
  2537. let nav = _document.querySelector('.menu');
  2538. if (!nav) {
  2539. _console.warn('Unable to locate header element');
  2540. break HeaderAds;
  2541. }
  2542. for (let itm of nav.parentNode.children)
  2543. if (itm !== nav)
  2544. hide(itm);
  2545. else break;
  2546. }
  2547.  
  2548. if (isForum) {
  2549. let itm = _document.querySelector('#logostrip');
  2550. if (itm)
  2551. remove(itm.parentNode.nextSibling);
  2552. // clear background in the download frame
  2553. if (location.pathname.startsWith('/forum/dl/')) {
  2554. let setBackground = node => _setAttribute(
  2555. node,
  2556. 'style', (_getAttribute(node, 'style') || '') +
  2557. ';background-color:#4ebaf6!important'
  2558. );
  2559. setBackground(_document.body);
  2560. for (let itm of _document.querySelectorAll('body > div'))
  2561. if (!itm.querySelector('.dw-fdwlink, .content') && !itm.classList.contains('footer'))
  2562. remove(itm);
  2563. else
  2564. setBackground(itm);
  2565. }
  2566. // exist from DOMContentLoaded since the rest is not for forum
  2567. return;
  2568. }
  2569.  
  2570. FixNavMenu: {
  2571. // hide ad link from the navigation
  2572. let ad = _document.querySelector('.menu-main-item > a > svg');
  2573. if (!ad) {
  2574. _console.warn('Unable to locate menu ad item');
  2575. break FixNavMenu;
  2576. } else {
  2577. ad = ad.parentNode.parentNode;
  2578. hide(ad);
  2579. }
  2580. }
  2581. SidebarAds: {
  2582. // remove ads from sidebar
  2583. let aside = _document.querySelectorAll('[class]:not([id]) > [id]:not([class]) > :first-child + :last-child:not(.v-panel)');
  2584. if (!aside.length) {
  2585. _console.warn('Unable to locate sidebar');
  2586. break SidebarAds;
  2587. }
  2588. let post;
  2589. for (let side of aside) {
  2590. _console.log('Processing potential sidebar:', side);
  2591. for (let itm of Array.from(side.children)) {
  2592. post = itm.classList.contains('post');
  2593. if (itm.querySelector('iframe') && !post)
  2594. remove(itm);
  2595. if (itm.querySelector('script, a[target="_blank"] > img') && !post || !itm.children.length)
  2596. hide(itm);
  2597. }
  2598. }
  2599. }
  2600.  
  2601. _document.body.setAttribute('style', (_document.body.getAttribute('style')||'')+';background-color:#E6E7E9!important');
  2602.  
  2603. let extra = 'background-image:none!important;background-color:transparent!important',
  2604. fakeStyles = new WeakMap(),
  2605. styleProxy = {
  2606. get: (target, prop) => fakeStyles.get(target)[prop] || target[prop],
  2607. set: function(target, prop, value) {
  2608. let fakeStyle = fakeStyles.get(target);
  2609. ((prop in fakeStyle) ? fakeStyle : target)[prop] = value;
  2610. return true;
  2611. }
  2612. };
  2613. for (let itm of _document.querySelectorAll('[id]:not(A), A')) {
  2614. if (!(itm.offsetWidth > 0.95 * width() &&
  2615. itm.offsetHeight > 0.85 * height()))
  2616. continue;
  2617. if (itm.tagName !== 'A') {
  2618. fakeStyles.set(itm.style, {
  2619. 'backgroundImage': itm.style.backgroundImage,
  2620. 'backgroundColor': itm.style.backgroundColor
  2621. });
  2622.  
  2623. try {
  2624. Object.defineProperty(itm, 'style', {
  2625. value: new Proxy(itm.style, styleProxy),
  2626. enumerable: true
  2627. });
  2628. } catch (e) {
  2629. _console.log('Unable to protect style property.', e);
  2630. }
  2631.  
  2632. _setAttribute(itm, 'style', `${(_getAttribute(itm, 'style') || '')};${extra}`);
  2633. }
  2634. if (itm.tagName === 'A')
  2635. _setAttribute(itm, 'style', 'display:none!important');
  2636. }
  2637. }
  2638. );
  2639. }
  2640. };
  2641.  
  2642. scripts['adhands.ru'] = () => scriptLander(() => {
  2643. let nt = new nullTools();
  2644. try {
  2645. let _adv;
  2646. Object.defineProperty(win, 'adv', {
  2647. get: () => _adv,
  2648. set: (v) => {
  2649. _console.log('Blocked advert on adhands.ru.');
  2650. nt.define(v, 'advert', '');
  2651. _adv = v;
  2652. }
  2653. });
  2654. } catch (ignore) {
  2655. if (!win.adv)
  2656. _console.log('Unable to locate advert on adhands.ru.');
  2657. else {
  2658. _console.log('Blocked advert on adhands.ru.');
  2659. nt.define(win.adv, 'advert', '');
  2660. }
  2661. }
  2662. }, nullTools);
  2663.  
  2664. scripts['all-episodes.tv'] = () => {
  2665. let nt = new nullTools();
  2666. nt.define(win, 'perX1', 2);
  2667. createStyle('#advtss, #ad3, a[href*="/ad.admitad.com/"] { display:none!important }');
  2668. };
  2669.  
  2670. scripts['allhentai.ru'] = () => {
  2671. selectiveEval();
  2672. preventPopups();
  2673. scriptLander(() => {
  2674. let _onerror = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'onerror');
  2675. if (!_onerror)
  2676. return;
  2677. _onerror.set = (...args) => _console.log(args[0].toString());
  2678. Object.defineProperty(HTMLElement.prototype, 'onerror', _onerror);
  2679. });
  2680. };
  2681.  
  2682. scripts['allmovie.pro'] = {
  2683. other: ['rufilmtv.org'],
  2684. dom: function() {
  2685. // pretend to be Android to make site use different played for ads
  2686. if (isSafari)
  2687. return;
  2688. Object.defineProperty(navigator, 'userAgent', {
  2689. get: function(){
  2690. 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';
  2691. },
  2692. enumerable: true
  2693. });
  2694. }
  2695. };
  2696.  
  2697. scripts['anidub-online.ru'] = {
  2698. other: ['anime.anidub.com', 'online.anidub.com'],
  2699. dom: function() {
  2700. if (win.ogonekstart1)
  2701. win.ogonekstart1 = () => _console.log("Fire in the hole!");
  2702. },
  2703. now: () => createStyle([
  2704. '.background {background: none!important;}',
  2705. '.background > script + div,'+
  2706. '.background > script ~ div:not([id]):not([class]) + div[id][class]'+
  2707. '{display:none!important}'
  2708. ])
  2709. };
  2710.  
  2711. scripts['tv.animebest.org'] = {
  2712. now: () => {
  2713. let _eval = win.eval;
  2714. win.eval = new win.Proxy(win.eval, {
  2715. apply: (evl, ths, args) => {
  2716. if (typeof args[0] === 'string' &&
  2717. args[0].includes("'VASTP'")) {
  2718. args[0] = args[0].replace("'VASTP'", "''");
  2719. win.eval = _eval;
  2720. }
  2721. return Reflect.apply(evl, ths, args);
  2722. }
  2723. });
  2724. }
  2725. };
  2726.  
  2727. scripts['audioportal.su'] = {
  2728. now: () => createStyle('#blink2 { display: none !important }'),
  2729. dom: () => {
  2730. let links = _document.querySelectorAll('a[onclick*="clickme("]');
  2731. if (!links) return;
  2732. for (let link of links)
  2733. clickme(link);
  2734. }
  2735. };
  2736.  
  2737. scripts['avito.ru'] = () => selectiveCookies('abp|cmtchd|crookie|is_adblock');
  2738.  
  2739. scripts['di.fm'] = () => scriptLander(() => {
  2740. let log = false;
  2741. // wrap global app object to catch registration of specific modules
  2742. let _di = void 0;
  2743. Object.defineProperty(win, 'di', {
  2744. get: () => _di,
  2745. set: vl => {
  2746. if (vl === _di)
  2747. return;
  2748. log && _console.log('di =', vl);
  2749. _di = new Proxy(vl, {
  2750. set: (di, name, vl) => {
  2751. if (vl === di[name])
  2752. return true;
  2753. if (name === 'app') {
  2754. log && _console.log('di.app =', vl);
  2755. if ('module' in vl)
  2756. vl.module = new Proxy(vl.module, {
  2757. apply: (module, that, args) => {
  2758. if (/Wall|Banner|Detect|WebplayerApp\.Ads/.test(args[0])) {
  2759. let name = args[0];
  2760. log && _console.warn('wrap', name, 'module');
  2761. if (typeof args[1] === 'function')
  2762. args[1] = new Proxy(args[1], {
  2763. apply: (fun, that, args) => {
  2764. if (args[0]) // module object
  2765. args[0].start = () => _console.log('Skipped start of', name);
  2766. return Reflect.apply(fun, that, args);
  2767. }
  2768. });
  2769. }// else log && _console.log('loading module', args[0]);
  2770. if (args[0] === 'Modals') {
  2771. log && _console.warn('wrap', name, 'module');
  2772. if (typeof args[1] === 'function')
  2773. args[1] = new Proxy(args[1], {
  2774. apply: (fun, that, args) => {
  2775. if ('commands' in args[1] && 'setHandlers' in args[1].commands &&
  2776. !Object.hasOwnProperty.call(args[1].commands, 'setHandlers')) {
  2777. let _commands = args[1].commands;
  2778. _commands.setHandlers = new Proxy(_commands.setHandlers, {
  2779. apply: (fun, that, args) => {
  2780. for (let name in args[0])
  2781. if (name === 'modal:streaminterrupt' ||
  2782. name === 'modal:midroll')
  2783. args[0][name] = () => _console.log('Skipped', name, 'window');
  2784. delete _commands.setHandlers;
  2785. return Reflect.apply(fun, that, args);
  2786. }
  2787. });
  2788. }
  2789. return Reflect.apply(fun, that, args);
  2790. }
  2791. });
  2792. }
  2793. return Reflect.apply(module, that, args);
  2794. }
  2795. });
  2796. }
  2797. di[name] = vl;
  2798. return true;
  2799. }
  2800. });
  2801. }
  2802. });
  2803. // don't send errorception logs
  2804. Object.defineProperty(win, 'onerror', {
  2805. set: vl => log && _console.warn('Skipped global onerror callback', vl)
  2806. });
  2807. });
  2808.  
  2809. scripts['draug.ru'] = {
  2810. other: ['vargr.ru'],
  2811. now: () => scriptLander(() => {
  2812. if (location.pathname === '/pop.html')
  2813. win.close();
  2814. createStyle([
  2815. '#timer_1 { display: none !important }',
  2816. '#timer_2 { display: block !important }'
  2817. ]);
  2818. let _contentWindow = Object.getOwnPropertyDescriptor(HTMLIFrameElement.prototype, 'contentWindow');
  2819. let _get_contentWindow = Function.prototype.apply.bind(_contentWindow.get);
  2820. _contentWindow.get = function() {
  2821. let res = _get_contentWindow(this);
  2822. if (res.location.href === 'about:blank')
  2823. res.document.write = (...args) => _console.log('Skipped iframe.write(', ...args, ')');
  2824. return res;
  2825. };
  2826. Object.defineProperty(HTMLIFrameElement.prototype, 'contentWindow', _contentWindow);
  2827. }),
  2828. dom: () => {
  2829. let list = _querySelectorAll('div[id^="yandex_rtb_"], .adsbygoogle');
  2830. list.forEach(node => _console.log('Removed:', node.parentNode.parentNode.removeChild(node.parentNode)));
  2831. }
  2832. };
  2833.  
  2834. scripts['drive2.ru'] = () => {
  2835. selectiveCookies();
  2836. gardener('.c-block:not([data-metrika="recomm"]),.o-grid__item', />Реклама<\//i);
  2837. scriptLander(() => {
  2838. let _d2 = void 0;
  2839. Object.defineProperty(win, 'd2', {
  2840. get: () => _d2,
  2841. set: o => {
  2842. if (o === _d2)
  2843. return true;
  2844. _d2 = new Proxy(o, {
  2845. set: (tgt, prop, val) => {
  2846. if (['brandingRender', 'dvReveal', '__dv'].includes(prop))
  2847. val = () => null;
  2848. tgt[prop] = val;
  2849. return true;
  2850. }
  2851. });
  2852. }
  2853. });
  2854. let nt = new nullTools();
  2855. nt.define(Object.prototype, 'initYaDirect', void 0, false);
  2856. }, nullTools);
  2857. };
  2858.  
  2859. scripts['echo.msk.ru'] = () => {
  2860. selectiveCookies();
  2861. selectiveEval(evalPatternYandex, /^document\.write/, /callAdblock/);
  2862. }
  2863.  
  2864. scripts['fastpic.ru'] = () => {
  2865. let nt = new nullTools();
  2866. // Had to obfuscate property name to avoid triggering anti-obfuscation on greasyfork.org -_- (Exception 403012)
  2867. nt.define(win, `_0x${'4955'}`, []);
  2868. };
  2869.  
  2870. scripts['fishki.net'] = () => {
  2871. scriptLander(() => {
  2872. let nt = new nullTools();
  2873. let fishki = {};
  2874. nt.define(fishki, 'adv', nt.proxy({
  2875. afterAdblockCheck: nt.func(null),
  2876. refreshFloat: nt.func(null)
  2877. }));
  2878. nt.define(fishki, 'is_adblock', false);
  2879. nt.define(win, 'fishki', fishki);
  2880. }, nullTools);
  2881. gardener('.drag_list > .drag_element, .list-view > .paddingtop15, .post-wrap', /543769|Новости\sпартнеров|Полезная\sреклама/);
  2882. };
  2883.  
  2884. scripts['friends.in.ua'] = () => scriptLander(() => {
  2885. Object.defineProperty(win, 'need_warning', {
  2886. get: () => 0, set: () => null
  2887. });
  2888. });
  2889.  
  2890. scripts['gidonline.club'] = () => createStyle('.tray > div[style] {display: none!important}');
  2891.  
  2892. scripts['hdgo.cc'] = {
  2893. other: ['46.30.43.38', 'couber.be'],
  2894. now: () => (new MutationObserver(
  2895. (ms) => {
  2896. let m, node;
  2897. for (m of ms) for (node of m.addedNodes)
  2898. if (node.tagName instanceof HTMLScriptElement && _getAttribute(node, 'onerror') !== null)
  2899. node.removeAttribute('onerror');
  2900. }
  2901. )).observe(_document.documentElement, { childList:true, subtree: true })
  2902. };
  2903.  
  2904. scripts['gismeteo.ru'] = {
  2905. other: ['gismeteo.by', 'gismeteo.kz', 'gismeteo.ua'],
  2906. now: () => {
  2907. selectiveCookies('ab_[^=]*|redirect|_gab');
  2908. gardener('div > script', /AdvManager/i, { observe: true, parent: 'div' })
  2909. }
  2910. };
  2911.  
  2912. scripts['hdrezka.ag'] = () => {
  2913. Object.defineProperty(win, 'ab', { value: false, enumerable: true });
  2914. gardener('div[id][onclick][onmouseup][onmousedown]', /onmouseout/i);
  2915. };
  2916.  
  2917. scripts['hqq.tv'] = () => scriptLander(() => {
  2918. // disable anti-debugging in hqq.tv player
  2919. 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);
  2920. deepWrapAPI(root => {
  2921. // skip obfuscated stuff and a few other calls
  2922. let _setInterval = root.setInterval,
  2923. _setTimeout = root.setTimeout,
  2924. _toString = root.Function.prototype.call.bind(root.Function.prototype.toString);
  2925. root.setInterval = (...args) => {
  2926. let fun = args[0];
  2927. if (fun instanceof Function) {
  2928. let text = _toString(fun),
  2929. skip = text.includes('check();') || isObfuscated(text);
  2930. _console.warn('setInterval', text, 'skip', skip);
  2931. if (skip) return -1;
  2932. }
  2933. return _setInterval.apply(this, args);
  2934. };
  2935. let wrappedST = new WeakSet();
  2936. root.setTimeout = (...args) => {
  2937. let fun = args[0];
  2938. if (fun instanceof Function) {
  2939. let text = _toString(fun),
  2940. skip = fun.name === 'check' || isObfuscated(text);
  2941. if (!wrappedST.has(fun)) {
  2942. _console.warn('setTimeout', text, 'skip', skip);
  2943. wrappedST.add(fun);
  2944. }
  2945. if (skip) return;
  2946. }
  2947. return _setTimeout.apply(this, args);
  2948. };
  2949. // skip 'debugger' call
  2950. let _eval = root.eval;
  2951. root.eval = text => {
  2952. if (typeof text === 'string' && text.includes('debugger;')) {
  2953. _console.warn('skip eval', text);
  2954. return;
  2955. }
  2956. _eval(text);
  2957. };
  2958. // Prevent RegExpt + toString trick
  2959. let _proto = void 0;
  2960. try {
  2961. _proto = root.RegExp.prototype;
  2962. } catch(ignore) {
  2963. return;
  2964. }
  2965. let _RE_tS = Object.getOwnPropertyDescriptor(_proto, 'toString');
  2966. let _RE_tSV = _RE_tS.value || _RE_tS.get();
  2967. Object.defineProperty(_proto, 'toString', {
  2968. enumerable: _RE_tS.enumerable,
  2969. configurable: _RE_tS.configurable,
  2970. get: () => _RE_tSV,
  2971. set: val => _console.warn('Attempt to change toString for', this, 'with', _toString(val))
  2972. });
  2973. });
  2974. }, deepWrapAPI);
  2975.  
  2976. scripts['hideip.me'] = {
  2977. now: () => scriptLander(() => {
  2978. let _innerHTML = Object.getOwnPropertyDescriptor(_Element, 'innerHTML');
  2979. let _set_innerHTML = _innerHTML.set;
  2980. let _innerText = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'innerText');
  2981. let _get_innerText = _innerText.get;
  2982. let div = _document.createElement('div');
  2983. _innerHTML.set = function(...args) {
  2984. _set_innerHTML.call(div, args[0].replace('i','a'));
  2985. if (args[0] && /[рp][еe]кл/.test(_get_innerText.call(div))||
  2986. /(\d\d\d?\.){3}\d\d\d?:\d/.test(_get_innerText.call(this)) ) {
  2987. _console.log('Anti-Adblock killed.');
  2988. return true;
  2989. }
  2990. _set_innerHTML.apply(this, args);
  2991. };
  2992. Object.defineProperty(_Element, 'innerHTML', _innerHTML);
  2993. Object.defineProperty(win, 'adblock', {
  2994. get: () => false,
  2995. set: () => null,
  2996. enumerable: true
  2997. });
  2998. let _$ = {};
  2999. let _$_map = new WeakMap();
  3000. let _gOPD = Object.getOwnPropertyDescriptor(Object, 'getOwnPropertyDescriptor');
  3001. let _val_gOPD = _gOPD.value;
  3002. _gOPD.value = function(...args) {
  3003. let _res = _val_gOPD.apply(this, args);
  3004. if (args[0] instanceof Window && (args[1] === '$' || args[1] === 'jQuery')) {
  3005. delete _res.get;
  3006. delete _res.set;
  3007. _res.value = win[args[1]];
  3008. }
  3009. return _res;
  3010. };
  3011. Object.defineProperty(Object, 'getOwnPropertyDescriptor', _gOPD);
  3012. let getJQWrap = (n) => {
  3013. let name = n;
  3014. return {
  3015. enumerable: true,
  3016. get: () => _$[name],
  3017. set: x => {
  3018. if (_$_map.has(x)) {
  3019. _$[name] = _$_map.get(x);
  3020. return true;
  3021. }
  3022. if (x === _$.$ || x === _$.jQuery) {
  3023. _$[name] = x;
  3024. return true;
  3025. }
  3026. _$[name] = new Proxy(x, {
  3027. apply: (t, o, args) => {
  3028. let _res = t.apply(o, args);
  3029. if (_$_map.has(_res.is))
  3030. _res.is = _$_map.get(_res.is);
  3031. else {
  3032. let _is = _res.is;
  3033. _res.is = function(...args) {
  3034. if (args[0] === ':hidden')
  3035. return false;
  3036. return _is.apply(this, args);
  3037. };
  3038. _$_map.set(_is, _res.is);
  3039. }
  3040. return _res;
  3041. }
  3042. });
  3043. _$_map.set(x, _$[name]);
  3044. return true;
  3045. }
  3046. };
  3047. };
  3048. Object.defineProperty(win, '$', getJQWrap('$'));
  3049. Object.defineProperty(win, 'jQuery', getJQWrap('jQuery'));
  3050. let _dP = Object.defineProperty;
  3051. Object.defineProperty = function(...args) {
  3052. if (args[0] instanceof Window && (args[1] === '$' || args[1] === 'jQuery'))
  3053. return void 0;
  3054. return _dP.apply(this, args);
  3055. };
  3056. })
  3057. };
  3058.  
  3059. scripts['igra-prestoloff.cx'] = () => scriptLander(() => {
  3060. let nt = new nullTools();
  3061. /*jslint evil: true */ // yes, evil, I know
  3062. let _write = _document.write.bind(_document);
  3063. /*jslint evil: false */
  3064. nt.define(_document, 'write', t => {
  3065. let id = t.match(/jwplayer\("(\w+)"\)/i);
  3066. if (id && id[1])
  3067. return _write(`<div id="${id[1]}"></div>${t}`);
  3068. return _write('');
  3069. });
  3070. });
  3071.  
  3072. scripts['imageban.ru'] = () => { Object.defineProperty(win, 'V7x1J', { get: () => null }); };
  3073.  
  3074. scripts['inoreader.com'] = () => scriptLander(() => {
  3075. let i = setInterval(() => {
  3076. if ('adb_detected' in win) {
  3077. win.adb_detected = () => adb_not_detected();
  3078. clearInterval(i);
  3079. }
  3080. }, 10);
  3081. _document.addEventListener('DOMContentLoaded', () => clearInterval(i), false);
  3082. });
  3083.  
  3084. scripts['ivi.ru'] = () => {
  3085. let _xhr_open = win.XMLHttpRequest.prototype.open;
  3086. win.XMLHttpRequest.prototype.open = function(method, url, ...args) {
  3087. if (typeof url === 'string')
  3088. if (url.endsWith('/track'))
  3089. return;
  3090. return _xhr_open.call(this, method, url, ...args);
  3091. };
  3092. let _responseText = Object.getOwnPropertyDescriptor(XMLHttpRequest.prototype, 'responseText');
  3093. let _responseText_get = _responseText.get;
  3094. _responseText.get = function() {
  3095. if (this.__responseText__)
  3096. return this.__responseText__;
  3097. let res = _responseText_get.apply(this, arguments);
  3098. let o;
  3099. try {
  3100. if (res)
  3101. o = JSON.parse(res);
  3102. } catch(ignore) {};
  3103. let changed = false;
  3104. if (o && o.result) {
  3105. if (o.result instanceof Array &&
  3106. 'adv_network_logo_url' in o.result[0]) {
  3107. o.result = [];
  3108. changed = true;
  3109. }
  3110. if (o.result.show_adv) {
  3111. o.result.show_adv = false;
  3112. changed = true;
  3113. }
  3114. }
  3115. if (changed) {
  3116. _console.log('changed response >>', o);
  3117. res = JSON.stringify(o);
  3118. }
  3119. this.__responseText__ = res;
  3120. return res;
  3121. };
  3122. Object.defineProperty(XMLHttpRequest.prototype, 'responseText', _responseText);
  3123. };
  3124.  
  3125. scripts['kinopoisk.ru'] = () => {
  3126. selectiveCookies('cmtchd|crookie|kpunk');
  3127. // set no-branding body style and adjust other blocks on the page
  3128. let style = [
  3129. '.app__header.app__header_margin-bottom_brand, #top { margin-bottom: 20px !important }',
  3130. '.app__branding { display: none !important}'
  3131. ];
  3132. if (location.hostname === 'www.kinopoisk.ru' && !location.pathname.startsWith('/games/'))
  3133. style.push('html:not(#id), body:not(#id), .app-container { background: #d5d5d5 url(/images/noBrandBg.jpg) 50% 0 no-repeat !important }');
  3134. createStyle(style);
  3135. // catch branding and other things
  3136. let _KP = void 0;
  3137. Object.defineProperty(win, 'KP', {
  3138. get: () => _KP,
  3139. set: val => {
  3140. if (_KP === val)
  3141. return true;
  3142. _KP = new Proxy(val, {
  3143. set: (kp, name, val) => {
  3144. if (name === 'branding') {
  3145. kp[name] = new Proxy({ weborama: {} }, {
  3146. get: (kp, name) => name in kp ? kp[name] : '',
  3147. set: () => true
  3148. });
  3149. return true;
  3150. }
  3151. if (name === 'config')
  3152. val = new Proxy(val, {
  3153. set: (cfg, name, val) => {
  3154. if (name === 'anContextUrl')
  3155. return true;
  3156. if (name === 'adfoxEnabled' || name === 'hasBranding')
  3157. val = false;
  3158. if (name === 'adfoxVideoAdUrls')
  3159. val = {flash:{}, html:{}};
  3160. cfg[name] = val;
  3161. return true;
  3162. }
  3163. });
  3164. kp[name] = val;
  3165. return true;
  3166. }
  3167. });
  3168. _console.log('KP =', val);
  3169. }
  3170. });
  3171. // skip branding and some other junk
  3172. if (!('advBlock' in win))
  3173. Object.defineProperty(win, 'advBlock', {
  3174. get: () => () => null,
  3175. set: () => true
  3176. });
  3177. // skip timeout check for blocked requests
  3178. let _setTimeout = Function.prototype.apply.bind(win.setTimeout);
  3179. let _toString = Function.prototype.apply.bind(Function.prototype.toString);
  3180. win.setTimeout = function(...args) {
  3181. if (args[1] === 100) {
  3182. let str = _toString(args[0]);
  3183. if (str.endsWith('{a()}') || str.endsWith('{n()}'))
  3184. return;
  3185. }
  3186. return _setTimeout(this, args);
  3187. };
  3188. };
  3189.  
  3190. scripts['korrespondent.net'] = {
  3191. now: () => scriptLander(() => {
  3192. let nt = new nullTools();
  3193. nt.define(win, 'holder', function(id) {
  3194. let div = _document.getElementById(id);
  3195. if (!div)
  3196. return;
  3197. if (div.parentNode.classList.contains('col__sidebar')) {
  3198. div.parentNode.appendChild(div);
  3199. div.style.height = '300px';
  3200. }
  3201. });
  3202. }, nullTools),
  3203. dom: () => {
  3204. for (let frame of _document.querySelectorAll('.unit-side-informer > iframe'))
  3205. frame.parentNode.style.width = '1px';
  3206. }
  3207. };
  3208.  
  3209. scripts['liveinternet.ru'] = () => selectiveEval(evalPatternYandex);
  3210.  
  3211. scripts['mail.ru'] = {
  3212. other: ['ok.ru', 'sportmail.ru'],
  3213. now: () => {
  3214. selectiveCookies('act|testcookie');
  3215. scriptLander(() => {
  3216. let _hostparts = location.hostname.split('.');
  3217. let _subdomain = _hostparts.slice(-3).join('.');
  3218. let _hostname = _hostparts.slice(-2).join('.');
  3219. let _emailru = _subdomain === 'e.mail.ru' || _subdomain === 'octavius.mail.ru';
  3220. // setTimeout filter
  3221. let pattern = /advBlock|rbParams/i;
  3222. let _toString = Function.prototype.call.bind(Function.prototype.toString);
  3223. let _setTimeout = Function.prototype.apply.bind(win.setTimeout);
  3224. win.setTimeout = function setTimeout(...args) {
  3225. let text = _toString(args[0]);
  3226. if (pattern.test(text)) {
  3227. _console.warn('Skipped setTimeout:', text);
  3228. return;
  3229. }// else if (!text.includes('checkLoaded()'))
  3230. // _console.warn(text, args[1]);
  3231. return _setTimeout(this, args);
  3232. };
  3233.  
  3234. let nt = new nullTools();
  3235. // Trick to prevent mail.ru from removing 3rd-party styles
  3236. nt.define(win.Object.prototype, 'restoreVisibility', nt.func(null), false);
  3237. // Other Yandex Direct and other ads
  3238. nt.define(win.Object.prototype, 'initMimic', void 0, false);
  3239. nt.define(win.Object.prototype, 'hpConfig', void 0, false);
  3240. nt.define(win.Object.prototype, 'direct', void 0, false);
  3241. nt.define(win.Object.prototype, 'getAds', void 0, false);
  3242. if (_hostname === 'mail.ru') {
  3243. if (_subdomain === _hostname)
  3244. nt.define(win.Object.prototype, 'baits', void 0, false);
  3245. if (!_emailru) {
  3246. nt.define(win.Object.prototype, 'mimic', void 0, false);
  3247. nt.define(win, 'createRadar', nt.func(nt.func(null, 'aRadar'), 'createRadar'));
  3248. } else nt.define(win, 'aRadar', nt.func(null, 'aRadar'));
  3249. }
  3250. // banners on ok.ru and another counter
  3251. nt.define(win, 'getAdvTargetParam', nt.func(null, 'getAdvTargetParam'));
  3252. nt.define(win, 'rb_bannerClick', nt.func(null, 'rb_bannerClick'));
  3253. nt.define(win, 'rb_banner', nt.func(null, 'rb_banner'));
  3254. nt.define(win, 'rb_tadq', nt.func(null, 'rb_tadq'));
  3255. nt.define(win, 'rb_counter', nt.func(null, 'rb_counter'));
  3256. // experimental stub for ok.ru
  3257. if (_hostname === 'ok.ru')
  3258. Object.defineProperty(Object.prototype, 'mrg-nano-xhr', {
  3259. set: () => true,
  3260. get: () => (_console.warn('return undefined instead of mrg-nano-xhr '), void 0)
  3261. });
  3262. // all the rest is only needed on main page and in emails
  3263. if (_subdomain !== 'mail.ru' && !_emailru/* && _hostname !== 'ok.ru'*/)
  3264. return;
  3265.  
  3266. // Disable page scrambler on mail.ru to let extensions easily block ads there
  3267. let logger = {
  3268. apply: (target, thisArg, args) => {
  3269. let res = target.apply(thisArg, args);
  3270. _console.log(`${target._name}(`, ...args, `)\n>>`, res);
  3271. return res;
  3272. }
  3273. };
  3274.  
  3275. function wrapLocator(locator) {
  3276. if ('setup' in locator) {
  3277. let _setup = locator.setup;
  3278. locator.setup = function(o) {
  3279. if ('enable' in o) {
  3280. o.enable = false;
  3281. _console.log('Disable mimic mode.');
  3282. }
  3283. if ('links' in o) {
  3284. o.links = [];
  3285. _console.log('Call with empty list of sheets.');
  3286. }
  3287. return _setup.call(this, o);
  3288. };
  3289. locator.insertSheet = () => false;
  3290. locator.wrap = () => false;
  3291. }
  3292. try {
  3293. let names = [];
  3294. for (let name in locator)
  3295. if (locator[name] instanceof Function && name !== 'transform') {
  3296. locator[name]._name = "locator." + name;
  3297. locator[name] = new Proxy(locator[name], logger);
  3298. names.push(name);
  3299. }
  3300. _console.log(`[locator] wrapped properties: ${names.length ? names.join(', ') : '[empty]'}`);
  3301. } catch(e) {
  3302. _console.log(e);
  3303. }
  3304. return locator;
  3305. }
  3306.  
  3307. function defineLocator(root) {
  3308. let _locator = root.locator;
  3309. let wrapLocatorSetter = vl => _locator = wrapLocator(vl);
  3310. let loc_desc = Object.getOwnPropertyDescriptor(root, 'locator');
  3311. if (!loc_desc || loc_desc.set !== wrapLocatorSetter)
  3312. try {
  3313. Object.defineProperty(root, 'locator', {
  3314. set: wrapLocatorSetter,
  3315. get: () => _locator
  3316. });
  3317. } catch (err) {
  3318. _console.log('Unable to redefine "locator" object!!!', err);
  3319. }
  3320. if (loc_desc.value)
  3321. _locator = wrapLocator(loc_desc.value);
  3322. }
  3323.  
  3324. {
  3325. let missingCheck = {
  3326. get: (obj, name) => {
  3327. if (!(name in obj))
  3328. _console.warn(obj, 'missing:', name);
  3329. return obj[name];
  3330. }
  3331. };
  3332. // wow, Mail.ru can't just keep base Array functionality alone >_<
  3333. let _reduce = Function.prototype.call.bind(Array.prototype.reduce);
  3334. let skipLog = (name, ret) => (...args) => (_console.log(`Skip ${name}(`, ...args, ')'), ret);
  3335. let createSkipLogObject = (baseName, list) => _reduce(
  3336. list,
  3337. (acc, cur) => (acc[cur] = skipLog(`${baseName}.${cur}`), acc),
  3338. {}
  3339. );
  3340. let _apply = Reflect.apply;
  3341. let redefiner = {
  3342. apply: (target, thisArg, args) => {
  3343. let res = void 0;
  3344. let warn = false;
  3345. let name = target._name;
  3346. if (name === 'mrg-smokescreen/Welter')
  3347. res = {
  3348. isWelter: () => true,
  3349. wrap: skipLog(`${name}.wrap`)
  3350. };
  3351. if (name === 'mrg-smokescreen/StyleSheets')
  3352. res = createSkipLogObject(name, ['update', 'remove', 'insert', 'setup']);
  3353. if (name === 'mrg-smokescreen/Honeypot')
  3354. res = {
  3355. check: (...args) => (_console.log(`${name}.check(`, ...args, ')'), new Promise(() => void 0)),
  3356. version: "-1"
  3357. }
  3358. /*
  3359. if (name.startsWith('OK/banners/'))
  3360. res = createSkipLogObject(name, ['activate', 'ready', 'detectAdBlock', 'onHooksReady']);
  3361. if (name === 'OK/Smokescreen')
  3362. res = {
  3363. getLocator: skipLog(`${name}.getLocator`, void 0),
  3364. getById: id => {
  3365. let e = _document.getElementById(id);
  3366. if (e && !e.logged) {
  3367. _console.log(`${name}.getById(`, id, ') >', e);
  3368. e.logged = true;
  3369. }
  3370. return e;
  3371. }
  3372. };
  3373. */
  3374. if (name === 'advert/adman/adman') {
  3375. res = createSkipLogObject(name, ['deleteRBParams', 'getBlock', 'hasBlocker', 'init', 'refresh', 'setForceMimic', 'setRBParams']);
  3376. let features = { siteZones: {}, slots: {} };
  3377. [
  3378. 'expId', 'siteId', 'mimicEndpoint', 'mimicPartnerId', 'immediateFetchTimeout', 'delayedFetchTimeout'
  3379. ].forEach(name => void (features[name] = null));
  3380. res.getFeatures = skipLog('advert/adman/adman.getFeatures', features);
  3381. }
  3382. if (res) {
  3383. Object.defineProperty(res, Symbol.toStringTag, {
  3384. get: () => `Skiplog object for ${name}`
  3385. });
  3386. Object.defineProperty(res, Symbol.toPrimitive, {
  3387. value: function(hint) {
  3388. if (hint === 'string')
  3389. return Object.prototype.toString.call(this);
  3390. return `[missing toPrimitive] ${name} ${hint}`;
  3391. }
  3392. });
  3393. res = new Proxy(res, missingCheck);
  3394. } else {
  3395. res = _apply(target, thisArg, args);
  3396. warn = true;
  3397. }
  3398. if (name === 'mrg-smokescreen/Utils')
  3399. res.extend = function(...args) {
  3400. let res = {
  3401. enable: false,
  3402. match: [],
  3403. links: []
  3404. };
  3405. _console.log(`${name}.extend(`, ...args, ') >>', res );
  3406. return res;
  3407. };
  3408. _console[warn?'warn':'log'](name, '(',...args,')\n>>', res);
  3409. return res;
  3410. }
  3411. };
  3412.  
  3413. let advModuleNamesStartWith = /^(mrg-(context|honeypot)|adv\/)/;
  3414. let advModuleNamesGeneric = /advert|banner|mimic|smoke/i;
  3415. let wrapAdFuncs = {
  3416. apply: (target, thisArg, args) => {
  3417. let module = args[0];
  3418. if (typeof module === 'string')
  3419. if ((advModuleNamesStartWith.test(module) ||
  3420. advModuleNamesGeneric.test(module)) &&
  3421. // fix for e.mail.ru in Fx56 and below, looks like Proxy is quirky there
  3422. !module.startsWith('patron.v2.')) {
  3423. let fun = args[args.length-1];
  3424. fun._name = module;
  3425. args[args.length-1] = new Proxy(fun, redefiner);
  3426. }
  3427. return _apply(target, thisArg, args);
  3428. }
  3429. };
  3430. let wrapDefine = def => {
  3431. if (!def)
  3432. return;
  3433. _console.log('define =', def);
  3434. def = new Proxy(def, wrapAdFuncs);
  3435. def._name = 'define';
  3436. return def;
  3437. };
  3438. let _define = wrapDefine(win.define);
  3439. Object.defineProperty(win, 'define', {
  3440. get: () => _define,
  3441. set: x => {
  3442. if (_define === x)
  3443. return true;
  3444. _define = wrapDefine(x);
  3445. return true;
  3446. }
  3447. });
  3448. }
  3449.  
  3450. let _honeyPot;
  3451. function defineDetector(mr) {
  3452. let __ = mr._ || {};
  3453. let setHoneyPot = o => {
  3454. if (!o || o === _honeyPot) return;
  3455. _console.log('[honeyPot]', o);
  3456. _honeyPot = function() {
  3457. this.check = new Proxy(() => {
  3458. __.STUCK_IN_POT = false;
  3459. return false;
  3460. }, logger);
  3461. this.check._name = 'honeyPot.check';
  3462. this.destroy = () => null;
  3463. };
  3464. };
  3465. if ('honeyPot' in mr)
  3466. setHoneyPot(mr.honeyPot);
  3467. else
  3468. Object.defineProperty(mr, 'honeyPot', {
  3469. get: () => _honeyPot,
  3470. set: setHoneyPot
  3471. });
  3472.  
  3473. __ = new Proxy(__, {
  3474. get: (t, p) => t[p],
  3475. set: (t, p, v) => {
  3476. _console.log(`mr._.${p} =`, v);
  3477. t[p] = v;
  3478. return true;
  3479. }
  3480. });
  3481. mr._ = __;
  3482. }
  3483.  
  3484. function defineAdd(mr) {
  3485. let _add;
  3486. let addWrapper = {
  3487. apply: (tgt, that, args) => {
  3488. let module = args[0];
  3489. if (typeof module === 'string' && module.startsWith('ad')) {
  3490. _console.log('Skip module:', module);
  3491. return;
  3492. }
  3493. if (typeof module === 'object' && module.name.startsWith('ad'))
  3494. _console.log('Loaded module:', module);
  3495. return logger.apply(tgt, that, args);
  3496. }
  3497. };
  3498. let setMrAdd = v => {
  3499. if (!v) return;
  3500. v._name = 'mr.add';
  3501. v = new Proxy(v, addWrapper);
  3502. _add = v;
  3503. };
  3504. if ('add' in mr)
  3505. setMrAdd(mr.add);
  3506. Object.defineProperty(mr, 'add', {
  3507. get: () => _add,
  3508. set: setMrAdd
  3509. });
  3510.  
  3511. }
  3512.  
  3513. let _mr_wrapper = vl => {
  3514. defineLocator(vl.mimic ? vl.mimic : vl);
  3515. defineDetector(vl);
  3516. defineAdd(vl);
  3517. return vl;
  3518. };
  3519. if ('mr' in win) {
  3520. _console.log('Found existing "mr" object.');
  3521. win.mr = _mr_wrapper(win.mr);
  3522. } else {
  3523. let _mr = void 0;
  3524. Object.defineProperty(win, 'mr', {
  3525. get: () => _mr,
  3526. set: vl => { _mr = _mr_wrapper(vl) },
  3527. configurable: true
  3528. });
  3529. let _defineProperty = Function.prototype.apply.bind(Object.defineProperty);
  3530. Object.defineProperty = function defineProperty(o, name, conf) {
  3531. if (name === 'mr' && o instanceof Window) {
  3532. _console.warn('Object.defineProperty(', ...arguments, ')');
  3533. conf.set(_mr_wrapper(conf.get()));
  3534. }
  3535. if ((name === 'honeyPot' || name === 'add') && _mr === o && conf.set)
  3536. return;
  3537. return _defineProperty(this, arguments);
  3538. };
  3539. }
  3540. }, nullTools);
  3541. }
  3542. };
  3543.  
  3544. scripts['oms.matchat.online'] = () => scriptLander(() => {
  3545. let _rmpGlobals = void 0;
  3546. Object.defineProperty(win, 'rmpGlobals', {
  3547. get: () => _rmpGlobals,
  3548. set: x => {
  3549. if (x === _rmpGlobals)
  3550. return true;
  3551. _rmpGlobals = new Proxy(x, {
  3552. get: (obj, name) => {
  3553. if (name === 'adBlockerDetected')
  3554. return false;
  3555. return obj[name];
  3556. },
  3557. set: (obj, name, val) => {
  3558. if (name === 'adBlockerDetected')
  3559. _console.warn('rmpGlobals.adBlockerDetected =', val)
  3560. else
  3561. obj[name] = val;
  3562. return true;
  3563. }
  3564. });
  3565. }
  3566. });
  3567. });
  3568.  
  3569. scripts['megogo.net'] = {
  3570. now: () => {
  3571. let nt = new nullTools();
  3572. nt.define(win, 'adBlock', false);
  3573. nt.define(win, 'showAdBlockMessage', nt.func(null));
  3574. }
  3575. };
  3576.  
  3577. scripts['n-torrents.org'] = () => scriptLander(() => {
  3578. let _$ = void 0;
  3579. Object.defineProperty(win, '$', {
  3580. get: () => _$,
  3581. set: vl => {
  3582. _$ = vl;
  3583. if (!vl.fn)
  3584. return true;
  3585. let _videoPopup = vl.fn.videoPopup;
  3586. Object.defineProperty(vl.fn, 'videoPopup', {
  3587. get: () => _videoPopup,
  3588. set: vl => {
  3589. if (vl === _videoPopup)
  3590. return true;
  3591. _videoPopup = new Proxy(vl, {
  3592. apply: (fun, obj, args) => {
  3593. let opts = args[0];
  3594. if (opts) {
  3595. opts.adv = '';
  3596. opts.duration = 0;
  3597. }
  3598. return Reflect.apply(fun, obj, args);
  3599. }
  3600. });
  3601. return true;
  3602. }
  3603. });
  3604. return true
  3605. }
  3606. });
  3607. });
  3608.  
  3609. scripts['naruto-base.su'] = () => gardener('div[id^="entryID"],.block', /href="http.*?target="_blank"/i);
  3610.  
  3611. scripts['newdeaf-online.net'] = {
  3612. dom: () => {
  3613. let adNodes = _document.querySelectorAll('.ads');
  3614. if (!adNodes)
  3615. return;
  3616. let getter = x => {
  3617. let val = x;
  3618. return () => (_console.warn('read .ads', name, val), val);
  3619. };
  3620. let setter = x => _console.warn('skip write .ads', name, x);
  3621. for (let adNode of adNodes)
  3622. for (let name of ['innerHTML'])
  3623. Object.defineProperty(adNode, name, {
  3624. get: getter(ads[name]),
  3625. set: setter
  3626. });
  3627. }
  3628. };
  3629.  
  3630. scripts['overclockers.ru'] = {
  3631. dom: () => scriptLander(() => {
  3632. let killed = () => _console.warn('Anti-Adblock killed.');
  3633. if ('$' in win)
  3634. win.$ = new Proxy($, {
  3635. apply: (tgt, that, args) => {
  3636. let res = tgt.apply(that, args);
  3637. if (res[0] && res[0] === _document.body) {
  3638. res.html = killed;
  3639. res.empty = killed;
  3640. }
  3641. return res;
  3642. }
  3643. });
  3644. })
  3645. };
  3646. scripts['forums.overclockers.ru'] = {
  3647. now: () => {
  3648. createStyle('.needblock {position: fixed; left: -10000px}');
  3649. Object.defineProperty(win, 'adblck', {
  3650. get: () => 'no',
  3651. set: () => undefined,
  3652. enumerable: true
  3653. });
  3654. }
  3655. };
  3656.  
  3657. scripts['pb.wtf'] = {
  3658. other: ['piratbit.org', 'piratbit.ru'],
  3659. dom: () => {
  3660. // line above topic content and images in the slider in the header
  3661. let remove = node => (_console.log('removed', node), node.parentNode.removeChild(node));
  3662. for (let el of _document.querySelectorAll('.release-block-img a, #page_content a')) {
  3663. if (location.hostname === el.hostname &&
  3664. /^\/(\w{3}|exit)\/[\w=/]{20,}$/.test(el.pathname)) {
  3665. remove(el.closest('div, tr'));
  3666. continue;
  3667. }
  3668. // ads in the topic header in case filter above wasn't enough
  3669. let parent = el.closest('tr');
  3670. if (parent) {
  3671. let span = (parent.querySelector('span') || {}).textContent;
  3672. span && span.startsWith('YO!') && remove(parent);
  3673. }
  3674. }
  3675. // casino ad button in random places
  3676. for (let el of _document.querySelectorAll('.btn-group')) {
  3677. el = el.parentNode;
  3678. if (el.tagName === 'CENTER')
  3679. remove(el.parentNode);
  3680. }
  3681. // ads in comments
  3682. let el = _document.querySelector('thead + tbody[id^="post_"] + tbody[class*=" "]');
  3683. if (el && el.parentNode.children[2] == el)
  3684. remove(el);
  3685. }
  3686. };
  3687.  
  3688. scripts['pikabu.ru'] = () => gardener('.story', /story__author[^>]+>ads</i, {root: '.inner_wrap', observe: true});
  3689.  
  3690. scripts['peka2.tv'] = () => {
  3691. let bodyClass = 'body--branding';
  3692. let checkNode = node => {
  3693. for (let className of node.classList)
  3694. if (className.includes('banner') || className === bodyClass) {
  3695. _removeAttribute(node, 'style');
  3696. node.classList.remove(className);
  3697. for (let attr of Array.from(node.attributes))
  3698. if (attr.name.startsWith('advert'))
  3699. _removeAttribute(node, attr.name);
  3700. }
  3701. };
  3702. (new MutationObserver(ms => {
  3703. let m, node;
  3704. for (m of ms) for (node of m.addedNodes)
  3705. if (node instanceof HTMLElement)
  3706. checkNode(node);
  3707. })).observe(_de, {childList: true, subtree: true});
  3708. (new MutationObserver(ms => {
  3709. for (let m of ms)
  3710. checkNode(m.target);
  3711. })).observe(_de, {attributes: true, subtree: true, attributeFilter: ['class']});
  3712. };
  3713.  
  3714. scripts['qrz.ru'] = {
  3715. now: () => {
  3716. let nt = new nullTools();
  3717. nt.define(win, 'ab', false);
  3718. nt.define(win, 'tryMessage', nt.func(null));
  3719. }
  3720. };
  3721.  
  3722. scripts['razlozhi.ru'] = {
  3723. now: () => {
  3724. let nt = new nullTools();
  3725. nt.define(win, 'cadb', false);
  3726. for (let func of ['createShadowRoot', 'attachShadow'])
  3727. if (func in _Element)
  3728. _Element[func] = function(){
  3729. return this.cloneNode();
  3730. };
  3731. }
  3732. };
  3733.  
  3734. scripts['rbc.ru'] = {
  3735. other: ['autonews.ru', 'rbcplus.ru', 'sportrbc.ru'],
  3736. now: () => {
  3737. selectiveCookies('adb_on');
  3738. let _RA = void 0;
  3739. let setArgs = {
  3740. 'showBanners': true,
  3741. 'showAds': true,
  3742. 'banners.staticPath': '',
  3743. 'paywall.staticPath': '',
  3744. 'banners.dfp.config': [],
  3745. 'banners.dfp.pageTargeting': () => null,
  3746. };
  3747. Object.defineProperty(win, 'RA', {
  3748. get: () => _RA,
  3749. set: vl => {
  3750. _console.log('RA =', vl);
  3751. if ('repo' in vl) {
  3752. _console.log('RA.repo =', vl.repo);
  3753. vl.repo = new Proxy(vl.repo, {
  3754. set: (o, name, val) => {
  3755. if (name === 'banner') {
  3756. _console.log(`RA.repo.${name} =`, val);
  3757. val = new Proxy(val, {
  3758. get: (o, name) => {
  3759. let res = o[name];
  3760. if (typeof o[name] === 'function') {
  3761. res = () => null;
  3762. res.toString = o[name].toString.bind(o[name]);
  3763. }
  3764. if (name === 'isInited')
  3765. res = true;
  3766. _console.warn(`get RA.repo.banner.${name}`, res);
  3767. return res;
  3768. }
  3769. });
  3770. }
  3771. o[name] = val;
  3772. return true;
  3773. }
  3774. });
  3775. } else
  3776. _console.log('Unable to locate RA.repo');
  3777. _RA = new Proxy(vl, {
  3778. set: (o, name, val) => {
  3779. if (name === 'config') {
  3780. _console.log('RA.config =', val);
  3781. if ('set' in val) {
  3782. val.set = new Proxy(val.set, {
  3783. apply: (set, that, args) => {
  3784. let name = args[0];
  3785. if (name in setArgs)
  3786. args[1] = setArgs[name];
  3787. if (name in setArgs || name === 'checkad')
  3788. _console.log('RA.config.set(', ...args, ')');
  3789. return Reflect.apply(set, that, args);
  3790. }
  3791. });
  3792. val.set('showAds', true); // pretend ads already were shown
  3793. }
  3794. }
  3795. o[name] = val;
  3796. return true;
  3797. }
  3798. });
  3799. }
  3800. });
  3801. Object.defineProperty(win, 'bannersConfig', {
  3802. get: () => [], set: () => null
  3803. });
  3804. // pretend there is a paywall landing on screen already
  3805. let pwl = _document.createElement('div');
  3806. pwl.style.display = 'none';
  3807. pwl.className = 'js-paywall-landing';
  3808. _document.documentElement.appendChild(pwl);
  3809. // detect and skip execution of one of the ABP detectors
  3810. let _setTimeout = Function.prototype.apply.bind(win.setTimeout);
  3811. let _toString = Function.prototype.call.bind(Function.prototype.toString);
  3812. win.setTimeout = function setTimeout() {
  3813. if (typeof arguments[0] === 'function') {
  3814. let fts = _toString(arguments[0]);
  3815. if (/\.length\s*>\s*0\s*&&/.test(fts) && /:hidden/.test(fts)) {
  3816. _console.log('Skipped setTimout(', fts, arguments[1], ')');
  3817. return;
  3818. }
  3819. }
  3820. return _setTimeout(this, arguments);
  3821. };
  3822. // hide banner placeholders
  3823. createStyle('[data-banner-id], .banner__container, .banners__yandex__article { display: none !important }');
  3824. },
  3825. dom: () => {
  3826. // hide sticky banner place at the top of the page
  3827. for (let itm of _document.querySelectorAll('.l-sticky'))
  3828. if (itm.querySelector('.banner__container__link'))
  3829. itm.style.display = 'none';
  3830. }
  3831. };
  3832.  
  3833. scripts['rp5.ru'] = {
  3834. other: ['rp5.by', 'rp5.kz', 'rp5.ua'],
  3835. now: () => {
  3836. Object.defineProperty(win, 'sContentBottom', {
  3837. get: () => '',
  3838. set: () => true
  3839. });
  3840. // skip timeout check for blocked requests
  3841. let _setTimeout = Function.prototype.apply.bind(win.setTimeout);
  3842. let _toString = Function.prototype.apply.bind(Function.prototype.toString);
  3843. win.setTimeout = function(...args) {
  3844. let str = (typeof args[0] === 'string' ? args[0] : _toString(args[0]));
  3845. if (str.includes('xvb')) {
  3846. _console.log('Blocked setTimeout for:', str);
  3847. return;
  3848. }
  3849. return _setTimeout(this, args);
  3850. };
  3851. },
  3852. dom: () => {
  3853. let node = selectNodeByTextContent('Разместить текстовое объявление', { root: _de.querySelector('#content-wrapper'), shallow: true });
  3854. if (node)
  3855. node.style.display = 'none';
  3856. }
  3857. };
  3858.  
  3859. scripts['rutube.ru'] = () => scriptLander(() => {
  3860. let _parse = JSON.parse;
  3861. let _skip_enabled = false;
  3862. JSON.parse = (...args) => {
  3863. let res = _parse(...args),
  3864. log = false;
  3865. if (!res)
  3866. return res;
  3867. // parse player configuration
  3868. if ('appearance' in res || 'video_balancer' in res) {
  3869. log = true;
  3870. if (res.appearance) {
  3871. if ('forbid_seek' in res.appearance && res.appearance.forbid_seek)
  3872. res.appearance.forbid_seek = false;
  3873. if ('forbid_timeline_preview' in res.appearance && res.appearance.forbid_timeline_preview)
  3874. res.appearance.forbid_timeline_preview = false;
  3875. }
  3876. _skip_enabled = !!res.remove_unseekable_blocks;
  3877. //res.advert = [];
  3878. delete res.advert;
  3879. //for (let limit of res.limits)
  3880. // limit.limit = 0;
  3881. delete res.limits;
  3882. //res.yast = null;
  3883. //res.yast_live_online = null;
  3884. delete res.yast;
  3885. delete res.yast_live_online;
  3886. Object.defineProperty(res, 'stat', {
  3887. get: () => [],
  3888. set: () => true,
  3889. enumerable: true
  3890. });
  3891. }
  3892.  
  3893. // parse video configuration
  3894. if ('video_url' in res) {
  3895. log = true;
  3896. if (res.cuepoints && !_skip_enabled)
  3897. for (let point of res.cuepoints) {
  3898. point.is_pause = false;
  3899. point.show_navigation = true;
  3900. point.forbid_seek = false;
  3901. }
  3902. }
  3903.  
  3904. if (log)
  3905. _console.log('[rutube]', res);
  3906. return res;
  3907. };
  3908. });
  3909.  
  3910. scripts['simpsonsua.com.ua'] = {
  3911. other: ['simpsonsua.tv'],
  3912. now: () => scriptLander(() => {
  3913. let _addEventListener = _Document.addEventListener;
  3914. _document.addEventListener = function(event, callback) {
  3915. if (event === 'DOMContentLoaded' && callback.toString().includes('show_warning'))
  3916. return;
  3917. return _addEventListener.apply(this, arguments);
  3918. };
  3919. let nt = new nullTools();
  3920. nt.define(win, 'need_warning', 0);
  3921. }, nullTools)
  3922. };
  3923.  
  3924. scripts['smotretanime.ru'] = () => scriptLander(() => {
  3925. deepWrapAPI(root => {
  3926. let _pause = root.Function.prototype.call.bind(root.Audio.prototype.pause);
  3927. let _addEventListener = root.Function.prototype.call.bind(root.Element.prototype.addEventListener);
  3928. let stopper = e => _pause(e.target);
  3929. root.Audio = new Proxy(root.Audio, {
  3930. construct: (audio, args) => {
  3931. let res = new audio(...args);
  3932. _addEventListener(res, 'play', stopper, true);
  3933. return res;
  3934. }
  3935. });
  3936. _createElement = root.Document.prototype.createElement;
  3937. root.Document.prototype.createElement = function createElement() {
  3938. let res = _createElement.apply(this, arguments);
  3939. if (res instanceof HTMLAudioElement)
  3940. _addEventListener(res, 'play', stopper, true);
  3941. return res;
  3942. };
  3943. });
  3944. }, deepWrapAPI);
  3945.  
  3946. scripts['spaces.ru'] = () => {
  3947. gardener('div:not(.f-c_fll) > a[href*="spaces.ru/?Cl="]', /./, { parent: 'div' });
  3948. gardener('.js-banner_rotator', /./, { parent: '.widgets-group' });
  3949. };
  3950.  
  3951. scripts['spam-club.blogspot.co.uk'] = () => {
  3952. let _clientHeight = Object.getOwnPropertyDescriptor(_Element, 'clientHeight'),
  3953. _clientWidth = Object.getOwnPropertyDescriptor(_Element, 'clientWidth');
  3954. let wrapGetter = (getter) => {
  3955. let _getter = getter;
  3956. return function() {
  3957. let _size = _getter.apply(this, arguments);
  3958. return _size ? _size : 1;
  3959. };
  3960. };
  3961. _clientHeight.get = wrapGetter(_clientHeight.get);
  3962. _clientWidth.get = wrapGetter(_clientWidth.get);
  3963. Object.defineProperty(_Element, 'clientHeight', _clientHeight);
  3964. Object.defineProperty(_Element, 'clientWidth', _clientWidth);
  3965. let _onload = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'onload'),
  3966. _set_onload = _onload.set;
  3967. _onload.set = function() {
  3968. if (this instanceof HTMLImageElement)
  3969. return true;
  3970. _set_onload.apply(this, arguments);
  3971. };
  3972. Object.defineProperty(HTMLElement.prototype, 'onload', _onload);
  3973. };
  3974.  
  3975. scripts['sport-express.ru'] = () => gardener('.js-relap__item',/>Реклама\s+<\//, {root:'.container', observe: true});
  3976.  
  3977. scripts['sports.ru'] = {
  3978. other: ['tribuna.com'],
  3979. now: () => {
  3980. // extra functionality: shows/hides panel at the top depending on scroll direction
  3981. createStyle([
  3982. '.user-panel__fixed { transition: top 0.2s ease-in-out!important; }',
  3983. '.popup__overlay.feedback { display: none!important }',
  3984. '.user-panel-up { top: -40px!important }',
  3985. '#branding-layout { margin-top: 100px!important }'
  3986. ], {id: 'fixes'}, false);
  3987. scriptLander(() => {
  3988. yandexRavenStub();
  3989. webpackJsonpFilter(/AdBlockDetector|addBranding|loadPlista/);
  3990. }, nullTools, yandexRavenStub);
  3991. },
  3992. dom: () => {
  3993. (function lookForPanel() {
  3994. let panel = _document.querySelector('.user-panel__fixed');
  3995. if (!panel)
  3996. setTimeout(lookForPanel, 100);
  3997. else
  3998. window.addEventListener(
  3999. 'wheel', function(e) {
  4000. if (e.deltaY > 0 && !panel.classList.contains('user-panel-up'))
  4001. panel.classList.add('user-panel-up');
  4002. else if (e.deltaY < 0 && panel.classList.contains('user-panel-up'))
  4003. panel.classList.remove('user-panel-up');
  4004. }, false
  4005. );
  4006. })();
  4007. }
  4008. };
  4009. scripts['stealthz.ru'] = {
  4010. dom: () => {
  4011. // skip timeout
  4012. let $ = _document.querySelector.bind(_document);
  4013. let [timer_1, timer_2] = [$('#timer_1'), $('#timer_2')];
  4014. if (!timer_1 || !timer_2)
  4015. return;
  4016. timer_1.style.display = 'none';
  4017. timer_2.style.display = 'block';
  4018. }
  4019. };
  4020.  
  4021. scripts['xatab-repack.net'] = {
  4022. other: ['rg-mechanics.org'],
  4023. now: () => scriptLander(() => {
  4024. Object.defineProperty(win, 'blocked', {
  4025. set: () => { throw 'and unlooked for.'; }
  4026. });
  4027. }, nullTools)
  4028. };
  4029.  
  4030. scripts['xittv.net'] = () => scriptLander(() => {
  4031. let logNames = ['setup', 'trigger', 'on', 'off', 'onReady', 'onError', 'getConfig', 'addPlugin', 'getAdBlock'];
  4032. let skipEvents = ['adComplete', 'adSkipped', 'adBlock', 'adRequest', 'adMeta', 'adImpression', 'adError', 'adTime', 'adStarted', 'adClick'];
  4033. let _jwplayer = void 0;
  4034. Object.defineProperty(win, 'jwplayer', {
  4035. get: () => _jwplayer,
  4036. set: x => {
  4037. _jwplayer = new Proxy(x, {
  4038. apply: (fun, that, args) => {
  4039. let res = fun.apply(that, args);
  4040. res = new Proxy(res, {
  4041. get: (obj, name) => {
  4042. if (logNames.includes(name) && obj[name] instanceof Function)
  4043. return new Proxy(obj[name], {
  4044. apply: (fun, that, args) => {
  4045. if (name === 'setup') {
  4046. let o = args[0];
  4047. if (o)
  4048. delete o.advertising;
  4049. }
  4050. if (name === 'on' || name === 'trigger') {
  4051. let events = typeof args[0] === 'string' ? args[0].split(" ") : null;
  4052. if (events.length === 1 && skipEvents.includes(events[0]))
  4053. return res;
  4054. if (events.length > 1) {
  4055. let names = [];
  4056. for (let event of events)
  4057. if (!skipEvents.includes(event))
  4058. names.push(event);
  4059. if (names.length > 0)
  4060. args[0] = names.join(" ");
  4061. else
  4062. return res;
  4063. }
  4064. }
  4065. let subres = fun.apply(that, args);
  4066. _console.warn(`jwplayer().${name}(`, ...args, `) >>`, res);
  4067. return subres;
  4068. }
  4069. });
  4070. return obj[name];
  4071. }
  4072. });
  4073. return res;
  4074. }
  4075. });
  4076. _console.log('jwplayer =', x);
  4077. }
  4078. });
  4079. });
  4080.  
  4081. scripts['yap.ru'] = {
  4082. other: ['yaplakal.com'],
  4083. now: () => {
  4084. gardener('form > table[id^="p_row_"]:nth-of-type(2)', /member1438|Administration/);
  4085. gardener('.icon-comments', /member1438|Administration|\/go\/\?http/, {parent:'tr', siblings:-2});
  4086. }
  4087. };
  4088.  
  4089. scripts['rambler.ru'] = {
  4090. other: ['championat.com', 'gazeta.ru', 'lenta.ru', 'media.eagleplatform.com', 'quto.ru', 'rns.online'],
  4091. now: () => {
  4092. selectiveCookies('detect_count');
  4093. scriptLander(() => {
  4094. // Prevent autoplay
  4095. if (!('EaglePlayer' in win)) {
  4096. let _EaglePlayer = void 0;
  4097. Object.defineProperty(win, 'EaglePlayer', {
  4098. enumerable: true,
  4099. get: () => _EaglePlayer,
  4100. set: x => {
  4101. if (x === _EaglePlayer)
  4102. return true;
  4103. _EaglePlayer = new Proxy(x, {
  4104. construct: (targ, args) => {
  4105. let player = new targ(...args);
  4106. if (!player.options) {
  4107. _console.log('EaglePlayer: no options', EaglePlayer);
  4108. return player;
  4109. }
  4110. Object.defineProperty(player.options, 'autoplay', {
  4111. get: () => false,
  4112. set: () => true
  4113. });
  4114. Object.defineProperty(player.options, 'scroll', {
  4115. get: () => false,
  4116. set: () => true
  4117. });
  4118. return player;
  4119. }
  4120. });
  4121. }
  4122. });
  4123. let _setAttribute = Function.prototype.apply.bind(_Element.setAttribute);
  4124. let isAutoplay = /^autoplay$/i;
  4125. _Element.setAttribute = function setAttribute(name) {
  4126. if (!this._stopped && isAutoplay.test(name)) {
  4127. _console.log('Prevented assigning autoplay attribute.');
  4128. return null;
  4129. }
  4130. return _setAttribute(this, arguments);
  4131. };
  4132. } else {
  4133. _console.log('EaglePlayer function already exists.');
  4134. if (inIFrame) {
  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. this._stopped = true;
  4141. this.play = () => {
  4142. _console.log('Prevented attempt to force-start playback.');
  4143. delete this.play;
  4144. };
  4145. return null;
  4146. }
  4147. return _setAttribute(this, arguments);
  4148. };
  4149. }
  4150. }
  4151. if (location.hostname.endsWith('.media.eagleplatform.com'))
  4152. return;
  4153. // Wrapper for adv loader settings in QW50aS1BZEJsb2Nr['7t7hystz']
  4154. let _contexts = new WeakMap();
  4155. Object.defineProperty(Object.prototype, 'Settings', {
  4156. set: function(val) {
  4157. if (typeof val === 'object' && 'Password' in val && 'Urls' in val) {
  4158. val.Urls = [];
  4159. _console.log('Adv.Client =', this, '\nAdv.Client.Settings =', val);
  4160. }
  4161. _contexts.set(this, val);
  4162. },
  4163. get: function() { return _contexts.get(this); }
  4164. });
  4165. // disable some logging
  4166. yandexRavenStub();
  4167. // prevent ads from loading
  4168. let blockPatterns = /\[[a-z]{1,4}\("0x[\da-f]+"\)\]|\.(rnet\.plus|24smi\.net|infox\.sg|lentainform\.com)\//i;
  4169. let _toString = Function.prototype.call.bind(Function.prototype.toString);
  4170. let _setTimeout = Function.prototype.apply.bind(win.setTimeout);
  4171. win.setTimeout = function(f) {
  4172. let str = _toString(f),
  4173. detected = blockPatterns.test();
  4174. if (!detected) {
  4175. try {
  4176. str = f.toString();
  4177. } catch(ignore) {};
  4178. if (str)
  4179. detected = blockPatterns.test(str);
  4180. }
  4181. if (detected) {
  4182. _console.warn('Stopped setTimeout for:', str.slice(0,100), '\u2026');
  4183. return null;
  4184. };
  4185. return _setTimeout(this, arguments);
  4186. };
  4187. // fake global Adf object
  4188. let nt = new nullTools();
  4189. let Adf_banner = {};
  4190. let autoresolvePromise = () => new Promise(r => r({status: true}));
  4191. [
  4192. 'reloadssp', 'sspScroll', 'sspRich', 'ssp', 'init'
  4193. ].forEach(name => void(Adf_banner[name] = nt.proxy(autoresolvePromise)));
  4194. let Adf_util = {
  4195. stack: nt.func(null, 'Adf.util.stack')
  4196. };
  4197. nt.define(win, 'Adf', nt.proxy({
  4198. banner: nt.proxy(Adf_banner),
  4199. util: nt.proxy(Adf_util),
  4200. }));
  4201. nt.define(win, 'AdfProxy', nt.proxy(Adf_banner));
  4202. // remove partner news on gazeta.ru and empty banner places on rambler.ru
  4203. if (!location.hostname.includes('gazeta.ru') && !location.hostname.includes('rambler.ru'))
  4204. return;
  4205. (new MutationObserver(
  4206. (ms) => {
  4207. let m, node, header;
  4208. for (m of ms) for (node of m.addedNodes) {
  4209. if (node instanceof HTMLDivElement && node.matches('.sausage')) {
  4210. header = node.querySelector('.sausage-header');
  4211. if (header && /новости\s+партн[её]ров/i.test(header.textContent))
  4212. node.style.display = 'none';
  4213. }
  4214. let walker = _document.createTreeWalker(node, NodeFilter.SHOW_COMMENT, null, null), comment;
  4215. while (comment = walker.nextNode())
  4216. if (comment.textContent.startsWith('bid:')) {
  4217. _console.log(`Hide ${comment.textContent} node:`, comment.parentNode.parentNode);
  4218. comment.parentNode.parentNode.style.display = 'none';
  4219. }
  4220. }
  4221. }
  4222. )).observe(_document.documentElement, { childList:true, subtree: true });
  4223. }, `let inIFrame = ${inIFrame}`, nullTools, yandexRavenStub)
  4224. },
  4225. dom: () => {
  4226. // remove utm_ form links
  4227. let parser = _document.createElement('a');
  4228. _document.addEventListener('mousedown', (e) => {
  4229. let t = e.target;
  4230. if (!t.href)
  4231. t = t.closest('A');
  4232. if (t && t.href) {
  4233. parser.href = t.href;
  4234. let remove = [];
  4235. let params = parser.search.slice(1).split('&').filter(name => {
  4236. if (name.startsWith('utm_')) {
  4237. remove.push(name);
  4238. return false;
  4239. }
  4240. return true;
  4241. });
  4242. if (remove.length)
  4243. _console.log('Removed parameters from link:', ...remove);
  4244. if (params.length)
  4245. parser.search = `?${params.join('&')}`;
  4246. else
  4247. parser.search = '';
  4248. t.href = parser.href;
  4249. }
  4250. }, false);
  4251. }
  4252. };
  4253.  
  4254. scripts['reactor.cc'] = {
  4255. other: ['joyreactor.cc', 'pornreactor.cc'],
  4256. now: () => {
  4257. selectiveEval();
  4258. scriptLander(() => {
  4259. let nt = new nullTools();
  4260. win.open = function(){
  4261. throw new Error('Redirect prevention.');
  4262. };
  4263. nt.define(win, 'Worker', function(){});
  4264. nt.define(win, 'JRCH', win.CoinHive);
  4265. }, nullTools);
  4266. },
  4267. click: function(e) {
  4268. let node = e.target;
  4269. if (node.nodeType === _Node.ELEMENT_NODE &&
  4270. node.style.position === 'absolute' &&
  4271. node.style.zIndex > 0)
  4272. node.parentNode.removeChild(node);
  4273. },
  4274. dom: function() {
  4275. let tid = void 0;
  4276. function probe() {
  4277. let node = selectNodeByTextContent('блокировщик рекламы');
  4278. if (!node) return;
  4279. while (node.parentNode.offsetHeight < 750 && node !== _document.body)
  4280. node = node.parentNode;
  4281. _setAttribute(node, 'style', 'background:none!important');
  4282. // stop observer
  4283. if (!tid) tid = setTimeout(() => this.disconnect(), 1000);
  4284. }
  4285. (new MutationObserver(probe))
  4286. .observe(_document, { childList:true, subtree:true });
  4287. }
  4288. };
  4289.  
  4290. scripts['auto.ru'] = () => {
  4291. let words = /Реклама|Яндекс.Директ|yandex_ad_/;
  4292. let userAdsListAds = (
  4293. '.listing-list > .listing-item,'+
  4294. '.listing-item_type_fixed.listing-item'
  4295. );
  4296. let catalogAds = (
  4297. 'div[class*="layout_catalog-inline"],'+
  4298. 'div[class$="layout_horizontal"]'
  4299. );
  4300. let otherAds = (
  4301. '.advt_auto,'+
  4302. '.sidebar-block,'+
  4303. '.pager-listing + div[class],'+
  4304. '.card > div[class][style],'+
  4305. '.sidebar > div[class],'+
  4306. '.main-page__section + div[class],'+
  4307. '.listing > tbody'
  4308. );
  4309. gardener(userAdsListAds, words, {root:'.listing-wrap', observe:true});
  4310. gardener(catalogAds, words, {root:'.catalog__page,.content__wrapper', observe:true});
  4311. gardener(otherAds, words);
  4312. };
  4313.  
  4314. scripts['rsload.net'] = {
  4315. load: () => {
  4316. let dis = _document.querySelector('label[class*="cb-disable"]');
  4317. if (dis)
  4318. dis.click();
  4319. },
  4320. click: e => {
  4321. let t = e.target;
  4322. if (t && t.href && (/:\/\/\d+\.\d+\.\d+\.\d+\//.test(t.href)))
  4323. t.href = t.href.replace('://','://rsload.net:rsload.net@');
  4324. }
  4325. };
  4326.  
  4327. let domain;
  4328. // add alternative domain names if present and wrap functions into objects
  4329. for (let name in scripts) {
  4330. if (scripts[name] instanceof Function)
  4331. scripts[name] = { now: scripts[name] };
  4332. for (domain of (scripts[name].other||[])) {
  4333. if (domain in scripts)
  4334. _console.log('Error in scripts list. Script for', name, 'replaced script for', domain);
  4335. scripts[domain] = scripts[name];
  4336. }
  4337. delete scripts[name].other;
  4338. }
  4339. // look for current domain in the list and run appropriate code
  4340. domain = _document.domain;
  4341. while (domain.includes('.')) {
  4342. if (domain in scripts) for (let when in scripts[domain])
  4343. switch(when) {
  4344. case 'now':
  4345. scripts[domain][when]();
  4346. break;
  4347. case 'dom':
  4348. _document.addEventListener('DOMContentLoaded', scripts[domain][when], false);
  4349. break;
  4350. default:
  4351. _document.addEventListener (when, scripts[domain][when], false);
  4352. }
  4353. domain = domain.slice(domain.indexOf('.') + 1);
  4354. }
  4355.  
  4356. // Batch script lander
  4357. if (!skipLander)
  4358. landScript(batchLand, batchPrepend);
  4359.  
  4360. { // JS Fixes Tools Menu
  4361. // Debug function, lists all unusual window properties
  4362. let _toString = Function.prototype.call.bind(Function.prototype.toString);
  4363. let isNativeFunction = new RegExp (`^[^{]*\\{[\\s\\r\\n]*\\[native\\scode\\][\\s\\r\\n]*\\}$`);
  4364. function getStrangeObjectsList() {
  4365. _console.warn('Window strangers list start');
  4366. let _skip = 'frames/self/window/webkitStorageInfo'.split('/');
  4367. for (let n of Object.getOwnPropertyNames(win)) {
  4368. let val = win[n];
  4369. if (val && !_skip.includes(n) && (win !== window && val !== window[n] || win === window) &&
  4370. (!(val instanceof Function) || val instanceof Function && !isNativeFunction.test(_toString(val))))
  4371. _console.log(`${n} =`, val);
  4372. }
  4373. _console.warn('Strangers list end');
  4374. }
  4375. // Debug function, lists all unusual Object.prototype properties
  4376. function getStrangeObjectsPrototypePropertiesList() {
  4377. _console.warn('Object.prototype strangers list start');
  4378. for (let n of Object.getOwnPropertyNames(win.Object.prototype)) {
  4379. let val = win.Object.prototype[n];
  4380. if (val &&
  4381. (!(val instanceof Function) || val instanceof Function && !isNativeFunction.test(_toString(val))))
  4382. _console.log(`${n} =`, val);
  4383. }
  4384. _console.warn('Strangers list end');
  4385. }
  4386.  
  4387. let openOptions = function() {
  4388. let ovl = _createElement('div'),
  4389. inner = _createElement('div');
  4390. ovl.style = (
  4391. 'position: fixed;'+
  4392. 'top:0; left:0;'+
  4393. 'bottom: 0; right: 0;'+
  4394. 'background: rgba(0,0,0,0.85);'+
  4395. 'z-index: 2147483647;'+
  4396. 'padding: 5em'
  4397. );
  4398. inner.style = (
  4399. 'background: whitesmoke;'+
  4400. 'font-size: 10pt;'+
  4401. 'color: black;'+
  4402. 'padding: 1em'
  4403. );
  4404. inner.textContent = 'JS Fixes Tools';
  4405. inner.appendChild(_createElement('br'));
  4406. inner.appendChild(_createElement('br'));
  4407. ovl.addEventListener(
  4408. 'click', function(e) {
  4409. if (e.target === ovl) {
  4410. ovl.parentNode.removeChild(ovl);
  4411. e.preventDefault();
  4412. }
  4413. e.stopPropagation();
  4414. }, false
  4415. );
  4416.  
  4417. let sObjBtn = _createElement('button');
  4418. sObjBtn.onclick = getStrangeObjectsList;
  4419. sObjBtn.textContent = 'Print (in console) list of unusual window properties';
  4420. let sOPPBtn = _createElement('button');
  4421. sOPPBtn.onclick = getStrangeObjectsPrototypePropertiesList;
  4422. sOPPBtn.textContent = 'Print (in console) list of unusual Object.prototype properties';
  4423. inner.appendChild(_createElement('br'));
  4424. inner.appendChild(sObjBtn);
  4425. inner.appendChild(_createElement('br'));
  4426. inner.appendChild(sOPPBtn);
  4427.  
  4428. _document.body.appendChild(ovl);
  4429. ovl.appendChild(inner);
  4430. };
  4431.  
  4432. // monitor keys pressed for Ctrl+Alt+Shift+J > s > f code
  4433. let opPos = 0, opKey = ['KeyJ','KeyS','KeyF'];
  4434. _document.addEventListener(
  4435. 'keydown', function(e) {
  4436. if ((e.code === opKey[opPos] || e.location) &&
  4437. (!!opPos || e.altKey && e.ctrlKey && e.shiftKey)) {
  4438. opPos += e.location ? 0 : 1;
  4439. e.stopPropagation();
  4440. e.preventDefault();
  4441. } else
  4442. opPos = 0;
  4443. if (opPos === opKey.length) {
  4444. opPos = 0;
  4445. openOptions();
  4446. }
  4447. }, false
  4448. );
  4449. }
  4450. })();