RU AdList JS Fixes

try to take over the world!

当前为 2018-04-02 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name RU AdList JS Fixes
  3. // @namespace ruadlist_js_fixes
  4. // @version 20180402.0
  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);
  29. // dTree 2.05 in some cases replaces Node object
  30. let _Node = Object.getPrototypeOf(Element);
  31.  
  32. // http://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser
  33. let isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0,
  34. isChrome = !!window.chrome && !!window.chrome.webstore,
  35. isSafari = (Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0 ||
  36. (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window.safari || safari.pushNotification)),
  37. isFirefox = 'InstallTrigger' in win,
  38. ifFirefoxUnder58 = isFirefox && 'StopIteration' in win,
  39. inIFrame = (win.self !== win.top),
  40. _getAttribute = Element.prototype.getAttribute,
  41. _setAttribute = Element.prototype.setAttribute,
  42. _removeAttribute = Element.prototype.removeAttribute,
  43. _de = document.documentElement,
  44. _appendChild = _Document.prototype.appendChild.bind(_de),
  45. _removeChild = _Document.prototype.removeChild.bind(_de),
  46. _createElement = _Document.prototype.createElement.bind(document);
  47.  
  48. if (isFirefox && // Exit on image pages in Fx
  49. document.constructor.prototype.toString() === '[object ImageDocumentPrototype]')
  50. return;
  51.  
  52. // NodeList iterator polyfill (mostly for Safari)
  53. // https://jakearchibald.com/2014/iterators-gonna-iterate/
  54. if (!NodeList.prototype[Symbol.iterator])
  55. NodeList.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
  56.  
  57. // Wrapper to run scripts designed to override objects available to other scripts
  58. // Required in old versions of Firefox (<58) or when running with Greasemonkey
  59. let skipLander = true;
  60. try {
  61. skipLander = !(ifFirefoxUnder58 || (isFirefox && GM.info.scriptHandler === 'Greasemonkey'));
  62. } catch(ignore){}
  63. let batchLand = [];
  64. let batchPrepend = [];
  65. let _APIString = 'let win = window, _Document = Object.getPrototypeOf(HTMLDocument), _Node = Object.getPrototypeOf(Element);';
  66. let landScript = (f, pre) => {
  67. let script = _createElement('script');
  68. script.textContent = `(()=>{${_APIString}${(
  69. (pre.length > 0 ? pre.join(';') : '')
  70. )};(${f.join(')();(')})();})();`;
  71. _appendChild(script);
  72. _removeChild(script);
  73. };
  74. let scriptLander = f => f();
  75. if (!skipLander) {
  76. scriptLander = (func, ...prepend) => {
  77. prepend.forEach(
  78. x => batchPrepend.includes(x) ? null : batchPrepend.push(x)
  79. );
  80. batchLand.push(func);
  81. };
  82. document.addEventListener(
  83. 'DOMContentLoaded', ignore => scriptLander = (f, ...prep) => landScript([f], prep), false
  84. );
  85. }
  86.  
  87. function nullTools(opts) {
  88. // jshint validthis:true
  89. let nt = this;
  90. opts = opts || {};
  91. let log = (...args) => opts.log ? console.log(...args) : null;
  92. let warn = (...args) => console.warn(...args);
  93. let trace = (...args) => (opts.log || opts.trace) ? warn(...arguments) : null;
  94.  
  95. nt.destroy = function(o, destroy)
  96. {
  97. if (!opts.destroy && !destroy && o instanceof Object)
  98. return;
  99. log('cleaning', o);
  100. try {
  101. for (let item in o)
  102. {
  103. if (item instanceof Object)
  104. nt.destroy(item);
  105. delete o[item];
  106. }
  107. } catch (e) {
  108. log('Error in object destructor', e);
  109. }
  110. };
  111.  
  112. nt.define = function(obj, prop, val, enumerable = true)
  113. {
  114. try {
  115. Object.defineProperty(
  116. obj, prop, {
  117. get: () => val,
  118. set: (v) => (v !== val ? (log(`set ${prop} of`, obj, 'to', v), nt.destroy(v)) : null, undefined),
  119. enumerable: enumerable
  120. }
  121. );
  122. } catch (err) {
  123. console.log(`Unable to redefine "${prop}" in `, obj, err);
  124. }
  125. };
  126. nt.proxy = function(obj)
  127. {
  128. return new Proxy(
  129. obj, {
  130. get: (t, p) => p in t ? t[p] : console.warn(`Missing ${p} in`, t),
  131. set: (t, p, v) => (v !== t[p] ? (log(`set ${p} of`, t, 'to', v), nt.destroy(v)) : null, true)
  132. }
  133. );
  134. };
  135. nt.func = (val, name = '', force_log = false) => (...args) => ((force_log ? warn : trace)(`call ${name}(`, ...args,`) return`, val), val);
  136. }
  137.  
  138. // Debug function, lists all unusual window properties
  139. function getStrangeObjectsList()
  140. {
  141. console.warn('Strangers list start');
  142. let _ts = Function.prototype.toString;
  143. let _skip = 'frames/self/window/webkitStorageInfo'.split('/');
  144. for (let n in win) {
  145. let val = win[n];
  146. if (val && !_skip.includes(n) && (win !== window && val !== window[n] || win === window) &&
  147. (!(val instanceof Function) ||
  148. val instanceof Function &&
  149. !(new RegExp (`^function\\s(${n})?\\(\\)[\\s\\r\\n]*\\{[\\s\\r\\n]*\\[native\\scode\\][\\s\\r\\n]*\\}$`)).test(_ts.call(val))))
  150. console.log(`${n} =`, val);
  151. }
  152. console.warn('Strangers list end');
  153. }
  154.  
  155. // Fake objects of advertisement networks to break their workflow
  156. scriptLander(
  157. function()
  158. {
  159. let nt = new nullTools();
  160. // Popular adblock detector
  161. if (!('fuckAdBlock' in win))
  162. {
  163. let FuckAdBlock = function(options) {
  164. let self = this;
  165. self._options = {
  166. checkOnLoad: false,
  167. resetOnEnd: false,
  168. checking: false
  169. };
  170. self.setOption = function(opt, val)
  171. {
  172. if (val)
  173. self._options[opt] = val;
  174. else
  175. Object.assign(self._options, opt);
  176. };
  177. if (options)
  178. self.setOption(options);
  179.  
  180. self._var = { event: {} };
  181. self.clearEvent = function()
  182. {
  183. self._var.event.detected = [];
  184. self._var.event.notDetected = [];
  185. };
  186. self.clearEvent();
  187.  
  188. self.on = function(detected, fun)
  189. {
  190. self._var.event[detected?'detected':'notDetected'].push(fun);
  191. return self;
  192. };
  193. self.onDetected = function(cb)
  194. {
  195. return self.on(true, cb);
  196. };
  197. self.onNotDetected = function(cb)
  198. {
  199. return self.on(false, cb);
  200. };
  201. self.emitEvent = function()
  202. {
  203. for (let fun of self._var.event.notDetected)
  204. fun();
  205. if (self._options.resetOnEnd)
  206. self.clearEvent();
  207. return self;
  208. };
  209. self._creatBait = () => null;
  210. self._destroyBait = () => null;
  211. self._checkBait = function() {
  212. setTimeout((() => self.emitEvent()), 1);
  213. };
  214. self.check = function() {
  215. self._checkBait();
  216. return true;
  217. };
  218.  
  219. let callback = function()
  220. {
  221. if (self._options.checkOnLoad)
  222. setTimeout(self.check, 1);
  223. };
  224. window.addEventListener('load', callback, false);
  225. };
  226. nt.define(win, 'FuckAdBlock', FuckAdBlock);
  227. nt.define(win, 'fuckAdBlock', new FuckAdBlock({
  228. checkOnLoad: true,
  229. resetOnEnd: true
  230. }));
  231. }
  232.  
  233. // CoinHive miner stub. Continuous 100% CPU load can easily kill some CPU with overheat.
  234. if (!('CoinHive' in win))
  235. {
  236. if (location.hostname !== 'cnhv.co')
  237. {
  238. // CoinHive stub for cases when it doesn't affect site functionality
  239. let CoinHiveConstructor = function()
  240. {
  241. console.warn('Fake CoinHive miner created.');
  242. this.setThrottle = nt.func(null);
  243. this.start = nt.func(null);
  244. this.on = nt.func(null);
  245. this.getTotalHashes = nt.func(0);
  246. };
  247. let CoinHiveStub = nt.proxy({
  248. Anonymous: CoinHiveConstructor,
  249. User: CoinHiveConstructor,
  250. Token: CoinHiveConstructor,
  251. JobThread: nt.func(null),
  252. IF_EXCLUSIVE_TAB: false
  253. });
  254. nt.define(win, 'CoinHive', CoinHiveStub);
  255. } else {
  256. // CoinHive wrapper to fool sites which expect it to actually work and return results
  257. let CoinHiveObject;
  258. let fishnet = {
  259. apply: (target, thisArg, args) => {
  260. console.log(`miner.${target._name}(${JSON.stringify(args).slice(1,-1)})`);
  261. return target.apply(thisArg, args);
  262. }
  263. };
  264. Object.defineProperty(win, 'CoinHive', {
  265. set: function(obj)
  266. {
  267. if ('Token' in obj)
  268. {
  269. console.log('[CoinHive] Token wrapper applied.');
  270. let _Token = obj.Token.bind(obj);
  271. obj.Token = function(siteKey, goal, params)
  272. {
  273. let _goal = goal;
  274. if (goal > 256)
  275. goal = 256;
  276. console.log(`[CoinHive] Original goal: ${_goal}, new smaller goal ${goal}.`);
  277. console.log(`With smaller goals server may return 'invalid_goal' error and stop working.`);
  278. let miner = _Token(siteKey, goal, params);
  279. miner.setThrottle(0.99);
  280. miner.setThrottle = () => null;
  281. let _start = miner.start.bind(miner);
  282. miner.start = function() {
  283. let res = _start(CoinHive.FORCE_EXCLUSIVE_TAB);
  284. return res;
  285. };
  286. let _getTotalHashes = miner.getTotalHashes;
  287. miner.getTotalHashes = function()
  288. {
  289. return Math.trunc(_getTotalHashes.call(this) / goal * _goal);
  290. };
  291. let __emit = miner._emit;
  292. miner._emit = function(state, props)
  293. {
  294. let _self = this;
  295. console.log('[CoinHive] state:', state, props);
  296. if (state === 'job')
  297. setTimeout(() => {
  298. _self.stop();
  299. _self._emit('accepted', { hashes: goal });
  300. }, 1000);
  301. return __emit.apply(_self, arguments);
  302. };
  303. let _on = miner.on.bind(miner);
  304. miner.on = function(type, callback)
  305. {
  306. if (type === 'accepted')
  307. {
  308. console.log('[CoinHive] "accepted" callback wrapper applied.');
  309. let _callback = callback;
  310. callback = function(params)
  311. {
  312. console.log('[CoinHive] "accepted" callback is called, imitating original goal being reached.');
  313. params.hashes = _goal;
  314. return _callback.apply(this, arguments);
  315. };
  316. miner.stop();
  317. }
  318. return _on(type, callback);
  319. };
  320. return miner;
  321. };
  322. }
  323. CoinHiveObject = obj;
  324. },
  325. get: () => CoinHiveObject
  326. });
  327. }
  328. }
  329.  
  330. // VideoJS player wrapper
  331. VideoJS: {
  332. let _videojs = win.videojs || void 0;
  333. Object.defineProperty(win, 'videojs', {
  334. get: x => _videojs,
  335. set: f => {
  336. if (f === _videojs)
  337. return true;
  338. console.log('videojs =', f);
  339. _videojs = new Proxy(f, {
  340. apply: (tgt, ths, args) => {
  341. console.log('videojs(', ...args, ')');
  342. let params = args[1];
  343. if (params) {
  344. if (params.hasAd)
  345. params.hasAd = false;
  346. if (params.plugins && params.plugins.vastClient)
  347. delete params.plugins.vastClient;
  348. }
  349. let res = tgt.apply(ths, args);
  350. console.log('player = ', res);
  351. return res;
  352. }
  353. });
  354. }
  355. });
  356. }
  357.  
  358. // piguiqproxy-like script loaded from random RU domains
  359. let fab_application_define = nt.func(null, 'fab_application.define', true);
  360. fab_application_define.amd = nt.func(null, 'fab_application.define.amd');
  361. let fab_application = {
  362. requirejs: nt.proxy(nt.func(null, 'fab_application.requirejs')),
  363. require: nt.proxy(nt.func(null, 'fab_application.require')),
  364. define: nt.proxy(fab_application_define)
  365. };
  366. nt.define(win, 'fab_application', nt.proxy(fab_application));
  367. // less aggressive wrapper for 'fab_application' in case it'll
  368. /*
  369. let fab_application = void 0;
  370. let fab_define_as_null = ['helpers/detecter', 'text!templates/bn_image.tpl', 'text!templates/yandex.tpl'];
  371. Object.defineProperty(win, 'fab_application', {
  372. enumerable: true,
  373. get: x => fab_application,
  374. set: o => {
  375. fab_application = new Proxy(o, {
  376. get: (t, p) => t[p],
  377. set: (t, p, v) => {
  378. if (p === 'define')
  379. v = new Proxy(v, {
  380. apply: (t, ths, args) => {
  381. if (fab_define_as_null.includes(args[0])) {
  382. let null_module = {};
  383. ['on', 'check'].forEach(name => null_module[name] = () => null);
  384. console.warn(`[fab_application] Define '${args[0]}' with custom code instead of`, args[2]);
  385. if (args[0] === 'helpers/detecter')
  386. args[2] = () => ({ on: () => null, check: () => null });
  387. else
  388. args[2] = () => '';
  389. } else {
  390. console.log(`[fab_application] Define '${args[0]}'`);
  391. }
  392. return t.apply(ths, args);
  393. }
  394. });
  395. t[p] = v;
  396. return true;
  397. }
  398. });
  399. return true;
  400. }
  401. });
  402. */
  403.  
  404. // Yandex API (ADBTools, Metrika)
  405. let hostname = location.hostname;
  406. if (location.protocol === 'about:' ||
  407. // Thank you, Greasemonkey, now I have to check for this. -_-
  408. hostname.startsWith('google.') || hostname.includes('.google.') ||
  409. // Google likes to define odd global variables like Ya
  410. ((hostname.startsWith('yandex.') || hostname.includes('.yandex.')) &&
  411. /^\/((yand)?search|images)/i.test(location.pathname) &&
  412. !hostname.startsWith('news.')) ||
  413. // Also, Yandex uses their Ya object for a lot of things on their pages and
  414. // wrapping it may cause problems. It's better to skip it in some cases.
  415. hostname.endsWith('chatango.com') || hostname.endsWith('github.io') ||
  416. hostname.endsWith('grimtools.com'))
  417. return;
  418.  
  419. let YaProps = new Set();
  420. function onAdvManager (Ya, rootProp, obj)
  421. {
  422. return new Proxy(obj, {
  423. set: (tgt, prop, val) => {
  424. if (prop === 'AdvManager')
  425. {
  426. console.log(`Ya.${rootProp} = Ya.Context`);
  427. nt.define(Ya, rootProp, Ya.Context);
  428. YaProps.add(rootProp);
  429. }
  430. tgt[prop] = val;
  431. return true;
  432. },
  433. get: (tgt, prop) => tgt[prop]
  434. });
  435. }
  436. let Rum = {};
  437. [
  438. '__timeMarks', '_timeMarks', '__deltaMarks', '_deltaMarks',
  439. '__defRes', '_defRes', '__defTimes', '_defTimes',
  440. 'commonVars'
  441. ].forEach(name => Rum[name] = []);
  442. [
  443. 'send', 'sendRaf', 'sendTimeMark', 'sendResTiming', 'sendTTI',
  444. 'time', 'timeEnd', 'getTime', 'mark', 'init',
  445. 'makeSubPage', 'observeDOMNode', 'isVisibilityChanged'
  446. ].forEach(name => Rum[name] = nt.func(null, `Ya.Rum.${name}`));
  447. [
  448. 'getSettings', 'getVarsList'
  449. ].forEach(name => Rum[name] = nt.func([], `Ya.Rum.${name}`));
  450. [
  451. ['ajaxStart', 0], ['ajaxComplete', 0],
  452. ['enabled', true], ['_tti', null],
  453. ['vsChanged', false], ['vsStart', 'visible']
  454. ].forEach(([prop, val]) => Rum[prop] = val);
  455. Rum = nt.proxy(Rum);
  456. let Ya = new Proxy({}, {
  457. set: function(tgt, prop, val)
  458. {
  459. if (val === tgt[prop])
  460. return true;
  461. if (prop === 'Rum')
  462. {
  463. nt.define(tgt, prop, Rum);
  464. YaProps.add(prop);
  465. Object.assign(val, Rum);
  466. }
  467. if (YaProps.has(prop))
  468. {
  469. console.log(`Ya.${prop} \u2260`, val);
  470. return true;
  471. }
  472. if (val instanceof Object && prop !== '__inline_params__')
  473. val = onAdvManager(Ya, prop, val);
  474. tgt[prop] = val;
  475. console.log(`Ya.${prop} =`, val);
  476. return true;
  477. },
  478. get: (tgt, prop) => tgt[prop]
  479. });
  480. let callWithParams = function(f)
  481. {
  482. f.call(this, Ya.__inline_params__ || {});
  483. Ya.__inline_params__ = null;
  484. };
  485. nt.define(Ya, 'callWithParams', callWithParams);
  486. nt.define(Ya, 'PerfCounters', nt.proxy({
  487. addCacheEvent: nt.func(null),
  488. getTime: nt.func(null),
  489. sendCacheEvents: nt.func(null),
  490. sendResTiming: nt.func(null),
  491. sendTimeMark: nt.func(null),
  492. __cacheEvents: []
  493. }));
  494. nt.define(Ya, '__isSent', true);
  495. nt.define(Ya, 'confirmUrl', '');
  496. nt.define(Ya, 'Direct', nt.proxy({
  497. insertInto: nt.func(null)
  498. }));
  499. nt.define(Ya, 'mediaCode', nt.proxy({
  500. create: function()
  501. {
  502. if (inIFrame)
  503. {
  504. console.log('Removed body of ad-frame.');
  505. document.documentElement.removeChild(document.body);
  506. }
  507. },
  508. moduleLoad: nt.func(null),
  509. setModule: nt.func(null)
  510. }));
  511. let extra = nt.proxy({
  512. extra: nt.proxy({ match: 0, confirm: '', src: '' }),
  513. id: 0, percent: 100, threshold: 1
  514. });
  515. nt.define(Ya, '_exp', nt.proxy({
  516. id: 0, coin: 0,
  517. choose: nt.func(extra),
  518. get: (prop) => extra.hasOwnProperty(prop) ? extra[prop] : null,
  519. getId: nt.func(0),
  520. defaultVersion: extra,
  521. getExtra: nt.func(extra.extra),
  522. getDefaultExtra: nt.func(extra.extra),
  523. versions: [extra]
  524. }));
  525. nt.define(Ya, 'c', nt.func(null));
  526. nt.define(Ya, 'ADBTools', function(){
  527. ['loadContext', 'testAdbStyle'].forEach(name => this[name] = nt.func(null));
  528. this.getCurrentState = nt.func(true);
  529. return nt.proxy(this);
  530. });
  531.  
  532. if (!location.hostname.includes('kinopoisk.ru')) {
  533. // kinopoisk uses adfox wrapped in Yandex code to display self-ads
  534. let adfoxCode = {};
  535. [
  536. 'create', 'reload', 'destroy',
  537. 'createAdaptive', 'moduleLoad',
  538. 'createScroll', 'pr'
  539. ].forEach(name => adfoxCode[name] = nt.func(null, `Ya.adfoxCode.${name}`));
  540. nt.define(Ya, 'adfoxCode', nt.proxy(adfoxCode));
  541. } else {
  542. nt.define(win, 'abExperiments', nt.proxy([]));
  543. }
  544. let AdvManager = function()
  545. {
  546. [
  547. 'renderDirect',
  548. 'getBid', 'releaseBid',
  549. 'getSkipToken',
  550. 'getAdSessionId'
  551. ].forEach(name => this[name] = nt.func(null, `Ya.AdvManager.${name}`));
  552. this.render = function(o) {
  553. if (!o.renderTo)
  554. return;
  555. let placeholder = document.getElementById(o.renderTo);
  556. let parent = placeholder.parentNode;
  557. placeholder.style = 'display:none!important';
  558. parent.style = (parent.getAttribute('style')||'') + 'height:auto!important';
  559. // fix for Yandex TV pages
  560. if (location.hostname.startsWith('tv.yandex.'))
  561. {
  562. let sibling = placeholder.previousSibling;
  563. if (sibling && sibling.classList && sibling.classList.contains('tv-spin'))
  564. sibling.style.display = 'none';
  565. }
  566. };
  567. return nt.proxy(this);
  568. };
  569. nt.define(Ya, 'Context', nt.proxy({
  570. __longExperiment: null,
  571. _callbacks: nt.proxy([]),
  572. _asyncModeOn: true,
  573. _init: nt.func(null),
  574. isAllowedRepeatAds: nt.func(null),
  575. AdvManager: new AdvManager()
  576. }));
  577. let Metrika = function()
  578. {
  579. [
  580. 'reachGoal', 'replacePhones',
  581. 'trackLinks', 'userParams',
  582. 'hit', 'params', 'clickmap'
  583. ].forEach(name => this[name] = nt.func(null, `Ya.Metrika.${name}`));
  584. this.id = 0;
  585. return nt.proxy(this);
  586. };
  587. Metrika.counters = () => Ya._metrika.counters;
  588. nt.define(Ya, 'Metrika', Metrika);
  589. let counter = new Ya.Metrika();
  590. nt.define(Ya, '_metrika', nt.proxy({
  591. counter: counter,
  592. counters: [counter],
  593. hitParam: {},
  594. counterNum: 0,
  595. hitId: 0,
  596. v: 1
  597. }));
  598. nt.define(Ya, '_globalMetrikaHitId', 0);
  599. counter = {};
  600. [
  601. 'cpHitDelayed','wHitDelayed',
  602. 'hitDelayed','makeReq',
  603. 'redir','hit','log','cp','w'
  604. ].forEach(name => counter[name] = nt.func(null, `Ya.counter.${name}`));
  605. [
  606. 'stringifyParams','_getVars',
  607. 'getUid','getUrl','getHash'
  608. ].forEach(name => counter[name] = nt.func(''));
  609. nt.define(Ya, 'counter', nt.proxy(counter));
  610. nt.define(Ya, 'jserrors', []);
  611. nt.define(Ya, 'onerror', nt.func(null, 'Ya.onerror'));
  612. if (win.Ya) {
  613. console.log('Found existing Ya object:', win.Ya);
  614. for (let prop in win.Ya)
  615. Ya[prop] = win.Ya[prop];
  616. }
  617. for (let prop in Ya) if (prop !== '__inline_params__')
  618. YaProps.add(prop);
  619. nt.define(win, 'Ya', Ya);
  620. // Yandex.Metrika callbacks
  621. let yandex_metrika_callbacks = [];
  622. document.addEventListener(
  623. 'DOMContentLoaded',
  624. (e) => {
  625. yandex_metrika_callbacks.forEach((f) => f && f.call(window));
  626. yandex_metrika_callbacks.length = 0;
  627. yandex_metrika_callbacks.push = (f) => setTimeout(f, 0);
  628. },
  629. false
  630. );
  631. nt.define(win, 'yandex_metrika_callbacks', yandex_metrika_callbacks);
  632. }, nullTools
  633. );
  634.  
  635. // Creates and return protected style (unless protection is manually disabled).
  636. // Protected style will re-add itself on removal and remaind enabled on attempt to disable it.
  637. function createStyle(rules, props, skip_protect)
  638. {
  639. props = props || {};
  640. props.type = 'text/css';
  641.  
  642. function _protect(style)
  643. {
  644. if (skip_protect)
  645. return;
  646.  
  647. Object.defineProperty(style, 'sheet', {
  648. value: null,
  649. enumerable: true
  650. });
  651. Object.defineProperty(style, 'disabled', {
  652. get: () => true, //pretend to be disabled
  653. set: () => undefined,
  654. enumerable: true
  655. });
  656. (new MutationObserver(
  657. (ms) => _removeChild(ms[0].target)
  658. )).observe(style, { childList: true });
  659. }
  660.  
  661.  
  662. function _create()
  663. {
  664. let style = _appendChild(_createElement('style'));
  665. Object.assign(style, props);
  666.  
  667. function insertRules(rule)
  668. {
  669. if (rule.forEach)
  670. rule.forEach(insertRules);
  671. else try {
  672. style.sheet.insertRule(rule, 0);
  673. } catch (e) {
  674. console.error(e);
  675. }
  676. }
  677.  
  678. insertRules(rules);
  679. _protect(style);
  680.  
  681. return style;
  682. }
  683.  
  684. let style = _create();
  685. if (skip_protect)
  686. return style;
  687.  
  688. function resolveInANewContext(resolve)
  689. {
  690. setTimeout(
  691. (resolve) => resolve(_create()),
  692. 0, resolve
  693. );
  694. }
  695.  
  696. (new MutationObserver(
  697. function(ms)
  698. {
  699. let m, node;
  700. for (m of ms) for (node of m.removedNodes)
  701. if (node === style)
  702. (new Promise(resolveInANewContext))
  703. .then((st) => (style = st));
  704. }
  705. )).observe(_de, { childList: true });
  706.  
  707. return style;
  708. }
  709.  
  710. // Simplistic WebSocket wrapper for troublesome browsers and
  711. // disable 'onerror' handler for scripts from blacklisted sources
  712. scriptLander(() => {
  713. let masks = [],
  714. isBlocked = url => masks.some(mask => mask.test(url));
  715. for (let filter of [// blacklist
  716. '||185.87.50.147^',
  717. '||10root25.website^', '||24video.xxx^',
  718. '||adlabs.ru^', '||adspayformymortgage.win^', '||aviabay.ru^',
  719. '||bgrndi.com^', '||brokeloy.com^',
  720. '||cnamerutor.ru^',
  721. '||directadvert.ru^', '||docfilms.info^', '||dreadfula.ru^',
  722. '||et-code.ru^', '||etcodes.com^',
  723. '||franecki.net^', '||film-doma.ru^',
  724. '||free-torrent.org^', '||free-torrent.pw^',
  725. '||free-torrents.org^', '||free-torrents.pw^',
  726. '||game-torrent.info^', '||gocdn.ru^',
  727. '||hdkinoshka.com^', '||hghit.com^', '||hindcine.net^',
  728. '||joyreactor.cc^', '||pornreactor.cc^', '||reactor.cc^',
  729. '||kiev.ua^', '||kinotochka.net^',
  730. '||kinott.com^', '||kinott.ru^', '||kuveres.com^',
  731. '||lepubs.com^', '||luxadv.com^', '||luxup.ru^', '||luxupcdna.com^',
  732. '||mail.ru^', '||marketgid.com^', '||mebablo.com^', '||mixadvert.com^', '||mxtads.com^',
  733. '||nickhel.com^',
  734. '||oconner.biz^', '||oconner.link^', '||octoclick.net^', '||octozoon.org^',
  735. '||pkpojhc.com^',
  736. '||psma01.com^', '||psma02.com^', '||psma03.com^',
  737. '||recreativ.ru^', '||redtram.com^', '||regpole.com^',
  738. '||rootmedia.ws^', '||ruttwind.com^', '||rutvind.com^',
  739. '||skidl.ru^',
  740. '||torvind.com^', '||traffic-media.co^', '||trafmag.com^', '||ttarget.ru^',
  741. '||webadvert-gid.ru^', '||webadvertgid.ru^',
  742. '||xxuhter.ru^',
  743. '||yuiout.online^',
  744. '||zoom-film.ru^'])
  745. masks.push(new RegExp(
  746. filter.replace(/([\\\/\[\].*+?(){}$])/g, '\\$1')
  747. .replace(/\^(?!$)/g,'\\.?[^\\w%._-]')
  748. .replace(/\^$/,'\\.?([^\\w%._-]|$)')
  749. .replace(/^\|\|/,'^(ws|http)s?:\\/+([^\/.]+\\.)*'),
  750. 'i'));
  751.  
  752. let _createElement = _Document.prototype.createElement,
  753. _addEventListener = Element.prototype.addEventListener,
  754. _removeEventListener = Element.prototype.removeEventListener;
  755.  
  756. let scriptMap = new WeakMap();
  757. scriptMap.isBlocked = isBlocked;
  758. let onErrorWrapper = {
  759. set: function(val)
  760. {
  761. if (scriptMap.has(this))
  762. {
  763. _removeEventListener.call(this, 'error', scriptMap.get(this).wrp, false);
  764. scriptMap.delete(this);
  765. }
  766. if (!val || typeof val !== 'function')
  767. return val;
  768.  
  769. scriptMap.set(this, {
  770. org: val,
  771. wrp: function(...args)
  772. {
  773. if (scriptMap.isBlocked(this.src))
  774. console.log('[WSI] Blocked "onerror" callback from', this.src);
  775. else
  776. scriptMap.get(this).org.apply(this, args);
  777. }
  778. });
  779. _addEventListener.call(this, 'error', scriptMap.get(this).wrp, false);
  780. },
  781. get: function()
  782. {
  783. return scriptMap.has(this) ? scriptMap.get(this).org : null;
  784. },
  785. enumerable: true
  786. };
  787. _Document.prototype.createElement = function createElement(...args) {
  788. let el = _createElement.apply(this, args);
  789.  
  790. // Custom onerror handler to block execution of callback if script source is blacklisted
  791. if (el instanceof HTMLScriptElement)
  792. Object.defineProperty(el, 'onerror', onErrorWrapper);
  793. // Block popular method to open a new window in Google Chrome by dispatching a custom click
  794. // event on a newly created anchor with _blank target. Untrusted events must not open a new window.
  795. if (el instanceof HTMLAnchorElement) {
  796. el.addEventListener('click', e => {
  797. if (!e.isTrusted && e.target && !e.target.parentNode && e.target.target[0] === '_') {
  798. e.stopPropagation();
  799. e.preventDefault();
  800. console.log('Blocked untrusted click on parentless anchor:', e.target);
  801. }
  802. }, false);}
  803.  
  804. return el;
  805. };
  806. let doc_proto = Object.getPrototypeOf(document);
  807. if (doc_proto && doc_proto.createElement !== _Document.prototype.createElement)
  808. doc_proto.createElement = _Document.prototype.createElement;
  809. // Simplistic WebSocket wrapper for Maxthon and Firefox before v58
  810. WSWrap: {
  811. if (/Maxthon/.test(navigator.appVersion) ||
  812. 'InstallTrigger' in win && 'StopIteration' in win) {
  813. let _ws = Object.getOwnPropertyDescriptor(win, 'WebSocket');
  814. if (!_ws)
  815. break WSWrap;
  816. _ws.value = new Proxy(_ws.value, {
  817. construct: (ws, args) => {
  818. if (isBlocked(args[0])) {
  819. console.log('[WSI] Blocked WS connection:', args[0]);
  820. return {};
  821. }
  822. return new ws(...args);
  823. }
  824. });
  825. Object.defineProperty(win, 'WebSocket', _ws);
  826. }
  827. }
  828. });
  829.  
  830. if (!isFirefox)
  831. { // scripts for non-Firefox browsers
  832. // https://gf.qytechs.cn/scripts/14720-it-s-not-important
  833. {
  834. let imptt = /((display|(margin|padding)(-top|-bottom)?)\s*:[^;!]*)!\s*important/ig,
  835. ret_b = (a,b) => b,
  836. _toLowerCase = String.prototype.toLowerCase,
  837. protectedNodes = new WeakSet(),
  838. log = false;
  839.  
  840. let logger = function()
  841. {
  842. if (log)
  843. console.log('Some page elements became a bit less important.');
  844. log = false;
  845. };
  846.  
  847. let unimportanter = function(node)
  848. {
  849. let style = (node.nodeType === _Node.ELEMENT_NODE) ?
  850. _getAttribute.call(node, 'style') : null;
  851.  
  852. if (!style || !imptt.test(style) || node.style.display === 'none' ||
  853. (node.src && node.src.slice(0,17) === 'chrome-extension:')) // Web of Trust IFRAME and similar
  854. return false; // get out if we have nothing to do here
  855.  
  856. protectedNodes.add(node);
  857. _setAttribute.call(node, 'style',
  858. style.replace(imptt, ret_b));
  859. log = true;
  860. };
  861.  
  862. (new MutationObserver(
  863. function(mutations)
  864. {
  865. setTimeout(
  866. function(ms)
  867. {
  868. let m, node;
  869. for (m of ms) for (node of m.addedNodes)
  870. unimportanter(node);
  871. logger();
  872. }, 0, mutations
  873. );
  874. }
  875. )).observe(document, {
  876. childList : true,
  877. subtree : true
  878. });
  879.  
  880. Element.prototype.setAttribute = function setAttribute(name, value)
  881. {
  882. "[native code]";
  883. let replaced = value;
  884. if (_toLowerCase.call(name) === 'style' && protectedNodes.has(this))
  885. replaced = value.replace(imptt, ret_b);
  886. log = (replaced !== value);
  887. logger();
  888. return _setAttribute.call(this, name, replaced);
  889. };
  890.  
  891. win.addEventListener (
  892. 'load', function()
  893. {
  894. for (let imp of document.querySelectorAll('[style*="!"]'))
  895. unimportanter(imp);
  896. logger();
  897. }, false
  898. );
  899. }
  900.  
  901. // Naive ABP Style protector
  902. {
  903. let _querySelector = _Document.prototype.querySelector.bind(document);
  904. let _removeChild = _Node.prototype.removeChild;
  905. let _appendChild = _Node.prototype.appendChild;
  906. let createShadow = () => _createElement('shadow');
  907. // Prevent adding fake content entry point
  908. _Node.prototype.appendChild = function(child)
  909. {
  910. if (this instanceof ShadowRoot &&
  911. child instanceof HTMLContentElement)
  912. return _appendChild.call(this, createShadow());
  913. return _appendChild.apply(this, arguments);
  914. };
  915. {
  916. let _shadowSelector = ShadowRoot.prototype.querySelector;
  917. let _innerHTML = Object.getOwnPropertyDescriptor(ShadowRoot.prototype, 'innerHTML');
  918. let _parentNode = Object.getOwnPropertyDescriptor(_Node.prototype, 'parentNode');
  919. if (_innerHTML && _parentNode)
  920. {
  921. let _set = _innerHTML.set;
  922. let _getParent = _parentNode.get;
  923. _innerHTML.configurable = false;
  924. _innerHTML.set = function()
  925. {
  926. _set.apply(this, arguments);
  927. let content = _shadowSelector.call(this, 'content');
  928. if (content)
  929. {
  930. let parent = _getParent.call(content);
  931. _removeChild.call(parent, content);
  932. _appendChild.call(parent, createShadow());
  933. }
  934. };
  935. }
  936. Object.defineProperty(ShadowRoot.prototype, 'innerHTML', _innerHTML);
  937. }
  938. // Locate and apply extra protection to a style on top of what ABP does
  939. let style;
  940. (new Promise(
  941. function(resolve, reject)
  942. {
  943. let getStyle = () => _querySelector('::shadow style');
  944. style = getStyle();
  945. if (style)
  946. return resolve(style);
  947. let intv = setInterval(
  948. function()
  949. {
  950. style = getStyle();
  951. if (!style)
  952. return;
  953. intv = clearInterval(intv);
  954. return resolve(style);
  955. }, 0
  956. );
  957. document.addEventListener(
  958. 'DOMContentLoaded',
  959. function()
  960. {
  961. if (intv)
  962. clearInterval(intv);
  963. style = getStyle();
  964. return style ? resolve(style) : reject();
  965. },
  966. false
  967. );
  968. }
  969. )).then(
  970. function(style)
  971. {
  972. let emptyArr = [],
  973. nullStr = {
  974. get: () => '',
  975. set: () => undefined
  976. };
  977. let shadow = style.parentNode;
  978. Object.defineProperties(shadow, {
  979. childElementCount: { value: 0 },
  980. styleSheets: { value: emptyArr },
  981. firstChild: { value: null },
  982. firstElementChild: { value: null },
  983. lastChild: { value: null },
  984. lastElementChild: { value: null },
  985. childNodes: { value: emptyArr },
  986. children: { value: emptyArr },
  987. innerHTML: { value: nullStr },
  988. });
  989. Object.defineProperties(style, {
  990. innerHTML: { value: nullStr },
  991. textContent: { value: nullStr },
  992. ownerDocument: { value: null },
  993. parentNode: {value: null },
  994. previousElementSibling: { value: null },
  995. previousSibling: { value: null },
  996. disabled: { get: () => true, set: x => null }
  997. });
  998. Object.defineProperties(style.sheet, {
  999. deleteRule: { value: () => null },
  1000. disabled: { get: () => true, set: x => null },
  1001. cssRules: { value: emptyArr },
  1002. rules: { value: emptyArr }
  1003. });
  1004. }
  1005. ).catch(()=>null);
  1006. _Node.prototype.removeChild = function(child)
  1007. {
  1008. if (child === style)
  1009. return;
  1010. return _removeChild.apply(this, arguments);
  1011. };
  1012. }
  1013. }
  1014. if (/^https?:\/\/(mail\.yandex\.|music\.yandex\.|news\.yandex\.|(www\.)?yandex\.[^\/]+\/(yand)?search[\/?])/i.test(win.location.href) ||
  1015. /^https?:\/\/tv\.yandex\./i.test(win.location.href))
  1016. {
  1017. // https://gf.qytechs.cn/en/scripts/809-no-yandex-ads
  1018. let yadWord = /Яндекс.Директ/i,
  1019. adWords = /Реклама|Ad/i;
  1020. let _querySelector = document.querySelector.bind(document),
  1021. _querySelectorAll = document.querySelectorAll.bind(document),
  1022. _getAttribute = Element.prototype.getAttribute,
  1023. _setAttribute = Element.prototype.setAttribute;
  1024. // Function to attach an observer to monitor dynamic changes on the page
  1025. let pageUpdateObserver = (func, obj, params) => {
  1026. if (obj)
  1027. (new MutationObserver(func))
  1028. .observe(obj, (params || { childList:true, subtree:true }));
  1029. };
  1030. // Short name for parentNode.removeChild and setAttribute style to display:none
  1031. let remove = (node) => {
  1032. if (!node || !node.parentNode)
  1033. return false;
  1034. console.log('Removed node.');
  1035. node.parentNode.removeChild(node);
  1036. };
  1037. let hide = (node) => {
  1038. if (!node)
  1039. return false;
  1040. console.log('Hid node.');
  1041. _setAttribute.call(node, 'style', 'display:none!important');
  1042. };
  1043. // Yandex search ads in Google Chrome
  1044. if ('attachShadow' in Element.prototype)
  1045. {
  1046. let _attachShadow = Element.prototype.attachShadow;
  1047. Element.prototype.attachShadow = function()
  1048. {
  1049. let node = this,
  1050. root = _attachShadow.apply(node, arguments);
  1051. pageUpdateObserver(
  1052. (ms) => {
  1053. for (let m of ms) if (m.addedNodes.length)
  1054. if (adWords.test(root.textContent))
  1055. remove(node.closest('.serp-item'));
  1056. }, root
  1057. );
  1058. return root;
  1059. };
  1060. }
  1061. // prevent/defuse adblock detector
  1062. setInterval(()=>{
  1063. localStorage.ic = '';
  1064. localStorage._mt__data = '';
  1065. },100);
  1066. let _doc_proto = ('cookie' in _Document.prototype) ? _Document.prototype : Object.getPrototypeOf(document);
  1067. let _cookie = Object.getOwnPropertyDescriptor(_doc_proto, 'cookie');
  1068. if (_cookie)
  1069. {
  1070. let _set_cookie = Function.prototype.call.bind(_cookie.set);
  1071. _cookie.set = function(value)
  1072. {
  1073. if (/^(mda=|yp=|ys=|yabs-|__)/.test(value))
  1074. {
  1075. // remove value, set expired
  1076. if (!value.startsWith('yp=')) {
  1077. value = value.replace(/^([^=]+=)[^;]+/,'$1').replace(/(expires=)[\w\s\d,]+/,'$1Thu, 01 Jan 1970 00');
  1078. console.log('expire cookie', value.match(/^[^=]+/)[0]);
  1079. } else {
  1080. let parts = value.split(';');
  1081. let values = parts[0].split('#').filter(part => /\.sp\./.test(part));
  1082. if (values.length)
  1083. values[0] = values[0].replace(/^yp=/, '');
  1084. parts[0] = `yp=${values.join('#')}`;
  1085. value = parts.join(';');
  1086. console.log(`set cookie ${parts[0]}`);
  1087. }
  1088. //return null;
  1089. }
  1090. return _set_cookie(this, value);
  1091. };
  1092. Object.defineProperty(_doc_proto, 'cookie', _cookie);
  1093. }
  1094. // other ads
  1095. document.addEventListener(
  1096. 'DOMContentLoaded', function()
  1097. {
  1098. { // Generic ads removal and fixes
  1099. let node = _querySelector('.serp-header');
  1100. if (node)
  1101. node.style.marginTop = '0';
  1102. for (node of _querySelectorAll(
  1103. '.serp-adv__head + .serp-item,'+
  1104. '#adbanner,'+
  1105. '.serp-adv,'+
  1106. '.b-spec-adv,'+
  1107. 'div[class*="serp-adv__"]:not(.serp-adv__found):not(.serp-adv__displayed)'
  1108. )) remove(node);
  1109. }
  1110. // Search ads
  1111. function removeSearchAds()
  1112. {
  1113. for (let node of _querySelectorAll('.serp-item'))
  1114. if (_getAttribute.call(node, 'role') === 'complementary' ||
  1115. adWords.test((node.querySelector('.label')||{}).textContent))
  1116. hide(node);
  1117. }
  1118. // News ads
  1119. function removeNewsAds()
  1120. {
  1121. let node, block, item, items, mask, classes,
  1122. masks = [
  1123. { class: '.ads__wrapper', regex: /[^,]*?,[^,]*?\.ads__wrapper/ },
  1124. { class: '.ads__pool', regex: /[^,]*?,[^,]*?\.ads__pool/ }
  1125. ];
  1126. for (node of _querySelectorAll('style[nonce]'))
  1127. {
  1128. classes = node.innerText.replace(/\{[^}]+\}+/ig, '|').split('|');
  1129. for (block of classes) for (mask of masks)
  1130. if (block.includes(mask.class))
  1131. {
  1132. block = block.match(mask.regex)[0];
  1133. items = _querySelectorAll(block);
  1134. for (item of items)
  1135. remove(items[0]);
  1136. }
  1137. }
  1138. }
  1139. // Music ads
  1140. function removeMusicAds()
  1141. {
  1142. for (let node of _querySelectorAll('.ads-block'))
  1143. remove(node);
  1144. }
  1145. // Mail ads
  1146. function removeMailAds()
  1147. {
  1148. let slice = Array.prototype.slice,
  1149. nodes = slice.call(_querySelectorAll('.ns-view-folders')),
  1150. node, len, cls;
  1151.  
  1152. for (node of nodes)
  1153. if (!len || len > node.classList.length)
  1154. len = node.classList.length;
  1155.  
  1156. node = nodes.pop();
  1157. while (node)
  1158. {
  1159. if (node.classList.length > len)
  1160. for (cls of slice.call(node.classList))
  1161. if (cls.indexOf('-') === -1)
  1162. {
  1163. remove(node);
  1164. break;
  1165. }
  1166. node = nodes.pop();
  1167. }
  1168. }
  1169. // News fixes
  1170. function removePageAdsClass()
  1171. {
  1172. if (document.body.classList.contains("b-page_ads_yes"))
  1173. {
  1174. document.body.classList.remove("b-page_ads_yes");
  1175. console.log('Page ads class removed.');
  1176. }
  1177. }
  1178. // TV fixes
  1179. function removeTVAds()
  1180. {
  1181. for (let node of _querySelectorAll('div[class^="_"][data-reactid] > div'))
  1182. if (yadWord.test(node.textContent) || node.querySelector('iframe:not([src])'))
  1183. {
  1184. if (node.offsetWidth)
  1185. {
  1186. let pad = document.createElement('div');
  1187. _setAttribute.call(pad, 'style', `width:${node.offsetWidth}px`);
  1188. node.parentNode.appendChild(pad);
  1189. }
  1190. remove(node);
  1191. }
  1192. }
  1193.  
  1194. if (location.hostname.startsWith('mail.')) {
  1195. pageUpdateObserver(
  1196. function(ms, o)
  1197. {
  1198. let aside = _querySelector('.mail-Layout-Aside');
  1199. if (aside) {
  1200. o.disconnect();
  1201. pageUpdateObserver(removeMailAds, aside);
  1202. }
  1203. }, document.body
  1204. );
  1205. removeMailAds();
  1206. } else if (location.hostname.startsWith('music.')) {
  1207. pageUpdateObserver(removeMusicAds, _querySelector('.sidebar'));
  1208. removeMusicAds();
  1209. } else if (location.hostname.startsWith('news.')) {
  1210. pageUpdateObserver(removeNewsAds, document.body);
  1211. pageUpdateObserver(removePageAdsClass, document.body, { attributes:true, attributesFilter:['class'] });
  1212. removeNewsAds();
  1213. removePageAdsClass();
  1214. } else if (location.hostname.startsWith('tv.')) {
  1215. pageUpdateObserver(removeTVAds, document.body);
  1216. removeTVAds();
  1217. } else {
  1218. pageUpdateObserver(removeSearchAds, _querySelector('.main__content'));
  1219. removeSearchAds();
  1220. }
  1221. }
  1222. );
  1223. }
  1224.  
  1225. // Yandex Link Tracking
  1226. if (/^https?:\/\/([^.]+\.)*yandex\.[^\/]+/i.test(win.location.href))
  1227. {
  1228. // remove banner on the start page
  1229. scriptLander(() => {
  1230. let nt = new nullTools({log: false, trace: true});
  1231. let AwapsJsonAPI_Json_prototype = {};
  1232. let AwapsJsonAPI_Json = function(...args) {
  1233. console.log('>> new AwapsJsonAPI.Json(', ...args, ')');
  1234. };
  1235. [
  1236. 'setID', 'addImageContent',
  1237. 'sendCounts', 'expand', 'refreshAd'
  1238. ].forEach(name => AwapsJsonAPI_Json.prototype[name] = nt.proxy(nt.func(null, `AwapsJsonAPI.Json.${name}`)));
  1239. AwapsJsonAPI_Json.prototype.checkBannerVisibility = nt.proxy(nt.func(true, 'AwapsJsonAPI.Json.checkBannerVisibility'));
  1240. AwapsJsonAPI_Json.prototype.addIframeContent = nt.proxy(function(...args) {
  1241. try {
  1242. let frame = args[1][0].parentNode;
  1243. frame.parentNode.removeChild(frame);
  1244. console.log(`Removed banner placeholder.`);
  1245. } catch(ignore) {
  1246. console.log(`Can't locate frame object to remove.`);
  1247. }
  1248. });
  1249. AwapsJsonAPI_Json.prototype.getHTML = nt.proxy(nt.func('', 'AwapsJsonAPI.Json.getHTML'));
  1250. AwapsJsonAPI_Json.prototype = nt.proxy(AwapsJsonAPI_Json.prototype);
  1251. AwapsJsonAPI_Json = nt.proxy(AwapsJsonAPI_Json);
  1252. if ('AwapsJsonAPI' in win) {
  1253. console.log('Oops! AwapsJsonAPI already defined.');
  1254. let f = win.AwapsJsonAPI.Json;
  1255. win.AwapsJsonAPI.Json = AwapsJsonAPI_Json;
  1256. if (f && f.prototype)
  1257. f.prototype = AwapsJsonAPI_Json.prototype;
  1258. } else {
  1259. nt.define(win, 'AwapsJsonAPI', nt.proxy({
  1260. Json: AwapsJsonAPI_Json
  1261. }));
  1262. }
  1263.  
  1264. let home = win.home || {};
  1265. let parseExport = x => {
  1266. if (!x)
  1267. return x;
  1268. // remove banner placeholder
  1269. if (x.banner && x.banner.cls) {
  1270. let _parent = `.${x.banner.cls.banner__parent}`;
  1271. document.addEventListener('DOMContentLoaded', () => {
  1272. for (let banner of document.querySelectorAll(_parent)) {
  1273. _setAttribute.call(banner, 'style', 'display:none!important');
  1274. console.log('Hid banner placeholder.');
  1275. }
  1276. }, false);
  1277. }
  1278.  
  1279. // remove banner data and some other stuff
  1280. delete x.banner;
  1281. delete x.consistency;
  1282. delete x['i-bannerid'];
  1283. delete x['i-counter'];
  1284. delete x['ga-counter'];
  1285. delete x['promo-curtain'];
  1286.  
  1287. return x;
  1288. };
  1289. let home_export = parseExport(home.export);
  1290. Object.defineProperty(home, 'export', {
  1291. get: x => home_export,
  1292. set: x => {
  1293. home_export = parseExport(x);
  1294. }
  1295. });
  1296. nt.define(win, 'home', home);
  1297. }, nullTools, '_setAttribute = Element.prototype.setAttribute');
  1298.  
  1299. if ('attachShadow' in Element.prototype) {
  1300. let fakeRoot = () => ({
  1301. firstChild: null,
  1302. appendChild: ()=>null,
  1303. querySelector: ()=>null,
  1304. querySelectorAll: ()=>null
  1305. });
  1306. Element.prototype.createShadowRoot = fakeRoot;
  1307. let shadows = new WeakMap();
  1308. let _attachShadow = Object.getOwnPropertyDescriptor(Element.prototype, 'attachShadow');
  1309. let _call_attachShadow = _attachShadow.value;
  1310. _attachShadow.value = function() {
  1311. return shadows.set(this, fakeRoot()).get(this);
  1312. };
  1313. Object.defineProperty(Element.prototype, 'attachShadow', _attachShadow);
  1314. let _shadowRoot = Object.getOwnPropertyDescriptor(Element.prototype, 'shadowRoot');
  1315. _shadowRoot.set = () => null;
  1316. _shadowRoot.get = function() {
  1317. return shadows.has(this) ? shadows.get(this) : void 0;
  1318. };
  1319. Object.defineProperty(Element.prototype, 'shadowRoot', _shadowRoot);
  1320. }
  1321. // Partially based on https://gf.qytechs.cn/en/scripts/22737-remove-yandex-redirect
  1322. let selectors = (
  1323. 'A[onmousedown*="/jsredir"],'+
  1324. 'A[data-vdir-href],'+
  1325. 'A[data-counter]'
  1326. );
  1327. let removeTrackingAttributes = function(link)
  1328. {
  1329. link.removeAttribute('onmousedown');
  1330. if (link.hasAttribute('data-vdir-href')) {
  1331. link.removeAttribute('data-vdir-href');
  1332. link.removeAttribute('data-orig-href');
  1333. }
  1334. if (link.hasAttribute('data-counter')) {
  1335. link.removeAttribute('data-counter');
  1336. link.removeAttribute('data-bem');
  1337. }
  1338. };
  1339. let removeTracking = function(scope)
  1340. {
  1341. for (let link of scope.querySelectorAll(selectors))
  1342. removeTrackingAttributes(link);
  1343. };
  1344. document.addEventListener('DOMContentLoaded', (e) => removeTracking(e.target));
  1345. (new MutationObserver(
  1346. function(ms)
  1347. {
  1348. let m, node;
  1349. for (m of ms) for (node of m.addedNodes) if (node.nodeType === _Node.ELEMENT_NODE)
  1350. if (node.tagName === 'A' && node.matches(selectors)) {
  1351. removeTrackingAttributes(node);
  1352. } else {
  1353. removeTracking(node);
  1354. }
  1355. }
  1356. )).observe(_de, { childList: true, subtree: true });
  1357. }
  1358.  
  1359. // https://gf.qytechs.cn/en/scripts/21937-moonwalk-hdgo-kodik-fix v0.8 (adapted)
  1360. document.addEventListener(
  1361. 'DOMContentLoaded', function()
  1362. {//createPlayer();
  1363. function log (name) {
  1364. console.log(`Player FIX: Detected ${name} player in ${location.href}`);
  1365. }
  1366. if (win.adv_enabled !== undefined && win.condition_detected !== undefined)
  1367. {
  1368. log('Moonwalk');
  1369. if (win.adv_enabled)
  1370. win.adv_enabled = false;
  1371. win.condition_detected = false;
  1372. if (win.MXoverrollCallback)
  1373. document.addEventListener(
  1374. 'click', function catcher(e)
  1375. {
  1376. e.stopPropagation();
  1377. win.MXoverrollCallback.call(window);
  1378. document.removeEventListener('click', catcher, true);
  1379. }, true
  1380. );
  1381. }
  1382. else if (win.stat_url !== undefined && win.is_html5 !== undefined && win.is_wp8 !== undefined)
  1383. {
  1384. log('HDGo');
  1385. document.body.onclick = null;
  1386. let tmp = document.querySelector('#swtf');
  1387. if (tmp)
  1388. tmp.style.display = 'none';
  1389. if (win.banner_second !== undefined)
  1390. win.banner_second = 0;
  1391. if (win.$banner_ads !== undefined)
  1392. win.$banner_ads = false;
  1393. if (win.$new_ads !== undefined)
  1394. win.$new_ads = false;
  1395. if (win.createCookie !== undefined)
  1396. win.createCookie('popup', 'true', '999');
  1397. if (win.canRunAds !== undefined && win.canRunAds !== true)
  1398. win.canRunAds = true;
  1399. }
  1400. else if (win.MXoverrollCallback && win.iframeSearch !== undefined)
  1401. {
  1402. log('Kodik');
  1403. let tmp = document.querySelector('.play_button');
  1404. if (tmp)
  1405. tmp.onclick = win.MXoverrollCallback.bind(window);
  1406. win.IsAdBlock = false;
  1407. }
  1408. else if (win.getnextepisode && win.uppodEvent)
  1409. {
  1410. log('Share-Serials.net');
  1411. scriptLander(
  1412. function()
  1413. {
  1414. let _setInterval = win.setInterval,
  1415. _setTimeout = win.setTimeout;
  1416. win.setInterval = function(func)
  1417. {
  1418. if (func instanceof Function && func.toString().indexOf('_delay') > -1)
  1419. {
  1420. let intv = _setInterval.call(
  1421. this, function()
  1422. {
  1423. _setTimeout.call(
  1424. this, function(intv)
  1425. {
  1426. clearInterval(intv);
  1427. let timer = document.querySelector('#timer');
  1428. if (timer)
  1429. timer.click();
  1430. }, 100, intv);
  1431. func.call(this);
  1432. }, 5
  1433. );
  1434.  
  1435. return intv;
  1436. }
  1437. return _setInterval.apply(this, arguments);
  1438. };
  1439. win.setTimeout = function(func) {
  1440. if (func instanceof Function && func.toString().indexOf('adv_showed') > -1)
  1441. {
  1442. return _setTimeout.call(this, func, 0);
  1443. }
  1444. return _setTimeout.apply(this, arguments);
  1445. };
  1446. }
  1447. );
  1448. } else if ('ADC' in win)
  1449. {
  1450. log('vjs-creatives plugin in');
  1451. let replacer = (obj) => {
  1452. for (let name in obj)
  1453. if (obj[name] instanceof Function)
  1454. obj[name] = () => null;
  1455. };
  1456. replacer(win.ADC);
  1457. replacer(win.currentAdSlot);
  1458. }
  1459. UberVK: {
  1460. if (!inIFrame)
  1461. break UberVK;
  1462. let oddNames = 'HD' in win &&
  1463. !Object.getOwnPropertyNames(win).every(n => !n.startsWith('_0x'));
  1464. if (!oddNames)
  1465. break UberVK;
  1466. log('UberVK');
  1467. XMLHttpRequest.prototype.open = () => { throw 404; };
  1468. }
  1469. }, false
  1470. );
  1471.  
  1472. // piguiqproxy.com circumvention prevention
  1473. scriptLander(
  1474. () => {
  1475. let _open = XMLHttpRequest.prototype.open;
  1476. // blacklist of third-party domains requests to which are ignored
  1477. let blacklist = /[/.@](amgload\.net|dsn-fishki\.ru|kingoablc\.com|piguiqproxy\.com|rcdn\.pro)[:/]/i;
  1478. // blacklist of domains where all third-party requests are ignored
  1479. let ondomains = /(^|[/.@])oane\.ws($|[:/])/i;
  1480. // highly suspicious URLs
  1481. let suspicious = /^https?:\/\/(csp-)?[a-z0-9]{6}\.ru\//i;
  1482. let on_get_ban = /^https?:\/\/(csp-)?[a-z0-9]{6}\.ru\/([a-z0-9\/]{45,}|[a-z0-9]{8,}|ad\/banner\/.+)$/i;
  1483. let on_post_ban = /^https?:\/\/(csp-)?[a-z0-9]{6}\.ru\/([a-z0-9]{6,})$/i;
  1484.  
  1485. XMLHttpRequest.prototype.open = function(method, url)
  1486. {
  1487. if (method === 'GET' &&
  1488. (blacklist.test(url) || on_get_ban.test(url) ||
  1489. ondomains.test(location.hostname) && !ondomains.test(url)) ||
  1490. method === 'POST' && on_post_ban.test(url))
  1491. {
  1492. this.send = () => null;
  1493. this.setRequestHeader = () => null;
  1494. console.log('Blocked request: ', url);
  1495. return;
  1496. }
  1497. if (suspicious.test(url))
  1498. console.warn('Suspicious request: ', url);
  1499. return _open.apply(this, arguments);
  1500. };
  1501. }
  1502. );
  1503.  
  1504. // === Helper functions ===
  1505.  
  1506. // function to search and remove nodes by content
  1507. // selector - standard CSS selector to define set of nodes to check
  1508. // words - regular expression to check content of the suspicious nodes
  1509. // params - object with multiple extra parameters:
  1510. // .log - display log in the console
  1511. // .hide - set display to none instead of removing from the page
  1512. // .parent - parent node to remove if content is found in the child node
  1513. // .siblings - number of simling nodes to remove (excluding text nodes)
  1514. let scRemove = (node) => node.parentNode.removeChild(node);
  1515. let scHide = function(node)
  1516. {
  1517. let style = _getAttribute.call(node, 'style') || '',
  1518. hide = ';display:none!important;';
  1519. if (style.indexOf(hide) < 0)
  1520. _setAttribute.call(node, 'style', style + hide);
  1521. };
  1522.  
  1523. function scissors (selector, words, scope, params)
  1524. {
  1525. let logger = function() { return params.log ? console.log(...arguments) : null; };
  1526. if (!scope.contains(document.body))
  1527. logger('[s] scope', scope);
  1528. let remFunc = (params.hide ? scHide : scRemove),
  1529. iterFunc = (params.siblings > 0 ? 'nextElementSibling' : 'previousElementSibling'),
  1530. toRemove = [],
  1531. siblings;
  1532. for (let node of scope.querySelectorAll(selector))
  1533. {
  1534. // drill up to a parent node if specified, break if not found
  1535. if (params.parent)
  1536. {
  1537. let old = node;
  1538. node = node.closest(params.parent);
  1539. if (node === null || node.contains(scope))
  1540. {
  1541. logger('[s] went out of scope with', old);
  1542. continue;
  1543. }
  1544. }
  1545. logger('[s] processing', node);
  1546. if (toRemove.includes(node))
  1547. continue;
  1548. if (words.test(node.innerHTML))
  1549. {
  1550. // skip node if already marked for removal
  1551. logger('[s] marked for removal');
  1552. toRemove.push(node);
  1553. // add multiple nodes if defined more than one sibling
  1554. siblings = Math.abs(params.siblings) || 0;
  1555. while (siblings)
  1556. {
  1557. node = node[iterFunc];
  1558. if (!node) break; // can't go any further - exit
  1559. logger('[s] adding sibling node', node);
  1560. toRemove.push(node);
  1561. siblings -= 1;
  1562. }
  1563. }
  1564. }
  1565. let toSkip = [];
  1566. for (let node of toRemove)
  1567. if (!toRemove.every(other => other === node || !node.contains(other)))
  1568. toSkip.push(node);
  1569. if (toRemove.length)
  1570. logger(`[s] proceeding with ${params.hide?'hide':'removal'} of`, toRemove, `skip`, toSkip);
  1571. for (let node of toRemove) if (!toSkip.includes(node))
  1572. remFunc(node);
  1573. }
  1574.  
  1575. // function to perform multiple checks if ads inserted with a delay
  1576. // by default does 30 checks withing a 3 seconds unless nonstop mode specified
  1577. // also does 1 extra check when a page completely loads
  1578. // selector and words - passed dow to scissors
  1579. // params - object with multiple extra parameters:
  1580. // .log - display log in the console
  1581. // .root - selector to narrow down scope to scan;
  1582. // .observe - if true then check will be performed continuously;
  1583. // Other parameters passed down to scissors.
  1584. function gardener(selector, words, params)
  1585. {
  1586. let logger = function() { return params.log ? console.log(...arguments) : null; };
  1587. params = params || {};
  1588. logger(`[gardener] selector: '${selector}' detector: ${words} options: ${JSON.stringify(params)}`);
  1589. let scope;
  1590. let globalScope = [_de];
  1591. let domLoaded = false;
  1592. let getScope = root => root ? _de.querySelectorAll(root) : globalScope;
  1593. let onevent = e => {
  1594. logger(`[gardener] cleanup on ${Object.getPrototypeOf(e)} "${e.type}"`);
  1595. for (let node of scope)
  1596. scissors(selector, words, node, params);
  1597. };
  1598. let repeater = n => {
  1599. if (!domLoaded && n) {
  1600. setTimeout(repeater, 500, n - 1);
  1601. scope = getScope(params.root);
  1602. if (!scope) // exit if the root element is not present on the page
  1603. return 0;
  1604. onevent({type: 'Repeater'});
  1605. }
  1606. };
  1607. repeater(20);
  1608. document.addEventListener(
  1609. 'DOMContentLoaded', (e) => {
  1610. domLoaded = true;
  1611. // narrow down scope to a specific element
  1612. scope = getScope(params.root);
  1613. if (!scope) // exit if the root element is not present on the page
  1614. return 0;
  1615. logger('[g] scope', scope);
  1616. // add observe mode if required
  1617. if (params.observe)
  1618. {
  1619. let params = { childList:true, subtree: true };
  1620. let observer = new MutationObserver(
  1621. function(ms)
  1622. {
  1623. for (let m of ms)
  1624. if (m.addedNodes.length)
  1625. onevent(m);
  1626. }
  1627. );
  1628. for (let node of scope)
  1629. observer.observe(node, params);
  1630. logger('[g] observer enabled');
  1631. }
  1632. onevent(e);
  1633. }, false);
  1634. // wait for a full page load to do one extra cut
  1635. win.addEventListener('load', onevent, false);
  1636. }
  1637.  
  1638. // wrap popular methods to open a new tab to catch specific behaviours
  1639. function createWindowOpenWrapper(openFunc, onClickFunc)
  1640. {
  1641. let _createElement = _Document.prototype.createElement,
  1642. _appendChild = Element.prototype.appendChild,
  1643. fakeNative = (f) => (f.toString = () => `function ${f.name}() { [native code] }`);
  1644.  
  1645. let nt = new nullTools();
  1646. fakeNative(openFunc);
  1647.  
  1648. let parser = _createElement.call(document, 'a');
  1649. let openWhitelist = (url, parent) => {
  1650. parser.href = url;
  1651. return parser.hostname === 'www.imdb.com' || parser.hostname === 'www.kinopoisk.ru' ||
  1652. parent.hostname === 'radikal.ru' && url === void 0;
  1653. };
  1654.  
  1655. let redefineOpen = (root) => {
  1656. if ('open' in root) {
  1657. let _open = root.open.bind(root);
  1658. nt.define(root, 'open', (...args) => {
  1659. if (openWhitelist(args[0], location)) {
  1660. console.log('Whitelisted popup:', ...args);
  1661. return _open(...args);
  1662. }
  1663. return openFunc(...args);
  1664. });
  1665. }
  1666. };
  1667. redefineOpen(win);
  1668.  
  1669. function createElement(name) {
  1670. '[native code]';
  1671. // jshint validthis:true
  1672. let el = _createElement.apply(this, arguments);
  1673. // redefine window.open in first-party frames
  1674. if (el instanceof HTMLIFrameElement || el instanceof HTMLObjectElement)
  1675. el.addEventListener('load', (e) => {
  1676. try {
  1677. redefineOpen(e.target.contentWindow);
  1678. } catch(ignore) {}
  1679. }, false);
  1680. return el;
  1681. }
  1682. fakeNative(createElement);
  1683.  
  1684. let redefineCreateElement = (obj) => {
  1685. for (let root of [obj.document, _Document.prototype]) if ('createElement' in root)
  1686. nt.define(root, 'createElement', createElement);
  1687. };
  1688. redefineCreateElement(win);
  1689.  
  1690. // wrap window.open in newly added first-party frames
  1691. Element.prototype.appendChild = function appendChild()
  1692. {
  1693. '[native code]';
  1694. let el = _appendChild.apply(this, arguments);
  1695. if (el instanceof HTMLIFrameElement) {
  1696. try {
  1697. redefineOpen(el.contentWindow);
  1698. redefineCreateElement(el.contentWindow);
  1699. } catch(ignore) {}
  1700. }
  1701. return el;
  1702. };
  1703. fakeNative(Element.prototype.appendChild);
  1704. }
  1705.  
  1706. // Function to catch and block various methods to open a new window with 3rd-party content.
  1707. // Some advertisement networks went way past simple window.open call to circumvent default popup protection.
  1708. // This funciton blocks window.open, ability to restore original window.open from an IFRAME object,
  1709. // ability to perform an untrusted (not initiated by user) click on a link, click on a link without a parent
  1710. // node or simply a link with piece of javascript code in the HREF attribute.
  1711. function preventPopups()
  1712. {
  1713. // call sandbox-me if in iframe and not whitelisted
  1714. if (inIFrame) {
  1715. win.top.postMessage({ name: 'sandbox-me', href: win.location.href }, '*');
  1716. return;
  1717. }
  1718.  
  1719. scriptLander(() => {
  1720. let open = (...args) => {
  1721. '[native code]';
  1722. console.warn('Site attempted to open a new window', args);
  1723. if (new RegExp(`^https?://${location.hostname}/`).test(args[0])) // skip extra click in case of blocked popunder
  1724. location.assign(args[0]);
  1725. return {
  1726. document: {
  1727. write: () => {},
  1728. writeln: () => {}
  1729. },
  1730. location: {}
  1731. };
  1732. };
  1733.  
  1734. let clickHandler = (e) => {
  1735. let link = e.target;
  1736. if (!link.parentNode || !e.isTrusted ||
  1737. (link.href && link.href.trim().toLowerCase().indexOf('javascript') === 0))
  1738. {
  1739. e.preventDefault();
  1740. console.warn('Blocked suspicious click event', e, 'on', e.target);
  1741. }
  1742. };
  1743.  
  1744. createWindowOpenWrapper(open, clickHandler);
  1745.  
  1746. console.log('Popup prevention enabled.');
  1747. }, nullTools, createWindowOpenWrapper);
  1748. }
  1749.  
  1750. // Helper function to close background tab if site opens itself in a new tab and then
  1751. // loads a 3rd-party page in the background one (thus performing background redirect).
  1752. function preventPopunders()
  1753. {
  1754. // create "close_me" event to call high-level window.close()
  1755. let eventName = `close_me_${Math.random().toString(36).substr(2)}`;
  1756. let callClose = () => (console.log('close call'), window.close());
  1757. window.addEventListener(eventName, callClose, true);
  1758.  
  1759. scriptLander(() => {
  1760. // get host of a provided URL with help of an anchor object
  1761. // unfortunately new URL(url, window.location) generates wrong URL in some cases
  1762. let parseURL = document.createElement('A');
  1763. let getHost = (url) => (parseURL.href = url, parseURL.hostname);
  1764. // site went to a new tab and attempts to unload
  1765. // call for high-level close through event
  1766. let closeWindow = () => window.dispatchEvent(new CustomEvent(eventName, {}));
  1767. // check is URL local or goes to different site
  1768. let isLocal = (url) => {
  1769. if (url === location.pathname || url === location.href)
  1770. return true; // URL points to current pathname or full address
  1771. let host = getHost(url);
  1772. let site = location.hostname;
  1773. return host !== '' && // URLs with unusual protocol may have empty 'host'
  1774. (site === host || site.endsWith(`.${host}`) || host.endsWith(`.${site}`));
  1775. };
  1776.  
  1777. let _open = window.open.bind(window);
  1778. let open = (...args) => {
  1779. '[native code]';
  1780. let url = args[0];
  1781. if (url && isLocal(url))
  1782. window.addEventListener('beforeunload', closeWindow, true);
  1783. // jshint validthis:true
  1784. return _open(...args);
  1785. };
  1786.  
  1787. let clickHandler = (e) => {
  1788. if (!e.target.parentNode || !e.isTrusted)
  1789. window.addEventListener('beforeunload', closeWindow, true);
  1790. };
  1791.  
  1792. createWindowOpenWrapper(open, clickHandler);
  1793.  
  1794. console.log("Background redirect prevention enabled.");
  1795. }, `let eventName="${eventName}"`, nullTools, createWindowOpenWrapper);
  1796. }
  1797.  
  1798. // Mix between check for popups and popunders
  1799. // Significantly more agressive than both and can't be used as universal solution
  1800. function preventPopMix()
  1801. {
  1802. if (inIFrame)
  1803. {
  1804. win.top.postMessage({ name: 'sandbox-me', href: win.location.href }, '*');
  1805. return;
  1806. }
  1807.  
  1808. // create "close_me" event to call high-level window.close()
  1809. let eventName = `close_me_${Math.random().toString(36).substr(2)}`;
  1810. let callClose = () => (console.log('close call'), window.close());
  1811. window.addEventListener(eventName, callClose, true);
  1812.  
  1813. scriptLander(() => {
  1814. let _open = window.open,
  1815. parseURL = document.createElement('A');
  1816. // get host of a provided URL with help of an anchor object
  1817. // unfortunately new URL(url, window.location) generates wrong URL in some cases
  1818. let getHost = (url) => (parseURL.href = url, parseURL.host);
  1819. // site went to a new tab and attempts to unload
  1820. // call for high-level close through event
  1821. let closeWindow = () => (_open(window.location,'_self'), window.dispatchEvent(new CustomEvent(eventName, {})));
  1822. // check is URL local or goes to different site
  1823. function isLocal(url)
  1824. {
  1825. let loc = window.location;
  1826. if (url === loc.pathname || url === loc.href)
  1827. return true; // URL points to current pathname or full address
  1828. let host = getHost(url),
  1829. site = loc.host;
  1830. if (host === '')
  1831. return false; // URLs with unusual protocol may have empty 'host'
  1832. if (host.length > site.length)
  1833. [site, host] = [host, site];
  1834. return site.includes(host, site.length - host.length);
  1835. }
  1836.  
  1837. // add check for redirect for 5 seconds, then disable it
  1838. function checkRedirect()
  1839. {
  1840. window.addEventListener('beforeunload', closeWindow, true);
  1841. setTimeout(closeWindow=>window.removeEventListener('beforeunload', closeWindow, true), 5000, closeWindow);
  1842. }
  1843.  
  1844. function open(url, name)
  1845. {
  1846. '[native code]';
  1847. if (url && isLocal(url) && (!name || name === '_blank'))
  1848. {
  1849. console.warn('Suspicious local new window', arguments);
  1850. checkRedirect();
  1851. // jshint validthis:true
  1852. return _open.apply(this, arguments);
  1853. }
  1854. console.warn('Blocked attempt to open a new window', arguments);
  1855. return {
  1856. document: {
  1857. write: () => {},
  1858. writeln: () => {}
  1859. }
  1860. };
  1861. }
  1862.  
  1863. function clickHandler(e)
  1864. {
  1865. let link = e.target,
  1866. url = link.href||'';
  1867. if (e.targetParentNode && e.isTrusted || link.target !== '_blank')
  1868. {
  1869. console.log('Link', link, 'were created dinamically, but looks fine.');
  1870. return true;
  1871. }
  1872. if (isLocal(url) && link.target === '_blank')
  1873. {
  1874. console.log('Suspicious local link', link);
  1875. checkRedirect();
  1876. return;
  1877. }
  1878. console.log('Blocked suspicious click on a link', link);
  1879. e.stopPropagation();
  1880. e.preventDefault();
  1881. }
  1882.  
  1883. createWindowOpenWrapper(open, clickHandler);
  1884.  
  1885. console.log("Mixed popups prevention enabled.");
  1886. }, `let eventName="${eventName}"`, createWindowOpenWrapper);
  1887. }
  1888. // External listener for case when site known to open popups were loaded in iframe
  1889. // It will sandbox any iframe which will send message 'forbid.popups' (preventPopups sends it)
  1890. // Some sites replace frame's window.location with data-url to run in clean context
  1891. if (!inIFrame)
  1892. {
  1893. window.addEventListener(
  1894. 'message', function(e)
  1895. {
  1896. if (!e.data || e.data.name !== 'sandbox-me' || !e.data.href)
  1897. return;
  1898. let src = e.data.href;
  1899. for (let frame of document.querySelectorAll('iframe'))
  1900. if (frame.contentWindow === e.source)
  1901. {
  1902. if (frame.hasAttribute('sandbox'))
  1903. {
  1904. if (!frame.sandbox.contains('allow-popups'))
  1905. return; // exit frame since it's already sandboxed and popups are blocked
  1906. // remove allow-popups if frame already sandboxed
  1907. frame.sandbox.remove('allow-popups');
  1908. } else {
  1909. // set sandbox mode for troublesome frame and allow scripts, forms and a few other actions
  1910. // technically allowing both scripts and same-origin allows removal of the sandbox attribute,
  1911. // but to apply content must be reloaded and this script will re-apply it in the result
  1912. frame.setAttribute('sandbox','allow-forms allow-scripts allow-presentation allow-top-navigation allow-same-origin');
  1913. }
  1914. console.log('Disallowed popups from iframe', frame);
  1915.  
  1916. // reload frame content to apply restrictions
  1917. if (!src) {
  1918. src = frame.src;
  1919. console.log('Unable to get current iframe location, reloading from src', src);
  1920. } else
  1921. console.log('Reloading iframe with URL', src);
  1922. frame.src = 'about:blank';
  1923. frame.src = src;
  1924. }
  1925. }, false
  1926. );
  1927. }
  1928.  
  1929. function selectiveEval() {
  1930. scriptLander(() => {
  1931. let nt = new nullTools();
  1932. let _eval = win.eval.bind(window);
  1933. nt.define(win, 'eval', function(...args) {
  1934. if (/_0x|location\s*?=|location.href\s*?=|location.assign\(|open\(/i.test(args[0])) {
  1935. console.log(`Skipped eval of ${args[0].slice(0, 512)}\u2026`);
  1936. return null;
  1937. }
  1938. return _eval(...args);
  1939. });
  1940. }, nullTools);
  1941. }
  1942.  
  1943. // === Scripts for specific domains ===
  1944.  
  1945. let scripts = {};
  1946. // prevent popups and redirects block
  1947. // Popups
  1948. scripts.preventPopups = {
  1949. other: [
  1950. 'biqle.ru',
  1951. 'chaturbate.com',
  1952. 'dfiles.ru',
  1953. 'eporner.eu',
  1954. 'hentaiz.org',
  1955. 'mirrorcreator.com',
  1956. 'online-multy.ru',
  1957. 'radikal.ru', 'rumedia.ws',
  1958. 'thepiratebay.org',
  1959. 'unionpeer.com',
  1960. 'zippyshare.com'
  1961. ],
  1962. now: preventPopups
  1963. };
  1964. // Popunders (background redirect)
  1965. scripts.preventPopunders = {
  1966. other: [
  1967. 'lostfilm-online.ru',
  1968. 'mediafire.com', 'megapeer.org', 'megapeer.ru',
  1969. 'perfectgirls.net'
  1970. ],
  1971. now: preventPopunders
  1972. };
  1973. // PopMix (both types of popups encountered on site)
  1974. scripts['openload.co'] = {
  1975. other: ['oload.tv', 'oload.info'],
  1976. now: () => {
  1977. let nt = new nullTools();
  1978. nt.define(win, 'CNight', win.CoinHive);
  1979. if (location.pathname.startsWith('/embed/'))
  1980. {
  1981. nt.define(win, 'BetterJsPop', {
  1982. add: ((a, b) => console.warn('BetterJsPop.add', a, b)),
  1983. config: ((o) => console.warn('BetterJsPop.config', o)),
  1984. Browser: { isChrome: true }
  1985. });
  1986. nt.define(win, 'isSandboxed', nt.func(null));
  1987. nt.define(win, 'adblock', false);
  1988. nt.define(win, 'adblock2', false);
  1989. } else
  1990. preventPopMix();
  1991. }
  1992. };
  1993. scripts['turbobit.net'] = preventPopMix;
  1994.  
  1995. // workaround for moradu.com/apu.php load error handler script, not sure which ad network is this
  1996. scripts['tapochek.net'] = () => {
  1997. let _appendChild = Object.getOwnPropertyDescriptor(_Node.prototype, 'appendChild');
  1998. let _appendChild_value = _appendChild.value;
  1999. _appendChild.value = function appendChild(node) {
  2000. if (this === win.document.body)
  2001. if ((node instanceof HTMLScriptElement || node instanceof HTMLStyleElement) &&
  2002. /^https?:\/\/[0-9a-f]{15}\.com\/\d+(\/|\.css)$/.test(node.src) ||
  2003. node instanceof HTMLDivElement && node.style.zIndex > 900000 &&
  2004. node.style.backgroundImage.includes('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'))
  2005. throw '...eenope!';
  2006. return _appendChild_value.apply(this, arguments);
  2007. };
  2008. Object.defineProperty(_Node.prototype, 'appendChild', _appendChild);
  2009.  
  2010. preventPopups();
  2011. };
  2012.  
  2013. scripts['rustorka.com'] = {
  2014. other: ['rustorka.lib'],
  2015. now: () => scriptLander(() => {
  2016. let crumbler = e => { // crumble suspicious cookies
  2017. let base = '=; expires=Thu, 01 Jan 1970 00:00:01 UTC; Max-Age=-99999999; path=/';
  2018. console.log('cookies', document.cookie);
  2019. for (let name of ['adblock', 'gophp', '_692293176245', '_692293176246'])
  2020. document.cookie = `${name}${base}`;
  2021. for (let name of ['st2', 'st3']) {
  2022. document.cookie = `${name}${base}forum`;
  2023. document.cookie = `${name}${base}forum/`;
  2024. }
  2025. console.log('cookies', document.cookie);
  2026. };
  2027. document.addEventListener('DOMContentLoaded', crumbler, false);
  2028. crumbler();
  2029.  
  2030. let nt = new nullTools({trace: true});
  2031. nt.define(win, 'syka', false);
  2032. nt.define(win, '_692293176244', location.href);
  2033. [
  2034. 'MTLuxup', 'MTAdSniper', 'MTutarg', 'MTUAatar', 'MTcityAds', 'MTmxMark',
  2035. 'MTmxMark2', 'MTmdnt', 'MTrfDumedia', 'MXsmTDS', 'MTritorno', 'MTadvice',
  2036. 'cyka', 'MTAdTraff', 'MTExebid', 'MXsockFound'
  2037. ].forEach(name => nt.define(win, name, nt.func(null, name)));
  2038. let _eval_def = Object.getOwnPropertyDescriptor(win, 'eval');
  2039. if (!_eval_def)
  2040. return;
  2041. let _eval_val = _eval_def.value;
  2042. _eval_def.value = (...args) => {
  2043. if (args[0] && args[0].includes('antiadblock'))
  2044. return console.log('Anti-AdBlock script may run another day, but not today.');
  2045. return _eval_val.apply(this, args);
  2046. };
  2047. Object.defineProperty(win, 'eval', _eval_def);
  2048. win.open = (...args) => {
  2049. console.warn(`Site attempted to open "${args[0]}" in a new window.`);
  2050. location.replace(location.href);
  2051. return null;
  2052. };
  2053. window.addEventListener('DOMContentLoaded', () => {
  2054. let link = void 0;
  2055. document.body.addEventListener('mousedown', e => {
  2056. link = e.target.closest('a, select, #fancybox-title-wrap');
  2057. }, false);
  2058. let _open = window.open.bind(window);
  2059. let _getAttribute = Element.prototype.getAttribute;
  2060. win.open = (...args) => {
  2061. let url = args[0];
  2062. let allow = false;
  2063. if (link instanceof HTMLAnchorElement) {
  2064. // third-party post links
  2065. let href = _getAttribute.call(link, 'href');
  2066. if (link.classList.contains('postLink') &&
  2067. !link.matches(`a[href*="${location.hostname}"]`) &&
  2068. (href === url || link.href === url)) {
  2069. return _open(...args);
  2070. }
  2071. // onclick # links
  2072. if (href === '#' && /window\.open/.test(_getAttribute.call(link, 'onclick'))) {
  2073. return _open(...args);
  2074. }
  2075. // force local links to load in the current window
  2076. if (href[0] === '/' || href.startsWith('./') || href.includes(`//${location.hostname}/`))
  2077. location.assign(href);
  2078. }
  2079. // list of image hostings under upload picture button (new comment)
  2080. if (link instanceof HTMLSelectElement &&
  2081. !url.includes(location.hostname) &&
  2082. link.value === url) {
  2083. return _open(...args);
  2084. }
  2085. // open screenshot in a new window
  2086. if (link instanceof HTMLSpanElement &&
  2087. link.id === 'fancybox-title-wrap') {
  2088. return _open(...args);
  2089. }
  2090. // looks like tabunder
  2091. if (link === null && url === location.href)
  2092. location.replace(url); // reload current page
  2093. // other cases
  2094. console.warn(`Site attempted to open "${url}" in a new window. Source: `, link);
  2095. return {};
  2096. };
  2097. }, true);
  2098. }, nullTools)
  2099. };
  2100.  
  2101. // other
  2102. scripts['1tv.ru'] = () => scriptLander(() => {
  2103. let nt = new nullTools();
  2104. nt.define(win, 'EUMPAntiblockConfig', nt.proxy({url: '//www.1tv.ru/favicon.ico'}));
  2105. let disablePlugins = {
  2106. 'antiblock': false,
  2107. 'stat1tv': false
  2108. };
  2109. let _EUMPConfig = void 0;
  2110. let _EUMPConfig_set = x => {
  2111. if (x.plugins) {
  2112. x.plugins = x.plugins.filter(plugin => (plugin in disablePlugins) ? !(disablePlugins[plugin] = true) : true);
  2113. console.warn(`Player plugins: active [${x.plugins}], disabled [${Object.keys(disablePlugins).filter(x => disablePlugins[x])}]`);
  2114. }
  2115. _EUMPConfig = x;
  2116. };
  2117. if ('EUMPConfig' in win)
  2118. _EUMPConfig_set(win.EUMPConfig);
  2119. Object.defineProperty(win, 'EUMPConfig', {
  2120. enumerable: true,
  2121. get: x => _EUMPConfig,
  2122. set: _EUMPConfig_set
  2123. });
  2124. }, nullTools);
  2125.  
  2126. scripts['2picsun.ru'] = {
  2127. other: [
  2128. 'pics2sun.ru', '3pics-img.ru'
  2129. ],
  2130. now: () => {
  2131. Object.defineProperty(navigator, 'userAgent', {value: 'googlebot'});
  2132. }
  2133. };
  2134.  
  2135. scripts['4pda.ru'] = {
  2136. now: () => {
  2137. // https://gf.qytechs.cn/en/scripts/14470-4pda-unbrender
  2138. let hStyle,
  2139. isForum = document.location.href.search('/forum/') !== -1,
  2140. remove = (node) => (node ? node.parentNode.removeChild(node) : null),
  2141. afterClean = () => remove(hStyle);
  2142.  
  2143. function beforeClean()
  2144. {
  2145. // attach styles before document displayed
  2146. hStyle = createStyle([
  2147. 'html { overflow-y: scroll }',
  2148. 'article + aside * { display: none !important }',
  2149. `section[id] {${(
  2150. 'position: absolute;'+
  2151. 'width: 100%'
  2152. )}}`,
  2153. `#header + div:after {${(
  2154. 'content: "";'+
  2155. 'position: fixed;'+
  2156. 'top: 0;'+
  2157. 'left: 0;'+
  2158. 'width: 100%;'+
  2159. 'height: 100%;'+
  2160. 'background-color: #E6E7E9'
  2161. )}}`,
  2162. // http://codepen.io/Beaugust/pen/DByiE
  2163. '@keyframes spin { 100% { transform: rotate(360deg) } }',
  2164. `article + aside:after {${(
  2165. 'content: "";'+
  2166. 'position: absolute;'+
  2167. 'width: 150px;'+
  2168. 'height: 150px;'+
  2169. 'top: 150px;'+
  2170. 'left: 50%;'+
  2171. 'margin-top: -75px;'+
  2172. 'margin-left: -75px;'+
  2173. 'box-sizing: border-box;'+
  2174. 'border-radius: 100%;'+
  2175. 'border: 10px solid rgba(0, 0, 0, 0.2);'+
  2176. 'border-top-color: rgba(0, 0, 0, 0.6);'+
  2177. 'animation: spin 2s infinite linear'
  2178. )}}`
  2179. ], {id:'ubrHider'}, true);
  2180.  
  2181. // display content of a page if time to load a page is more than 2 seconds to avoid
  2182. // blocking access to a page if it is loading for too long or stuck in a loading state
  2183. setTimeout(2000, afterClean);
  2184. }
  2185.  
  2186. createStyle([
  2187. '#nav .use-ad { display: block !important }',
  2188. 'article:not(.post) + article:not(#id),'+
  2189. 'html:not(#id)>body:not(#id) a[target="_blank"] img[height="90"] { display: none !important }'
  2190. ]);
  2191.  
  2192. if (!isForum)
  2193. beforeClean();
  2194.  
  2195. // save links to non-overridden functions to use later
  2196. let protectedElems;
  2197. // protect/hide changed attributes in case site attempt to restore them
  2198. function styleProtector(eventMode)
  2199. {
  2200. let _toLowerCase = String.prototype.toLowerCase,
  2201. isStyleText = (t) => (_toLowerCase.call(t) === 'style'),
  2202. protectedElems = new WeakMap();
  2203. function protoOverride(element, functionName, isStyleCheck, returnIfProtected)
  2204. {
  2205. let originalFunction = element.prototype[functionName];
  2206. element.prototype[functionName] = function wrapper()
  2207. {
  2208. if (protectedElems.has(this) && isStyleCheck(arguments[0]))
  2209. return returnIfProtected(this, arguments);
  2210. return originalFunction.apply(this, arguments);
  2211. };
  2212. }
  2213. protoOverride(Element, 'removeAttribute', isStyleText, () => undefined);
  2214. protoOverride(Element, 'hasAttribute', isStyleText, (_this) => protectedElems.get(_this) !== null);
  2215. protoOverride(Element, 'setAttribute', isStyleText, (_this, args) => protectedElems.set(_this, args[1]));
  2216. protoOverride(Element, 'getAttribute', isStyleText, (_this) => protectedElems.get(_this));
  2217. if (!eventMode)
  2218. return protectedElems;
  2219. else
  2220. {
  2221. let e = document.createEvent('Event');
  2222. e.initEvent('protoOverride', false, false);
  2223. window.protectedElems = protectedElems;
  2224. window.dispatchEvent(e);
  2225. }
  2226. }
  2227. if (!isFirefox)
  2228. protectedElems = styleProtector(false);
  2229. else
  2230. {
  2231. let script = document.createElement('script');
  2232. script.textContent = `(${styleProtector.toString()})(true);`;
  2233. window.addEventListener(
  2234. 'protoOverride', function protoOverrideCallback(e)
  2235. {
  2236. if (win.protectedElems) {
  2237. protectedElems = win.protectedElems;
  2238. delete win.protectedElems;
  2239. }
  2240. document.removeEventListener('protoOverride', protoOverrideCallback, true);
  2241. }, true
  2242. );
  2243. _appendChild(script);
  2244. _removeChild(script);
  2245. }
  2246.  
  2247. // clean a page
  2248. window.addEventListener(
  2249. 'DOMContentLoaded', function()
  2250. {
  2251. let width = () => window.innerWidth || _de.clientWidth || document.body.clientWidth || 0;
  2252. let height = () => window.innerHeight || _de.clientHeight || document.body.clientHeight || 0;
  2253.  
  2254. if (isForum)
  2255. {
  2256. let si = document.querySelector('#logostrip');
  2257. if (si)
  2258. remove(si.parentNode.nextSibling);
  2259. }
  2260.  
  2261. // clear background in the download frame
  2262. if (location.pathname.startsWith('/forum/dl/')) {
  2263. let setBackground = node => _setAttribute.call(
  2264. node,
  2265. 'style', (_getAttribute.call(node, 'style') || '') +
  2266. ';background-color:#4ebaf6!important'
  2267. );
  2268. setBackground(document.body);
  2269. for (let itm of document.querySelectorAll('body > div'))
  2270. if (!itm.querySelector('.dw-fdwlink, .content') && !itm.classList.contains('footer')) {
  2271. remove(itm);
  2272. } else {
  2273. setBackground(itm);
  2274. }
  2275. }
  2276.  
  2277. if (isForum) // Do not continue if it's a forum
  2278. return;
  2279.  
  2280. {
  2281. let si = document.querySelector('#header');
  2282. if (si)
  2283. {
  2284. let rem = si.previousSibling;
  2285. while (rem)
  2286. {
  2287. si = rem.previousSibling;
  2288. remove(rem);
  2289. rem = si;
  2290. }
  2291. }
  2292. }
  2293.  
  2294. for (let itm of document.querySelectorAll('#nav li[class]'))
  2295. if (itm && itm.querySelector('a[href^="/tag/"]'))
  2296. remove(itm);
  2297.  
  2298. let style, result,
  2299. fakeStyles = new WeakMap(),
  2300. styleProxy = {
  2301. get: function(target, prop)
  2302. {
  2303. let fakeStyle = fakeStyles.get(target);
  2304. return ((prop in fakeStyle) ? fakeStyle : target)[prop];
  2305. },
  2306. set: function(target, prop, value)
  2307. {
  2308. let fakeStyle = fakeStyles.get(target);
  2309. ((prop in fakeStyle) ? fakeStyle : target)[prop] = value;
  2310. return true;
  2311. }
  2312. };
  2313. for (let itm of document.querySelectorAll('DIV, A'))
  2314. {
  2315. if (itm.tagName ==='DIV' &&
  2316. itm.offsetWidth > 0.95 * width() &&
  2317. itm.offsetHeight > 0.85 * height())
  2318. {
  2319. style = window.getComputedStyle(itm, null);
  2320. result = [];
  2321.  
  2322. if (style.backgroundImage !== 'none')
  2323. result.push('background-image:none!important');
  2324.  
  2325. if (style.backgroundColor !== 'transparent' &&
  2326. style.backgroundColor !== 'rgba(0, 0, 0, 0)')
  2327. result.push('background-color:transparent!important');
  2328.  
  2329. if (result.length)
  2330. {
  2331. if (itm.getAttribute('style'))
  2332. result.unshift(itm.getAttribute('style'));
  2333.  
  2334. fakeStyles.set(itm.style, {
  2335. 'backgroundImage': itm.style.backgroundImage,
  2336. 'backgroundColor': itm.style.backgroundColor
  2337. });
  2338.  
  2339. try {
  2340. Object.defineProperty(itm, 'style', {
  2341. value: new Proxy(itm.style, styleProxy),
  2342. enumerable: true
  2343. });
  2344. } catch (e) {
  2345. console.log('Unable to protect style property.', e);
  2346. }
  2347.  
  2348. if (protectedElems)
  2349. protectedElems.set(itm, _getAttribute.call(itm, 'style'));
  2350.  
  2351. _setAttribute.call(itm, 'style', result.join(';'));
  2352. }
  2353. }
  2354. if (itm.tagName ==='A' &&
  2355. (itm.offsetWidth > 0.95 * width() ||
  2356. itm.offsetHeight > 0.85 * height()))
  2357. {
  2358. if (protectedElems)
  2359. protectedElems.set(itm, _getAttribute.call(itm, 'style'));
  2360.  
  2361. _setAttribute.call(itm, 'style', 'display:none!important');
  2362. }
  2363. }
  2364.  
  2365. for (let itm of document.querySelectorAll('ASIDE>DIV'))
  2366. if ( ((itm.querySelector('script, iframe, a[href*="/ad/www/"]') ||
  2367. itm.querySelector('img[src$=".gif"]:not([height="0"]), img[height="400"]')) &&
  2368. !itm.classList.contains('post') ) || !itm.childNodes.length )
  2369. remove(itm);
  2370.  
  2371. document.body.setAttribute('style', (document.body.getAttribute('style')||'')+';background-color:#E6E7E9!important');
  2372.  
  2373. // display content of the page
  2374. afterClean();
  2375. }
  2376. );
  2377. }
  2378. };
  2379.  
  2380. scripts['adhands.ru'] = () => scriptLander(() => {
  2381. let nt = new nullTools();
  2382. try {
  2383. let _adv;
  2384. Object.defineProperty(win, 'adv', {
  2385. get: () => _adv,
  2386. set: (v) => {
  2387. console.log('Blocked advert on adhands.ru.');
  2388. nt.define(v, 'advert', '');
  2389. _adv = v;
  2390. }
  2391. });
  2392. } catch (ignore) {
  2393. if (!win.adv)
  2394. console.log('Unable to locate advert on adhands.ru.');
  2395. else {
  2396. console.log('Blocked advert on adhands.ru.');
  2397. nt.define(win.adv, 'advert', '');
  2398. }
  2399. }
  2400. }, nullTools);
  2401.  
  2402. scripts['all-episodes.tv'] = () => {
  2403. let nt = new nullTools();
  2404. nt.define(win, 'perX1', 2);
  2405. createStyle('#advtss, #ad3, a[href*="/ad.admitad.com/"] { display:none!important }');
  2406. };
  2407.  
  2408. scripts['allhentai.ru'] = () => {
  2409. selectiveEval();
  2410. preventPopups();
  2411. scriptLander(() => {
  2412. let _onerror = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'onerror');
  2413. if (!_onerror)
  2414. return;
  2415. _onerror.set = (...args) => console.log(args[0].toString());
  2416. Object.defineProperty(HTMLElement.prototype, 'onerror', _onerror);
  2417. });
  2418. };
  2419.  
  2420. scripts['allmovie.pro'] = {
  2421. other: ['rufilmtv.org'],
  2422. dom: function()
  2423. {
  2424. // pretend to be Android to make site use different played for ads
  2425. if (isSafari)
  2426. return;
  2427. Object.defineProperty(navigator, 'userAgent', {
  2428. get: function(){ 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'; },
  2429. enumerable: true
  2430. });
  2431. }
  2432. };
  2433.  
  2434. scripts['anidub-online.ru'] = {
  2435. other: ['online.anidub.com'],
  2436. dom: function()
  2437. {
  2438. if (win.ogonekstart1)
  2439. win.ogonekstart1 = () => console.log("Fire in the hole!");
  2440. },
  2441. now: () => createStyle([
  2442. '.background {background: none!important;}',
  2443. '.background > script + div,'+
  2444. '.background > script ~ div:not([id]):not([class]) + div[id][class]'+
  2445. '{display:none!important}'
  2446. ])
  2447. };
  2448.  
  2449. scripts['drive2.ru'] = () => gardener('.c-block:not([data-metrika="recomm"]),.o-grid__item', />Реклама<\//i);
  2450.  
  2451. scripts['fishki.net'] = () => {
  2452. scriptLander(() => {
  2453. let nt = new nullTools();
  2454. let fishki = {};
  2455. nt.define(fishki, 'adv', nt.proxy({
  2456. afterAdblockCheck: nt.func(null),
  2457. refreshFloat: nt.func(null)
  2458. }));
  2459. nt.define(fishki, 'is_adblock', false);
  2460. nt.define(win, 'fishki', fishki);
  2461. }, nullTools);
  2462. gardener('.drag_list > .drag_element, .list-view > .paddingtop15, .post-wrap', /543769|Новости\sпартнеров|Полезная\sреклама/);
  2463. };
  2464.  
  2465. scripts['gidonline.club'] = () => createStyle('.tray > div[style] {display: none!important}');
  2466.  
  2467. scripts['hdgo.cc'] = {
  2468. other: ['46.30.43.38', 'couber.be'],
  2469. now: () => (new MutationObserver(
  2470. (ms) => {
  2471. let m, node;
  2472. for (m of ms) for (node of m.addedNodes)
  2473. if (node.tagName instanceof HTMLScriptElement && _getAttribute.call(node, 'onerror') !== null)
  2474. node.removeAttribute('onerror');
  2475. }
  2476. )).observe(document.documentElement, { childList:true, subtree: true })
  2477. };
  2478.  
  2479. scripts['gismeteo.ru'] = {
  2480. other: ['gismeteo.ua'],
  2481. now: () => gardener('div > script', /AdvManager/i, { observe: true, parent: 'div' })
  2482. };
  2483.  
  2484. scripts['hdrezka.ag'] = () => {
  2485. Object.defineProperty(win, 'ab', { value: false, enumerable: true });
  2486. gardener('div[id][onclick][onmouseup][onmousedown]', /onmouseout/i);
  2487. };
  2488.  
  2489. scripts['hideip.me'] = {
  2490. now: () => scriptLander(() => {
  2491. let _innerHTML = Object.getOwnPropertyDescriptor(Element.prototype, 'innerHTML');
  2492. let _set_innerHTML = _innerHTML.set;
  2493. let _innerText = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'innerText');
  2494. let _get_innerText = _innerText.get;
  2495. let div = document.createElement('div');
  2496. _innerHTML.set = function(...args) {
  2497. _set_innerHTML.call(div, args[0].replace('i','a'));
  2498. if (args[0] && /[рp][еe]кл/.test(_get_innerText.call(div))||
  2499. /(\d\d\d?\.){3}\d\d\d?\:\d/.test(_get_innerText.call(this)) ) {
  2500. console.log('Anti-Adblock killed.');
  2501. return true;
  2502. }
  2503. _set_innerHTML.apply(this, args);
  2504. };
  2505. Object.defineProperty(Element.prototype, 'innerHTML', _innerHTML);
  2506. Object.defineProperty(win, 'adblock', {
  2507. get: x => false,
  2508. set: x => null,
  2509. enumerable: true
  2510. });
  2511. let _$ = {};
  2512. let _$_map = new WeakMap();
  2513. let _gOPD = Object.getOwnPropertyDescriptor(Object, 'getOwnPropertyDescriptor');
  2514. let _val_gOPD = _gOPD.value;
  2515. _gOPD.value = function(...args) {
  2516. let _res = _val_gOPD.apply(this, args);
  2517. if (args[0] instanceof Window && (args[1] === '$' || args[1] === 'jQuery')) {
  2518. delete _res.get;
  2519. delete _res.set;
  2520. _res.value = win[args[1]];
  2521. }
  2522. return _res;
  2523. };
  2524. Object.defineProperty(Object, 'getOwnPropertyDescriptor', _gOPD);
  2525. let getJQWrap = (n) => {
  2526. let name = n;
  2527. return {
  2528. enumerable: true,
  2529. get: x => _$[name],
  2530. set: x => {
  2531. if (_$_map.has(x)) {
  2532. _$[name] = _$_map.get(x);
  2533. return true;
  2534. }
  2535. if (x === _$.$ || x === _$.jQuery) {
  2536. _$[name] = x;
  2537. return true;
  2538. }
  2539. _$[name] = new Proxy(x, {
  2540. apply: (t, o, args) => {
  2541. let _res = t.apply(o, args);
  2542. if (_$_map.has(_res.is)) {
  2543. _res.is = _$_map.get(_res.is);
  2544. } else {
  2545. let _is = _res.is;
  2546. _res.is = function(...args) {
  2547. if (args[0] === ':hidden')
  2548. return false;
  2549. return _is.apply(this, args);
  2550. };
  2551. _$_map.set(_is, _res.is);
  2552. }
  2553. return _res;
  2554. }
  2555. });
  2556. _$_map.set(x, _$[name]);
  2557. return true;
  2558. }
  2559. };
  2560. };
  2561. Object.defineProperty(win, '$', getJQWrap('$'));
  2562. Object.defineProperty(win, 'jQuery', getJQWrap('jQuery'));
  2563. let _dP = Object.defineProperty;
  2564. Object.defineProperty = function(...args) {
  2565. if (args[0] instanceof Window && (args[1] === '$' || args[1] === 'jQuery'))
  2566. return void 0;
  2567. return _dP.apply(this, args);
  2568. };
  2569. })
  2570. };
  2571.  
  2572. scripts['igra-prestoloff.cx'] = () => scriptLander(() => {
  2573. let nt = new nullTools();
  2574. /*jslint evil: true */ // yes, evil, I know
  2575. let _write = document.write.bind(document);
  2576. /*jslint evil: false */
  2577. nt.define(document, 'write', t => {
  2578. let id = t.match(/jwplayer\("(\w+)"\)/i);
  2579. if (id && id[1]) {
  2580. return _write(`<div id="${id[1]}"></div>${t}`);
  2581. } else {
  2582. return _write('');
  2583. }
  2584. });
  2585. });
  2586.  
  2587. scripts['imageban.ru'] = {
  2588. now: () => {
  2589. Object.defineProperty(win, 'V7x1J', { get: () => null });
  2590. //preventPopunders();
  2591. }
  2592. };
  2593.  
  2594. scripts['kinopoisk.ru'] = {
  2595. now: () => {
  2596. // set no-branding body style
  2597. createStyle('body:not(#id) { background: #d5d5d5 url(/images/noBrandBg.jpg) 50% 0 no-repeat !important }');
  2598. },
  2599. dom: () => {
  2600. (style => style ? style.parentNode.removeChild(style) : console.log('Unable to locate branding style.')
  2601. )(_de.querySelector('#branding-style'));
  2602. }
  2603. };
  2604.  
  2605. scripts['korrespondent.net'] = {
  2606. now: () => scriptLander(() => {
  2607. let nt = new nullTools();
  2608. nt.define(win, 'holder', function(id) {
  2609. let div = document.getElementById(id);
  2610. if (!div)
  2611. return;
  2612. if (div.parentNode.classList.contains('col__sidebar')) {
  2613. div.parentNode.appendChild(div);
  2614. div.style.height = '300px';
  2615. }
  2616. });
  2617. }, nullTools),
  2618. dom: () => {
  2619. for (let frame of document.querySelectorAll('.unit-side-informer > iframe'))
  2620. frame.parentNode.style.width = '1px';
  2621. }
  2622. };
  2623.  
  2624. scripts['mail.ru'] = () => scriptLander(() => {
  2625. let nt = new nullTools();
  2626. // Trick to prevent mail.ru from removing 3rd-party styles
  2627. nt.define(Object.prototype, 'restoreVisibility', nt.func(null), false);
  2628. // Disable some of their counters
  2629. nt.define(win, 'rb_counter', nt.func(null, 'rb_counter'));
  2630. if (location.hostname !== 'e.mail.ru')
  2631. nt.define(win, 'createRadar', nt.func(nt.func(null, 'aRadar'), 'createRadar'));
  2632. else
  2633. nt.define(win, 'aRadar', nt.func(null, 'aRadar'));
  2634.  
  2635. // Disable page scrambler on mail.ru to let extensions easily block ads there
  2636. function defineLocator(root)
  2637. {
  2638. let _locator;
  2639. let fishnet = {
  2640. apply: (target, thisArg, args) => {
  2641. console.log(`locator.${target._name}(${JSON.stringify(args).slice(1,-1)})`);
  2642. return target.apply(thisArg, args);
  2643. }
  2644. };
  2645.  
  2646. function wrapLocator(locator)
  2647. {
  2648. if ('setup' in locator)
  2649. {
  2650. let _setup = locator.setup;
  2651. locator.setup = function(o)
  2652. {
  2653. if ('enable' in o)
  2654. {
  2655. o.enable = false;
  2656. console.log('Disable mimic mode.');
  2657. }
  2658. if ('links' in o)
  2659. {
  2660. o.links = [];
  2661. console.log('Call with empty list of sheets.');
  2662. }
  2663. return _setup.call(this, o);
  2664. };
  2665. locator.insertSheet = () => console.log('Ignore insertSheet.');
  2666. locator.wrap = () => console.log('Ignore wrap.');
  2667. }
  2668. try {
  2669. let names = [];
  2670. for (let name in locator)
  2671. if (locator[name] instanceof Function) {
  2672. locator[name]._name = name;
  2673. locator[name] = new Proxy(locator[name], fishnet);
  2674. names.push(name);
  2675. }
  2676. console.log(`[locator] wrapped properties: ${names.join(', ')}`);
  2677. } catch(e) {
  2678. console.log(e);
  2679. }
  2680. _locator = locator;
  2681. }
  2682.  
  2683. if ('locator' in root && root.locator)
  2684. {
  2685. console.log('Found existing "locator" object. :|');
  2686. _locator = root.locator;
  2687. wrapLocator(root.locator);
  2688. }
  2689.  
  2690. let loc_desc = Object.getOwnPropertyDescriptor(root, 'locator');
  2691. if (!loc_desc || loc_desc.set !== wrapLocator)
  2692. try {
  2693. Object.defineProperty(root, 'locator', {
  2694. set: wrapLocator,
  2695. get: () => _locator
  2696. });
  2697. } catch (err) {
  2698. console.log('Unable to redefine "locator" object!!!', err);
  2699. }
  2700. }
  2701.  
  2702. function defineDetector(mr)
  2703. {
  2704. let __ = mr._ || {};
  2705.  
  2706. if ('HONEYPOT' in __)
  2707. {
  2708. console.log('Disarming existing detector instance. :|', JSON.stringify(__));
  2709. nt.define(__, 'HONEYPOT', '.honeypot_fake_class_to_miss');
  2710. nt.define(__, 'STUCK_IN_POT', false);
  2711. }
  2712.  
  2713. __ = new Proxy(__, {
  2714. get: (t, p) => t[p],
  2715. set: (t, p, v) => {
  2716. console.log(`mr._.${p} =`, v);
  2717. if (['HONEYPOT', 'STUCK_IN_POT'].includes(p))
  2718. console.log('Not changed.');
  2719. t[p] = v; // setter in nt.define will prevent this when needed
  2720. return true;
  2721. }
  2722. });
  2723. Object.defineProperty(mr, '_', {
  2724. enumerable: true,
  2725. value: __
  2726. });
  2727. }
  2728.  
  2729. if (location.hostname === 'e.mail.ru')
  2730. defineLocator(win);
  2731. else {
  2732. try {
  2733. let _mr;
  2734. Object.defineProperty(win, 'mr', {
  2735. enumerable: true,
  2736. get: () => _mr,
  2737. set: (v) => {
  2738. if (v === _mr)
  2739. return true;
  2740. console.log('Trapped new "mr" object.');
  2741. defineLocator(v.mimic ? v.mimic : v);
  2742. defineDetector(v);
  2743. _mr = v;
  2744. }
  2745. });
  2746. if (!('mr' in win))
  2747. throw 'Wat!?';
  2748. } catch (e) {
  2749. console.log('Found existing "mr" object.', e instanceof TypeError ? '' : e);
  2750. defineLocator(win.mr);
  2751. defineDetector(win.mr);
  2752. }
  2753. }
  2754. }, nullTools);
  2755.  
  2756. scripts['megogo.net'] = {
  2757. now: () => {
  2758. let nt = new nullTools();
  2759. nt.define(win, 'adBlock', false);
  2760. nt.define(win, 'showAdBlockMessage', nt.func(null));
  2761. }
  2762. };
  2763.  
  2764. scripts['naruto-base.su'] = () => gardener('div[id^="entryID"],.block', /href="http.*?target="_blank"/i);
  2765.  
  2766. scripts['overclockers.ru'] = {
  2767. now: () => scriptLander(() => {
  2768. let _innerHTML = Object.getOwnPropertyDescriptor(Element.prototype, 'innerHTML');
  2769. let _set_innerHTML = _innerHTML.set;
  2770. _innerHTML.set = function() {
  2771. if (this === document.body) {
  2772. console.log('Anti-Adblock killed.');
  2773. return true;
  2774. }
  2775. _set_innerHTML.apply(this, arguments);
  2776. };
  2777. Object.defineProperty(Element.prototype, 'innerHTML', _innerHTML);
  2778. })
  2779. };
  2780. scripts['forums.overclockers.ru'] = {
  2781. now: () => {
  2782. createStyle('.needblock {position: fixed; left: -10000px}');
  2783. Object.defineProperty(win, 'adblck', {
  2784. get: () => 'no',
  2785. set: () => undefined,
  2786. enumerable: true
  2787. });
  2788. }
  2789. };
  2790.  
  2791. scripts['pb.wtf'] = {
  2792. other: ['piratbit.org', 'piratbit.ru'],
  2793. now: () => {
  2794. // line above topic content and images in the slider in the header
  2795. gardener(
  2796. 'a[href^="/exit/"], a[href^="/fxt/"], a[href$="=="]',
  2797. /img|Реклама|center/i,
  2798. { root: '.release-navbar,#page_content', observe: true, parent: 'div,tr' }
  2799. );
  2800. // ads in comments
  2801. gardener('img[data-name="PiraBo"]', /./i, {root:'#main_content .table', observe:true, parent:'tr'});
  2802. }
  2803. };
  2804.  
  2805. scripts['pikabu.ru'] = () => gardener('.story', /story__author[^>]+>ads</i, {root: '.inner_wrap', observe: true});
  2806.  
  2807. scripts['peka2.tv'] = () => {
  2808. let bodyClass = 'body--branding';
  2809. let checkNode = node => {
  2810. for (let className of node.classList)
  2811. if (className.includes('banner') || className === bodyClass) {
  2812. _removeAttribute.call(node, 'style');
  2813. node.classList.remove(className);
  2814. for (let attr of Array.from(node.attributes)) {
  2815. if (attr.name.startsWith('advert'))
  2816. _removeAttribute.call(node, attr.name);
  2817. }
  2818. }
  2819. };
  2820. (new MutationObserver(ms => {
  2821. let m, node;
  2822. for (m of ms) for (node of m.addedNodes)
  2823. if (node instanceof HTMLElement)
  2824. checkNode(node);
  2825. })).observe(_de, {childList: true, subtree: true});
  2826. (new MutationObserver(ms => {
  2827. for (let m of ms)
  2828. checkNode(m.target);
  2829. })).observe(_de, {attributes: true, subtree: true, attributeFilter: ['class']});
  2830. };
  2831.  
  2832. scripts['qrz.ru'] = {
  2833. now: () => {
  2834. let nt = new nullTools();
  2835. nt.define(win, 'ab', false);
  2836. nt.define(win, 'tryMessage', nt.func(null));
  2837. }
  2838. };
  2839.  
  2840. scripts['razlozhi.ru'] = {
  2841. now: () => {
  2842. for (let func of ['createShadowRoot', 'attachShadow'])
  2843. if (func in Element.prototype)
  2844. Element.prototype[func] = function(){ return this.cloneNode(); };
  2845. }
  2846. };
  2847.  
  2848. scripts['rbc.ru'] = {
  2849. dom: () => {
  2850. let _preventDefault = Event.prototype.preventDefault;
  2851. Event.prototype.preventDefault = function preventDefault()
  2852. {
  2853. let t = this.target;
  2854. if (t instanceof HTMLAnchorElement || t.closest('A'))
  2855. throw new Error('an.yandex redirect prevention');
  2856. return _preventDefault.call(this);
  2857. };
  2858.  
  2859. function cleaner(nodes)
  2860. {
  2861. for (let node of nodes)
  2862. {
  2863. if (!node.classList || !node.classList.contains('js-yandex-counter'))
  2864. continue;
  2865. node.classList.remove('js-yandex-counter');
  2866. node.removeAttribute('data-yandex-name');
  2867. node.removeAttribute('data-yandex-params');
  2868. }
  2869. }
  2870. cleaner(_de.querySelectorAll('.js-yandex-counter'));
  2871.  
  2872. (new MutationObserver(
  2873. ms => { for (let m of ms) cleaner(m.addedNodes); }
  2874. )).observe(_de, {childList: true, subtree: true});
  2875. }
  2876. };
  2877.  
  2878. scripts['rp5.ru'] = {
  2879. other: ['rp5.by', 'rp5.kz', 'rp5.ua'],
  2880. now: () => gardener('div[id][class]', /\?AdvertMgmt=|adsbygoogle/, { root: '#content-wrapper', log: true })
  2881. };
  2882.  
  2883. scripts['rutube.ru'] = () => scriptLander(() => {
  2884. let _parse = JSON.parse.bind(JSON);
  2885. let _skip_enabled = false;
  2886. JSON.parse = (...args) => {
  2887. let res = _parse(...args),
  2888. log = false;
  2889. if (!res)
  2890. return res;
  2891. // parse player configuration
  2892. if ('appearance' in res || 'video_balancer' in res) {
  2893. log = true;
  2894. if ('appearance' in res) {
  2895. res.appearance.forbid_seek = false;
  2896. res.appearance.forbid_timeline_preview = false;
  2897. }
  2898. _skip_enabled = !!res.remove_unseekable_blocks;
  2899. res.advert = [];
  2900. for (let limit of res.limits)
  2901. limit.limit = 0;
  2902. res.yast = null;
  2903. res.yast_live_online = null;
  2904. Object.defineProperty(res, 'stat', {
  2905. get: x => [],
  2906. set: x => true,
  2907. enumerable: true
  2908. });
  2909. }
  2910.  
  2911. // parse video configuration
  2912. if ('video_url' in res) {
  2913. log = true;
  2914. if ('cuepoints' in res && !_skip_enabled)
  2915. for (let point of res.cuepoints) {
  2916. point.is_pause = false;
  2917. point.show_navigation = true;
  2918. point.forbid_seek = false;
  2919. }
  2920. }
  2921.  
  2922. if (log)
  2923. console.log('[rutube]', res);
  2924. return res;
  2925. };
  2926. });
  2927.  
  2928. scripts['simpsonsua.com.ua'] = () => scriptLander(() => {
  2929. let _addEventListener = Object.getPrototypeOf(HTMLDocument).prototype.addEventListener;
  2930. document.addEventListener = function(event, callback) {
  2931. if (event === 'DOMContentLoaded' && callback.toString().includes('show_warning'))
  2932. return;
  2933. return _addEventListener.apply(this, arguments);
  2934. };
  2935. });
  2936.  
  2937. scripts['spaces.ru'] = () => {
  2938. gardener('div:not(.f-c_fll) > a[href*="spaces.ru/?Cl="]', /./, { parent: 'div' });
  2939. gardener('.js-banner_rotator', /./, { parent: '.widgets-group' });
  2940. };
  2941.  
  2942. scripts['spam-club.blogspot.co.uk'] = () => {
  2943. let _clientHeight = Object.getOwnPropertyDescriptor(Element.prototype, 'clientHeight'),
  2944. _clientWidth = Object.getOwnPropertyDescriptor(Element.prototype, 'clientWidth');
  2945. let wrapGetter = (getter) => {
  2946. let _getter = getter;
  2947. return function()
  2948. {
  2949. let _size = _getter.apply(this, arguments);
  2950. return _size ? _size : 1;
  2951. };
  2952. };
  2953. _clientHeight.get = wrapGetter(_clientHeight.get);
  2954. _clientWidth.get = wrapGetter(_clientWidth.get);
  2955. Object.defineProperty(Element.prototype, 'clientHeight', _clientHeight);
  2956. Object.defineProperty(Element.prototype, 'clientWidth', _clientWidth);
  2957. let _onload = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'onload'),
  2958. _set_onload = _onload.set;
  2959. _onload.set = function()
  2960. {
  2961. if (this instanceof HTMLImageElement)
  2962. return true;
  2963. _set_onload.apply(this, arguments);
  2964. };
  2965. Object.defineProperty(HTMLElement.prototype, 'onload', _onload);
  2966. };
  2967.  
  2968. scripts['sport-express.ru'] = () => gardener('.js-relap__item',/>Реклама\s+<\//, {root:'.container', observe: true});
  2969.  
  2970. scripts['sports.ru'] = {
  2971. now: () => {
  2972. gardener('.aside-news-list__item', /aside-news-list__advert/i, {root:'.columns-layout__left', observe: true});
  2973. gardener('.material-list__item', /Реклама/i, {root:'.columns-layout', observe: true});
  2974. // extra functionality: shows/hides panel at the top depending on scroll direction
  2975. createStyle([
  2976. '.user-panel__fixed { transition: top 0.2s ease-in-out!important; }',
  2977. '.user-panel-up { top: -40px!important }'
  2978. ], {id: 'userPanelSlide'}, false);
  2979. },
  2980. dom: () => {
  2981. (function lookForPanel()
  2982. {
  2983. let panel = document.querySelector('.user-panel__fixed');
  2984. if (!panel)
  2985. setTimeout(lookForPanel, 100);
  2986. else
  2987. window.addEventListener(
  2988. 'wheel', function(e)
  2989. {
  2990. if (e.deltaY > 0 && !panel.classList.contains('user-panel-up'))
  2991. panel.classList.add('user-panel-up');
  2992. else if (e.deltaY < 0 && panel.classList.contains('user-panel-up'))
  2993. panel.classList.remove('user-panel-up');
  2994. }, false
  2995. );
  2996. })();
  2997. }
  2998. };
  2999.  
  3000. scripts['stealthz.ru'] = {
  3001. dom: () => {
  3002. // skip timeout
  3003. let $ = document.querySelector.bind(document);
  3004. let [timer_1, timer_2] = [$('#timer_1'), $('#timer_2')];
  3005. if (!timer_1 || !timer_2)
  3006. return;
  3007. timer_1.style.display = 'none';
  3008. timer_2.style.display = 'block';
  3009. }
  3010. };
  3011.  
  3012. scripts['yap.ru'] = {
  3013. other: ['yaplakal.com'],
  3014. now: () => {
  3015. gardener('form > table[id^="p_row_"]:nth-of-type(2)', /member1438|Administration/);
  3016. gardener('.icon-comments', /member1438|Administration|\/go\/\?http/, {parent:'tr', siblings:-2});
  3017. }
  3018. };
  3019.  
  3020. scripts['rambler.ru'] = {
  3021. other: ['championat.com','gazeta.ru','media.eagleplatform.com','lenta.ru', 'quto.ru'],
  3022. now: () => scriptLander(() => {
  3023. // Prevent autoplay
  3024. if (!('EaglePlayer' in win)) {
  3025. let _EaglePlayer = void 0;
  3026. Object.defineProperty(win, 'EaglePlayer', {
  3027. enumerable: true,
  3028. get: x => _EaglePlayer,
  3029. set: x => {
  3030. if (x === _EaglePlayer)
  3031. return true;
  3032. _EaglePlayer = x;
  3033. let _init = void 0;
  3034. Object.defineProperty(_EaglePlayer.prototype, 'init', {
  3035. enumerable: true,
  3036. set: x => _init = x,
  3037. get: function() {
  3038. let _self = this;
  3039. if (_self.options) {
  3040. Object.defineProperty(this.options, 'autoplay', {
  3041. enumerable: true,
  3042. get: x => false,
  3043. set: x => null
  3044. });
  3045. }
  3046. if (_self.options && _self.options.el && inIFrame) {
  3047. let addListener = (player) => {
  3048. console.log('Attached autostop');
  3049. player.addEventListener('canplay', e => {
  3050. e.target.play = () => console.log('Applied autostop.');
  3051. setTimeout(player => {
  3052. delete player.play;
  3053. console.log('Detached autostop');
  3054. }, 1500, e.target);
  3055. }, false);
  3056. };
  3057. (new MutationObserver(ms => {
  3058. let m, node;
  3059. for (m of ms) for (node of m.addedNodes)
  3060. if (node instanceof HTMLVideoElement)
  3061. addListener(node);
  3062. })).observe(this.options.el, { childList: true, subtree: true });
  3063. }
  3064. return _init;
  3065. }
  3066. });
  3067. }
  3068. });
  3069. let _setAttribute = Element.prototype.setAttribute;
  3070. let isAutoplay = /^autoplay$/i;
  3071. Element.prototype.setAttribute = function setAttribute(name)
  3072. {
  3073. if (!this._stopped && isAutoplay.test(name))
  3074. {
  3075. console.log('Prevented assigning autoplay attribute.');
  3076. return null;
  3077. }
  3078. return _setAttribute.apply(this, arguments);
  3079. };
  3080. } else if (inIFrame) {
  3081. let _setAttribute = Element.prototype.setAttribute;
  3082. let isAutoplay = /^autoplay$/i;
  3083. Element.prototype.setAttribute = function setAttribute(name)
  3084. {
  3085. if (!this._stopped && isAutoplay.test(name))
  3086. {
  3087. console.log('Prevented assigning autoplay attribute.');
  3088. this._stopped = true;
  3089. this.play = () => {
  3090. console.log('Prevented attempt to force-start playback.');
  3091. delete this.play;
  3092. };
  3093. return null;
  3094. }
  3095. return _setAttribute.apply(this, arguments);
  3096. };
  3097. }
  3098. if (location.hostname.endsWith('.media.eagleplatform.com'))
  3099. return;
  3100. let CSSRuleProto = 'cssText' in CSSRule.prototype ? CSSRule.prototype : CSSStyleRule.prototype;
  3101. let _cssText = Object.getOwnPropertyDescriptor(CSSRuleProto, 'cssText');
  3102. let _cssText_get = _cssText.get;
  3103. _cssText.configurable = false;
  3104. _cssText.get = function()
  3105. {
  3106. let cssText = _cssText_get.call(this);
  3107. if (cssText.includes('content:'))
  3108. {
  3109. console.log('Blocked access to suspicious cssText:', cssText.slice(0,60), '\u2026', cssText.length);
  3110. return null;
  3111. }
  3112. return cssText;
  3113. };
  3114. Object.defineProperty(CSSRuleProto, 'cssText', _cssText);
  3115. // fake global Adf object
  3116. let nt = new nullTools();
  3117. let Adf_banner = {};
  3118. [
  3119. 'reloadssp', 'sspScroll',
  3120. 'sspRich', 'ssp'
  3121. ].forEach(name => Adf_banner[name] = nt.proxy(() => new Promise((r,j) => r({status: true}))));
  3122. nt.define(win, 'Adf', nt.proxy({
  3123. banner: nt.proxy(Adf_banner)
  3124. }));
  3125. // extra script to remove partner news on gazeta.ru
  3126. if (!location.hostname.includes('gazeta.ru'))
  3127. return;
  3128. (new MutationObserver(
  3129. (ms) => {
  3130. let m, node, header;
  3131. for (m of ms) for (node of m.addedNodes)
  3132. if (node instanceof HTMLDivElement && node.matches('.sausage'))
  3133. {
  3134. header = node.querySelector('.sausage-header');
  3135. if (header && /новости\s+партн[её]ров/i.test(header.textContent))
  3136. node.style.display = 'none';
  3137. }
  3138. }
  3139. )).observe(document.documentElement, { childList:true, subtree: true });
  3140. }, `let inIFrame = ${inIFrame}`, nullTools)
  3141. };
  3142.  
  3143. scripts['reactor.cc'] = {
  3144. other: ['joyreactor.cc', 'pornreactor.cc'],
  3145. now: () => {
  3146. selectiveEval();
  3147. scriptLander(() => {
  3148. let nt = new nullTools();
  3149. win.open = (function(){ throw new Error('Redirect prevention.'); }).bind(window);
  3150. nt.define(win, 'Worker', function(){});
  3151. nt.define(win, 'JRCH', win.CoinHive);
  3152. }, nullTools);
  3153. },
  3154. click: function(e)
  3155. {
  3156. let node = e.target;
  3157. if (node.nodeType === _Node.ELEMENT_NODE &&
  3158. node.style.position === 'absolute' &&
  3159. node.style.zIndex > 0)
  3160. node.parentNode.removeChild(node);
  3161. },
  3162. dom: function()
  3163. {
  3164. let words = new RegExp(
  3165. 'блокировщик рекламы'
  3166. .split('')
  3167. .map(function(e){return e+'[\u200b\u200c\u200d]*';})
  3168. .join('')
  3169. .replace(' ', '\\s*')
  3170. .replace(/[аоре]/g, function(e){return ['[аa]','[оo]','[рp]','[еe]']['аоре'.indexOf(e)];}),
  3171. 'i'),
  3172. can;
  3173. function deeper(spider)
  3174. {
  3175. let c, l, n;
  3176. if (words.test(spider.innerText))
  3177. {
  3178. if (spider.nodeType === _Node.TEXT_NODE)
  3179. return true;
  3180. c = spider.childNodes;
  3181. l = c.length;
  3182. n = 0;
  3183. while(l--)
  3184. if (deeper(c[l]), can)
  3185. n++;
  3186. if (n > 0 && n === c.length && spider.offsetHeight < 750)
  3187. can.push(spider);
  3188. return false;
  3189. }
  3190. return true;
  3191. }
  3192. function probe()
  3193. {
  3194. if (words.test(document.body.innerText))
  3195. {
  3196. can = [];
  3197. deeper(document.body);
  3198. let i = can.length, spider;
  3199. while(i--) {
  3200. spider = can[i];
  3201. if (spider.offsetHeight > 10 && spider.offsetHeight < 750)
  3202. _setAttribute.call(spider, 'style', 'background:none!important');
  3203. }
  3204. }
  3205. }
  3206. (new MutationObserver(probe))
  3207. .observe(document, { childList:true, subtree:true });
  3208. }
  3209. };
  3210.  
  3211. scripts['auto.ru'] = () => {
  3212. let words = /Реклама|Яндекс.Директ|yandex_ad_/;
  3213. let userAdsListAds = (
  3214. '.listing-list > .listing-item,'+
  3215. '.listing-item_type_fixed.listing-item'
  3216. );
  3217. let catalogAds = (
  3218. 'div[class*="layout_catalog-inline"],'+
  3219. 'div[class$="layout_horizontal"]'
  3220. );
  3221. let otherAds = (
  3222. '.advt_auto,'+
  3223. '.sidebar-block,'+
  3224. '.pager-listing + div[class],'+
  3225. '.card > div[class][style],'+
  3226. '.sidebar > div[class],'+
  3227. '.main-page__section + div[class],'+
  3228. '.listing > tbody'
  3229. );
  3230. gardener(userAdsListAds, words, {root:'.listing-wrap', observe:true});
  3231. gardener(catalogAds, words, {root:'.catalog__page,.content__wrapper', observe:true});
  3232. gardener(otherAds, words);
  3233. };
  3234.  
  3235. scripts['rsload.net'] = {
  3236. load: () => {
  3237. let dis = document.querySelector('label[class*="cb-disable"]');
  3238. if (dis)
  3239. dis.click();
  3240. },
  3241. click: () => {
  3242. let t = e.target;
  3243. if (t && t.href && (/:\/\/\d+\.\d+\.\d+\.\d+\//.test(t.href)))
  3244. t.href = t.href.replace('://','://rsload.net:rsload.net@');
  3245. }
  3246. };
  3247.  
  3248. let domain;
  3249. // add alternative domain names if present and wrap functions into objects
  3250. for (let name in scripts)
  3251. {
  3252. if (scripts[name] instanceof Function)
  3253. scripts[name] = { now: scripts[name] };
  3254. for (domain of (scripts[name].other||[]))
  3255. {
  3256. if (domain in scripts)
  3257. console.log('Error in scripts list. Script for', name, 'replaced script for', domain);
  3258. scripts[domain] = scripts[name];
  3259. }
  3260. delete scripts[name].other;
  3261. }
  3262. // look for current domain in the list and run appropriate code
  3263. domain = document.domain;
  3264. while (domain.indexOf('.') > -1)
  3265. {
  3266. if (domain in scripts) for (let when in scripts[domain])
  3267. switch(when)
  3268. {
  3269. case 'now':
  3270. scripts[domain][when]();
  3271. break;
  3272. case 'dom':
  3273. document.addEventListener('DOMContentLoaded', scripts[domain][when], false);
  3274. break;
  3275. default:
  3276. document.addEventListener (when, scripts[domain][when], false);
  3277. }
  3278. domain = domain.slice(domain.indexOf('.') + 1);
  3279. }
  3280.  
  3281. // Batch script lander
  3282. if (!skipLander)
  3283. landScript(batchLand, batchPrepend);
  3284.  
  3285. { // JS Fixes Tools Menu
  3286. let openOptions = function()
  3287. {
  3288. let ovl = _createElement('div'),
  3289. inner = _createElement('div');
  3290. ovl.style = (
  3291. 'position: fixed;'+
  3292. 'top:0; left:0;'+
  3293. 'bottom: 0; right: 0;'+
  3294. 'background: rgba(0,0,0,0.85);'+
  3295. 'z-index: 2147483647;'+
  3296. 'padding: 5em'
  3297. );
  3298. inner.style = (
  3299. 'background: whitesmoke;'+
  3300. 'font-size: 10pt;'+
  3301. 'color: black;'+
  3302. 'padding: 1em'
  3303. );
  3304. inner.textContent = 'JS Fixes Tools';
  3305. inner.appendChild(_createElement('br'));
  3306. inner.appendChild(_createElement('br'));
  3307. ovl.addEventListener(
  3308. 'click', function(e)
  3309. {
  3310. if (e.target === ovl) {
  3311. ovl.parentNode.removeChild(ovl);
  3312. e.preventDefault();
  3313. }
  3314. e.stopPropagation();
  3315. }, false
  3316. );
  3317.  
  3318. let sObjBtn = _createElement('button');
  3319. sObjBtn.onclick = getStrangeObjectsList;
  3320. sObjBtn.textContent = 'Print (in console) list of unusual window properties';
  3321. inner.appendChild(_createElement('br'));
  3322. inner.appendChild(sObjBtn);
  3323.  
  3324. document.body.appendChild(ovl);
  3325. ovl.appendChild(inner);
  3326. };
  3327.  
  3328. // monitor keys pressed for Ctrl+Alt+Shift+J > s > f code
  3329. let opPos = 0, opKey = ['KeyJ','KeyS','KeyF'];
  3330. document.addEventListener(
  3331. 'keydown', function(e)
  3332. {
  3333. if ((e.code === opKey[opPos] || e.location) &&
  3334. (!!opPos || e.altKey && e.ctrlKey && e.shiftKey))
  3335. {
  3336. opPos += e.location ? 0 : 1;
  3337. e.stopPropagation();
  3338. e.preventDefault();
  3339. } else {
  3340. opPos = 0;
  3341. }
  3342. if (opPos === opKey.length)
  3343. {
  3344. opPos = 0;
  3345. openOptions();
  3346. }
  3347. }, false
  3348. );
  3349. }
  3350. })();

QingJ © 2025

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