RU AdList JS Fixes

try to take over the world!

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

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