RU AdList JS Fixes

try to take over the world!

当前为 2018-05-12 提交的版本,查看 最新版本

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

QingJ © 2025

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