RU AdList JS Fixes

try to take over the world!

当前为 2018-08-14 提交的版本,查看 最新版本

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

QingJ © 2025

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