RU AdList JS Fixes

try to take over the world!

目前為 2018-04-13 提交的版本,檢視 最新版本

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