RU AdList JS Fixes

try to take over the world!

当前为 2019-02-18 提交的版本,查看 最新版本

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