RU AdList JS Fixes

try to take over the world!

当前为 2019-03-17 提交的版本,查看 最新版本

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