RU AdList JS Fixes

try to take over the world!

当前为 2018-11-30 提交的版本,查看 最新版本

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

QingJ © 2025

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