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.0
  5. // @description try to take over the world!
  6. // @author lainverse & dimisa
  7. // @supportURL https://greasyfork.org/en/scripts/19993-ru-adlist-js-fixes/feedback
  8. // @match *://*/*
  9. // @exclude *://auth.wi-fi.ru/*
  10. // @exclude *://*.alfabank.ru/*
  11. // @exclude *://alfabank.ru/*
  12. // @exclude *://*.unicreditbanking.net/*
  13. // @exclude *://unicreditbanking.net/*
  14. // @exclude *://*.telegram.org/*
  15. // @exclude *://telegram.org/*
  16. // @grant unsafeWindow
  17. // @grant window.close
  18. // @run-at document-start
  19. // ==/UserScript==
  20.  
  21. (function() {
  22. 'use strict';
  23.  
  24. let win = (unsafeWindow || window);
  25.  
  26. // MooTools are crazy enough to replace standard browser object window.Document: https://mootools.net/core
  27. // Occasionally their code runs before my script on some domains and causes all kinds of havoc.
  28. let _Document = Object.getPrototypeOf(HTMLDocument);
  29. let _Element = Object.getPrototypeOf(HTMLElement);
  30. // dTree 2.05 in some cases replaces Node object
  31. let _Node = Object.getPrototypeOf(_Element);
  32.  
  33. // http://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser
  34. let isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0,
  35. isChrome = !!window.chrome && !!window.chrome.webstore,
  36. isSafari = (Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0 ||
  37. (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window.safari || safari.pushNotification)),
  38. isFirefox = 'InstallTrigger' in win,
  39. ifFirefoxUnder58 = isFirefox && 'StopIteration' in win,
  40. inIFrame = (win.self !== win.top),
  41. _getAttribute = _Element.prototype.getAttribute,
  42. _setAttribute = _Element.prototype.setAttribute,
  43. _removeAttribute = _Element.prototype.removeAttribute,
  44. _de = document.documentElement,
  45. _appendChild = _Document.prototype.appendChild.bind(_de),
  46. _removeChild = _Document.prototype.removeChild.bind(_de),
  47. _createElement = _Document.prototype.createElement.bind(document);
  48.  
  49. if (isFirefox && // Exit on image pages in Fx
  50. document.constructor.prototype.toString() === '[object ImageDocumentPrototype]')
  51. return;
  52.  
  53. // NodeList iterator polyfill (mostly for Safari)
  54. // https://jakearchibald.com/2014/iterators-gonna-iterate/
  55. if (!NodeList.prototype[Symbol.iterator])
  56. NodeList.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
  57.  
  58. // Wrapper to run scripts designed to override objects available to other scripts
  59. // Required in old versions of Firefox (<58) or when running with Greasemonkey
  60. let skipLander = true;
  61. try {
  62. skipLander = !(ifFirefoxUnder58 || (isFirefox && GM.info.scriptHandler === 'Greasemonkey'));
  63. } catch(ignore){}
  64. let batchLand = [];
  65. let batchPrepend = [];
  66. let _APIString = 'let win = window, _Document = Object.getPrototypeOf(HTMLDocument), _Element = Object.getPrototypeOf(HTMLElement), _Node = Object.getPrototypeOf(_Element);';
  67. let landScript = (f, pre) => {
  68. let script = _createElement('script');
  69. script.textContent = `(()=>{${_APIString}${(
  70. (pre.length > 0 ? pre.join(';') : '')
  71. )};(${f.join(')();(')})();})();`;
  72. _appendChild(script);
  73. _removeChild(script);
  74. };
  75. let scriptLander = f => f();
  76. if (!skipLander) {
  77. scriptLander = (func, ...prepend) => {
  78. prepend.forEach(
  79. x => batchPrepend.includes(x) ? null : batchPrepend.push(x)
  80. );
  81. batchLand.push(func);
  82. };
  83. document.addEventListener(
  84. 'DOMContentLoaded', ignore => scriptLander = (f, ...prep) => landScript([f], prep), false
  85. );
  86. }
  87.  
  88. function nullTools(opts) {
  89. // jshint validthis:true
  90. let nt = this;
  91. opts = opts || {};
  92. let log = (...args) => opts.log ? console.log(...args) : null;
  93. let warn = (...args) => console.warn(...args);
  94. let trace = (...args) => (opts.log || opts.trace) ? warn(...arguments) : null;
  95.  
  96. nt.destroy = function(o, destroy)
  97. {
  98. if (!opts.destroy && !destroy && o instanceof Object)
  99. return;
  100. log('cleaning', o);
  101. try {
  102. for (let item in o)
  103. {
  104. if (item instanceof Object)
  105. nt.destroy(item);
  106. delete o[item];
  107. }
  108. } catch (e) {
  109. log('Error in object destructor', e);
  110. }
  111. };
  112.  
  113. nt.define = function(obj, prop, val, enumerable = true)
  114. {
  115. try {
  116. Object.defineProperty(
  117. obj, prop, {
  118. get: () => val,
  119. set: (v) => (v !== val ? (log(`set ${prop} of`, obj, 'to', v), nt.destroy(v)) : null, undefined),
  120. enumerable: enumerable
  121. }
  122. );
  123. } catch (err) {
  124. console.log(`Unable to redefine "${prop}" in `, obj, err);
  125. }
  126. };
  127. nt.proxy = function(obj)
  128. {
  129. return new Proxy(
  130. obj, {
  131. get: (t, p) => p in t ? t[p] : console.warn(`Missing ${p} in`, t),
  132. set: (t, p, v) => (v !== t[p] ? (log(`set ${p} of`, t, 'to', v), nt.destroy(v)) : null, true)
  133. }
  134. );
  135. };
  136. nt.func = (val, name = '', force_log = false) => (...args) => ((force_log ? warn : trace)(`call ${name}(`, ...args,`) return`, val), val);
  137. }
  138.  
  139. // Debug function, lists all unusual window properties
  140. function getStrangeObjectsList()
  141. {
  142. console.warn('Strangers list start');
  143. let _ts = Function.prototype.toString;
  144. let _skip = 'frames/self/window/webkitStorageInfo'.split('/');
  145. for (let n in win) {
  146. let val = win[n];
  147. if (val && !_skip.includes(n) && (win !== window && val !== window[n] || win === window) &&
  148. (!(val instanceof Function) ||
  149. val instanceof Function &&
  150. !(new RegExp (`^function\\s(${n})?\\(\\)[\\s\\r\\n]*\\{[\\s\\r\\n]*\\[native\\scode\\][\\s\\r\\n]*\\}$`)).test(_ts.call(val))))
  151. console.log(`${n} =`, val);
  152. }
  153. console.warn('Strangers list end');
  154. }
  155.  
  156. // Fake objects of advertisement networks to break their workflow
  157. scriptLander(
  158. function()
  159. {
  160. let nt = new nullTools();
  161. // Popular adblock detector
  162. if (!('fuckAdBlock' in win))
  163. {
  164. let FuckAdBlock = function(options) {
  165. let self = this;
  166. self._options = {
  167. checkOnLoad: false,
  168. resetOnEnd: false,
  169. checking: false
  170. };
  171. self.setOption = function(opt, val)
  172. {
  173. if (val)
  174. self._options[opt] = val;
  175. else
  176. Object.assign(self._options, opt);
  177. };
  178. if (options)
  179. self.setOption(options);
  180.  
  181. self._var = { event: {} };
  182. self.clearEvent = function()
  183. {
  184. self._var.event.detected = [];
  185. self._var.event.notDetected = [];
  186. };
  187. self.clearEvent();
  188.  
  189. self.on = function(detected, fun)
  190. {
  191. self._var.event[detected?'detected':'notDetected'].push(fun);
  192. return self;
  193. };
  194. self.onDetected = function(cb)
  195. {
  196. return self.on(true, cb);
  197. };
  198. self.onNotDetected = function(cb)
  199. {
  200. return self.on(false, cb);
  201. };
  202. self.emitEvent = function()
  203. {
  204. for (let fun of self._var.event.notDetected)
  205. fun();
  206. if (self._options.resetOnEnd)
  207. self.clearEvent();
  208. return self;
  209. };
  210. self._creatBait = () => null;
  211. self._destroyBait = () => null;
  212. self._checkBait = function() {
  213. setTimeout((() => self.emitEvent()), 1);
  214. };
  215. self.check = function() {
  216. self._checkBait();
  217. return true;
  218. };
  219.  
  220. let callback = function()
  221. {
  222. if (self._options.checkOnLoad)
  223. setTimeout(self.check, 1);
  224. };
  225. window.addEventListener('load', callback, false);
  226. };
  227. nt.define(win, 'FuckAdBlock', FuckAdBlock);
  228. nt.define(win, 'fuckAdBlock', new FuckAdBlock({
  229. checkOnLoad: true,
  230. resetOnEnd: true
  231. }));
  232. }
  233.  
  234. // CoinHive miner stub. Continuous 100% CPU load can easily kill some CPU with overheat.
  235. if (!('CoinHive' in win))
  236. {
  237. if (location.hostname !== 'cnhv.co')
  238. {
  239. // CoinHive stub for cases when it doesn't affect site functionality
  240. let CoinHiveConstructor = function()
  241. {
  242. console.warn('Fake CoinHive miner created.');
  243. this.setThrottle = nt.func(null);
  244. this.start = nt.func(null);
  245. this.on = nt.func(null);
  246. this.getTotalHashes = nt.func(0);
  247. };
  248. let CoinHiveStub = nt.proxy({
  249. Anonymous: CoinHiveConstructor,
  250. User: CoinHiveConstructor,
  251. Token: CoinHiveConstructor,
  252. JobThread: nt.func(null),
  253. IF_EXCLUSIVE_TAB: false
  254. });
  255. nt.define(win, 'CoinHive', CoinHiveStub);
  256. } else {
  257. // CoinHive wrapper to fool sites which expect it to actually work and return results
  258. let CoinHiveObject;
  259. let fishnet = {
  260. apply: (target, thisArg, args) => {
  261. console.log(`miner.${target._name}(${JSON.stringify(args).slice(1,-1)})`);
  262. return target.apply(thisArg, args);
  263. }
  264. };
  265. Object.defineProperty(win, 'CoinHive', {
  266. set: function(obj)
  267. {
  268. if ('Token' in obj)
  269. {
  270. console.log('[CoinHive] Token wrapper applied.');
  271. let _Token = obj.Token.bind(obj);
  272. obj.Token = function(siteKey, goal, params)
  273. {
  274. let _goal = goal;
  275. if (goal > 256)
  276. goal = 256;
  277. console.log(`[CoinHive] Original goal: ${_goal}, new smaller goal ${goal}.`);
  278. console.log(`With smaller goals server may return 'invalid_goal' error and stop working.`);
  279. let miner = _Token(siteKey, goal, params);
  280. miner.setThrottle(0.99);
  281. miner.setThrottle = () => null;
  282. let _start = miner.start.bind(miner);
  283. miner.start = function() {
  284. let res = _start(CoinHive.FORCE_EXCLUSIVE_TAB);
  285. return res;
  286. };
  287. let _getTotalHashes = miner.getTotalHashes;
  288. miner.getTotalHashes = function()
  289. {
  290. return Math.trunc(_getTotalHashes.call(this) / goal * _goal);
  291. };
  292. let __emit = miner._emit;
  293. miner._emit = function(state, props)
  294. {
  295. let _self = this;
  296. console.log('[CoinHive] state:', state, props);
  297. if (state === 'job')
  298. setTimeout(() => {
  299. _self.stop();
  300. _self._emit('accepted', { hashes: goal });
  301. }, 1000);
  302. return __emit.apply(_self, arguments);
  303. };
  304. let _on = miner.on.bind(miner);
  305. miner.on = function(type, callback)
  306. {
  307. if (type === 'accepted')
  308. {
  309. console.log('[CoinHive] "accepted" callback wrapper applied.');
  310. let _callback = callback;
  311. callback = function(params)
  312. {
  313. console.log('[CoinHive] "accepted" callback is called, imitating original goal being reached.');
  314. params.hashes = _goal;
  315. return _callback.apply(this, arguments);
  316. };
  317. miner.stop();
  318. }
  319. return _on(type, callback);
  320. };
  321. return miner;
  322. };
  323. }
  324. CoinHiveObject = obj;
  325. },
  326. get: () => CoinHiveObject
  327. });
  328. }
  329. }
  330.  
  331. // VideoJS player wrapper
  332. VideoJS: {
  333. let _videojs = win.videojs || void 0;
  334. Object.defineProperty(win, 'videojs', {
  335. get: x => _videojs,
  336. set: f => {
  337. if (f === _videojs)
  338. return true;
  339. console.log('videojs =', f);
  340. _videojs = new Proxy(f, {
  341. apply: (tgt, ths, args) => {
  342. console.log('videojs(', ...args, ')');
  343. let params = args[1];
  344. if (params) {
  345. if (params.hasAd)
  346. params.hasAd = false;
  347. if (params.plugins && params.plugins.vastClient)
  348. delete params.plugins.vastClient;
  349. }
  350. let res = tgt.apply(ths, args);
  351. console.log('player = ', res);
  352. return res;
  353. }
  354. });
  355. }
  356. });
  357. }
  358.  
  359. // piguiqproxy-like script loaded from random RU domains
  360. let fab_application_define = nt.func(null, 'fab_application.define', true);
  361. fab_application_define.amd = nt.func(null, 'fab_application.define.amd');
  362. let fab_application = {
  363. requirejs: nt.proxy(nt.func(null, 'fab_application.requirejs')),
  364. require: nt.proxy(nt.func(null, 'fab_application.require')),
  365. define: nt.proxy(fab_application_define)
  366. };
  367. nt.define(win, 'fab_application', nt.proxy(fab_application));
  368. // less aggressive wrapper for 'fab_application' in case it'll
  369. /*
  370. let fab_application = void 0;
  371. let fab_define_as_null = ['helpers/detecter', 'text!templates/bn_image.tpl', 'text!templates/yandex.tpl'];
  372. Object.defineProperty(win, 'fab_application', {
  373. enumerable: true,
  374. get: x => fab_application,
  375. set: o => {
  376. fab_application = new Proxy(o, {
  377. get: (t, p) => t[p],
  378. set: (t, p, v) => {
  379. if (p === 'define')
  380. v = new Proxy(v, {
  381. apply: (t, ths, args) => {
  382. if (fab_define_as_null.includes(args[0])) {
  383. let null_module = {};
  384. ['on', 'check'].forEach(name => null_module[name] = () => null);
  385. console.warn(`[fab_application] Define '${args[0]}' with custom code instead of`, args[2]);
  386. if (args[0] === 'helpers/detecter')
  387. args[2] = () => ({ on: () => null, check: () => null });
  388. else
  389. args[2] = () => '';
  390. } else {
  391. console.log(`[fab_application] Define '${args[0]}'`);
  392. }
  393. return t.apply(ths, args);
  394. }
  395. });
  396. t[p] = v;
  397. return true;
  398. }
  399. });
  400. return true;
  401. }
  402. });
  403. */
  404.  
  405. // Yandex API (ADBTools, Metrika)
  406. let hostname = location.hostname;
  407. if (location.protocol === 'about:' ||
  408. // Thank you, Greasemonkey, now I have to check for this. -_-
  409. hostname.startsWith('google.') || hostname.includes('.google.') ||
  410. // Google likes to define odd global variables like Ya
  411. ((hostname.startsWith('yandex.') || hostname.includes('.yandex.')) &&
  412. /^\/((yand)?search|images)/i.test(location.pathname) &&
  413. !hostname.startsWith('news.')) ||
  414. // Also, Yandex uses their Ya object for a lot of things on their pages and
  415. // wrapping it may cause problems. It's better to skip it in some cases.
  416. hostname.endsWith('chatango.com') || hostname.endsWith('github.io') ||
  417. hostname.endsWith('grimtools.com'))
  418. return;
  419.  
  420. let YaProps = new Set();
  421. function onAdvManager (Ya, rootProp, obj)
  422. {
  423. return new Proxy(obj, {
  424. set: (tgt, prop, val) => {
  425. if (prop === 'AdvManager')
  426. {
  427. console.log(`Ya.${rootProp} = Ya.Context`);
  428. nt.define(Ya, rootProp, Ya.Context);
  429. YaProps.add(rootProp);
  430. }
  431. tgt[prop] = val;
  432. return true;
  433. },
  434. get: (tgt, prop) => tgt[prop]
  435. });
  436. }
  437. let Rum = {};
  438. [
  439. '__timeMarks', '_timeMarks', '__deltaMarks', '_deltaMarks',
  440. '__defRes', '_defRes', '__defTimes', '_defTimes',
  441. 'commonVars'
  442. ].forEach(name => Rum[name] = []);
  443. [
  444. 'send', 'sendRaf', 'sendTimeMark', 'sendResTiming', 'sendTTI',
  445. '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 !== undefined && win.condition_detected !== undefined)
  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 !== undefined)
  1415. win.banner_second = 0;
  1416. if (win.$banner_ads !== undefined)
  1417. win.$banner_ads = false;
  1418. if (win.$new_ads !== undefined)
  1419. win.$new_ads = false;
  1420. if (win.createCookie !== undefined)
  1421. win.createCookie('popup', 'true', '999');
  1422. if (win.canRunAds !== undefined && win.canRunAds !== true)
  1423. win.canRunAds = true;
  1424. }
  1425. else if (win.MXoverrollCallback && win.iframeSearch !== undefined)
  1426. {
  1427. log('Kodik');
  1428. let tmp = document.querySelector('.play_button');
  1429. if (tmp)
  1430. tmp.onclick = win.MXoverrollCallback.bind(window);
  1431. win.IsAdBlock = false;
  1432. }
  1433. else if (win.getnextepisode && win.uppodEvent)
  1434. {
  1435. log('Share-Serials.net');
  1436. scriptLander(
  1437. function()
  1438. {
  1439. let _setInterval = win.setInterval,
  1440. _setTimeout = win.setTimeout;
  1441. win.setInterval = function(func)
  1442. {
  1443. if (func instanceof Function && func.toString().indexOf('_delay') > -1)
  1444. {
  1445. let intv = _setInterval.call(
  1446. this, function()
  1447. {
  1448. _setTimeout.call(
  1449. this, function(intv)
  1450. {
  1451. clearInterval(intv);
  1452. let timer = document.querySelector('#timer');
  1453. if (timer)
  1454. timer.click();
  1455. }, 100, intv);
  1456. func.call(this);
  1457. }, 5
  1458. );
  1459.  
  1460. return intv;
  1461. }
  1462. return _setInterval.apply(this, arguments);
  1463. };
  1464. win.setTimeout = function(func) {
  1465. if (func instanceof Function && func.toString().indexOf('adv_showed') > -1)
  1466. {
  1467. return _setTimeout.call(this, func, 0);
  1468. }
  1469. return _setTimeout.apply(this, arguments);
  1470. };
  1471. }
  1472. );
  1473. } else if ('ADC' in win)
  1474. {
  1475. log('vjs-creatives plugin in');
  1476. let replacer = (obj) => {
  1477. for (let name in obj)
  1478. if (obj[name] instanceof Function)
  1479. obj[name] = () => null;
  1480. };
  1481. replacer(win.ADC);
  1482. replacer(win.currentAdSlot);
  1483. }
  1484. UberVK: {
  1485. if (!inIFrame)
  1486. break UberVK;
  1487. let oddNames = 'HD' in win &&
  1488. !Object.getOwnPropertyNames(win).every(n => !n.startsWith('_0x'));
  1489. if (!oddNames)
  1490. break UberVK;
  1491. log('UberVK');
  1492. XMLHttpRequest.prototype.open = () => { throw 404; };
  1493. }
  1494. }, false
  1495. );
  1496.  
  1497. // piguiqproxy.com circumvention prevention
  1498. scriptLander(
  1499. () => {
  1500. let _open = XMLHttpRequest.prototype.open;
  1501. // blacklist of third-party domains requests to which are ignored
  1502. let blacklist = /[/.@](amgload\.net|dsn-fishki\.ru|kingoablc\.com|piguiqproxy\.com|rcdn\.pro)[:/]/i;
  1503. // blacklist of domains where all third-party requests are ignored
  1504. let ondomains = /(^|[/.@])oane\.ws($|[:/])/i;
  1505. // highly suspicious URLs
  1506. let suspicious = /^https?:\/\/(csp-)?[a-z0-9]{6}\.ru\//i;
  1507. let on_get_ban = /^https?:\/\/(csp-)?[a-z0-9]{6}\.ru\/([a-z0-9\/]{45,}|[a-z0-9]{8,}|ad\/banner\/.+)$/i;
  1508. let on_post_ban = /^https?:\/\/(csp-)?[a-z0-9]{6}\.ru\/([a-z0-9]{6,})$/i;
  1509.  
  1510. XMLHttpRequest.prototype.open = function(method, url)
  1511. {
  1512. if (method === 'GET' &&
  1513. (blacklist.test(url) || on_get_ban.test(url) ||
  1514. ondomains.test(location.hostname) && !ondomains.test(url)) ||
  1515. method === 'POST' && on_post_ban.test(url))
  1516. {
  1517. this.send = () => null;
  1518. this.setRequestHeader = () => null;
  1519. console.log('Blocked request: ', url);
  1520. return;
  1521. }
  1522. if (suspicious.test(url))
  1523. console.warn('Suspicious request: ', url);
  1524. return _open.apply(this, arguments);
  1525. };
  1526. }
  1527. );
  1528.  
  1529. // === Helper functions ===
  1530.  
  1531. // function to search and remove nodes by content
  1532. // selector - standard CSS selector to define set of nodes to check
  1533. // words - regular expression to check content of the suspicious nodes
  1534. // params - object with multiple extra parameters:
  1535. // .log - display log in the console
  1536. // .hide - set display to none instead of removing from the page
  1537. // .parent - parent node to remove if content is found in the child node
  1538. // .siblings - number of simling nodes to remove (excluding text nodes)
  1539. let scRemove = (node) => node.parentNode.removeChild(node);
  1540. let scHide = function(node)
  1541. {
  1542. let style = _getAttribute.call(node, 'style') || '',
  1543. hide = ';display:none!important;';
  1544. if (style.indexOf(hide) < 0)
  1545. _setAttribute.call(node, 'style', style + hide);
  1546. };
  1547.  
  1548. function scissors (selector, words, scope, params)
  1549. {
  1550. let logger = function() { return params.log ? console.log(...arguments) : null; };
  1551. if (!scope.contains(document.body))
  1552. logger('[s] scope', scope);
  1553. let remFunc = (params.hide ? scHide : scRemove),
  1554. iterFunc = (params.siblings > 0 ? 'nextElementSibling' : 'previousElementSibling'),
  1555. toRemove = [],
  1556. siblings;
  1557. for (let node of scope.querySelectorAll(selector))
  1558. {
  1559. // drill up to a parent node if specified, break if not found
  1560. if (params.parent)
  1561. {
  1562. let old = node;
  1563. node = node.closest(params.parent);
  1564. if (node === null || node.contains(scope))
  1565. {
  1566. logger('[s] went out of scope with', old);
  1567. continue;
  1568. }
  1569. }
  1570. logger('[s] processing', node);
  1571. if (toRemove.includes(node))
  1572. continue;
  1573. if (words.test(node.innerHTML))
  1574. {
  1575. // skip node if already marked for removal
  1576. logger('[s] marked for removal');
  1577. toRemove.push(node);
  1578. // add multiple nodes if defined more than one sibling
  1579. siblings = Math.abs(params.siblings) || 0;
  1580. while (siblings)
  1581. {
  1582. node = node[iterFunc];
  1583. if (!node) break; // can't go any further - exit
  1584. logger('[s] adding sibling node', node);
  1585. toRemove.push(node);
  1586. siblings -= 1;
  1587. }
  1588. }
  1589. }
  1590. let toSkip = [];
  1591. for (let node of toRemove)
  1592. if (!toRemove.every(other => other === node || !node.contains(other)))
  1593. toSkip.push(node);
  1594. if (toRemove.length)
  1595. logger(`[s] proceeding with ${params.hide?'hide':'removal'} of`, toRemove, `skip`, toSkip);
  1596. for (let node of toRemove) if (!toSkip.includes(node))
  1597. remFunc(node);
  1598. }
  1599.  
  1600. // function to perform multiple checks if ads inserted with a delay
  1601. // by default does 30 checks withing a 3 seconds unless nonstop mode specified
  1602. // also does 1 extra check when a page completely loads
  1603. // selector and words - passed dow to scissors
  1604. // params - object with multiple extra parameters:
  1605. // .log - display log in the console
  1606. // .root - selector to narrow down scope to scan;
  1607. // .observe - if true then check will be performed continuously;
  1608. // Other parameters passed down to scissors.
  1609. function gardener(selector, words, params)
  1610. {
  1611. let logger = function() { return params.log ? console.log(...arguments) : null; };
  1612. params = params || {};
  1613. logger(`[gardener] selector: '${selector}' detector: ${words} options: ${JSON.stringify(params)}`);
  1614. let scope;
  1615. let globalScope = [_de];
  1616. let domLoaded = false;
  1617. let getScope = root => root ? _de.querySelectorAll(root) : globalScope;
  1618. let onevent = e => {
  1619. logger(`[gardener] cleanup on ${Object.getPrototypeOf(e)} "${e.type}"`);
  1620. for (let node of scope)
  1621. scissors(selector, words, node, params);
  1622. };
  1623. let repeater = n => {
  1624. if (!domLoaded && n) {
  1625. setTimeout(repeater, 500, n - 1);
  1626. scope = getScope(params.root);
  1627. if (!scope) // exit if the root element is not present on the page
  1628. return 0;
  1629. onevent({type: 'Repeater'});
  1630. }
  1631. };
  1632. repeater(20);
  1633. document.addEventListener(
  1634. 'DOMContentLoaded', (e) => {
  1635. domLoaded = true;
  1636. // narrow down scope to a specific element
  1637. scope = getScope(params.root);
  1638. if (!scope) // exit if the root element is not present on the page
  1639. return 0;
  1640. logger('[g] scope', scope);
  1641. // add observe mode if required
  1642. if (params.observe)
  1643. {
  1644. let params = { childList:true, subtree: true };
  1645. let observer = new MutationObserver(
  1646. function(ms)
  1647. {
  1648. for (let m of ms)
  1649. if (m.addedNodes.length)
  1650. onevent(m);
  1651. }
  1652. );
  1653. for (let node of scope)
  1654. observer.observe(node, params);
  1655. logger('[g] observer enabled');
  1656. }
  1657. onevent(e);
  1658. }, false);
  1659. // wait for a full page load to do one extra cut
  1660. win.addEventListener('load', onevent, false);
  1661. }
  1662.  
  1663. // wrap popular methods to open a new tab to catch specific behaviours
  1664. function createWindowOpenWrapper(openFunc, onClickFunc)
  1665. {
  1666. let _createElement = _Document.prototype.createElement,
  1667. _appendChild = _Element.prototype.appendChild,
  1668. fakeNative = (f) => (f.toString = () => `function ${f.name}() { [native code] }`);
  1669.  
  1670. let nt = new nullTools();
  1671. fakeNative(openFunc);
  1672.  
  1673. let parser = _createElement.call(document, 'a');
  1674. let openWhitelist = (url, parent) => {
  1675. parser.href = url;
  1676. return parser.hostname === 'www.imdb.com' || parser.hostname === 'www.kinopoisk.ru' ||
  1677. parent.hostname === 'radikal.ru' && url === void 0;
  1678. };
  1679.  
  1680. let redefineOpen = (root) => {
  1681. if ('open' in root) {
  1682. let _open = root.open.bind(root);
  1683. nt.define(root, 'open', (...args) => {
  1684. if (openWhitelist(args[0], location)) {
  1685. console.log('Whitelisted popup:', ...args);
  1686. return _open(...args);
  1687. }
  1688. return openFunc(...args);
  1689. });
  1690. }
  1691. };
  1692. redefineOpen(win);
  1693.  
  1694. function createElement(name) {
  1695. '[native code]';
  1696. // jshint validthis:true
  1697. let el = _createElement.apply(this, arguments);
  1698. // redefine window.open in first-party frames
  1699. if (el instanceof HTMLIFrameElement || el instanceof HTMLObjectElement)
  1700. el.addEventListener('load', (e) => {
  1701. try {
  1702. redefineOpen(e.target.contentWindow);
  1703. } catch(ignore) {}
  1704. }, false);
  1705. return el;
  1706. }
  1707. fakeNative(createElement);
  1708.  
  1709. let redefineCreateElement = (obj) => {
  1710. for (let root of [obj.document, _Document.prototype]) if ('createElement' in root)
  1711. nt.define(root, 'createElement', createElement);
  1712. };
  1713. redefineCreateElement(win);
  1714.  
  1715. // wrap window.open in newly added first-party frames
  1716. _Element.prototype.appendChild = function appendChild()
  1717. {
  1718. '[native code]';
  1719. let el = _appendChild.apply(this, arguments);
  1720. if (el instanceof HTMLIFrameElement) {
  1721. try {
  1722. redefineOpen(el.contentWindow);
  1723. redefineCreateElement(el.contentWindow);
  1724. } catch(ignore) {}
  1725. }
  1726. return el;
  1727. };
  1728. fakeNative(_Element.prototype.appendChild);
  1729. }
  1730.  
  1731. // Function to catch and block various methods to open a new window with 3rd-party content.
  1732. // Some advertisement networks went way past simple window.open call to circumvent default popup protection.
  1733. // This funciton blocks window.open, ability to restore original window.open from an IFRAME object,
  1734. // ability to perform an untrusted (not initiated by user) click on a link, click on a link without a parent
  1735. // node or simply a link with piece of javascript code in the HREF attribute.
  1736. function preventPopups()
  1737. {
  1738. // call sandbox-me if in iframe and not whitelisted
  1739. if (inIFrame) {
  1740. win.top.postMessage({ name: 'sandbox-me', href: win.location.href }, '*');
  1741. return;
  1742. }
  1743.  
  1744. scriptLander(() => {
  1745. let open = (...args) => {
  1746. '[native code]';
  1747. console.warn('Site attempted to open a new window', args);
  1748. if (new RegExp(`^https?://${location.hostname}/`).test(args[0])) // skip extra click in case of blocked popunder
  1749. location.assign(args[0]);
  1750. return {
  1751. document: {
  1752. write: () => {},
  1753. writeln: () => {}
  1754. },
  1755. location: {}
  1756. };
  1757. };
  1758.  
  1759. let clickHandler = (e) => {
  1760. let link = e.target;
  1761. if (!link.parentNode || !e.isTrusted ||
  1762. (link.href && link.href.trim().toLowerCase().indexOf('javascript') === 0))
  1763. {
  1764. e.preventDefault();
  1765. console.warn('Blocked suspicious click event', e, 'on', e.target);
  1766. }
  1767. };
  1768.  
  1769. createWindowOpenWrapper(open, clickHandler);
  1770.  
  1771. console.log('Popup prevention enabled.');
  1772. }, nullTools, createWindowOpenWrapper);
  1773. }
  1774.  
  1775. // Helper function to close background tab if site opens itself in a new tab and then
  1776. // loads a 3rd-party page in the background one (thus performing background redirect).
  1777. function preventPopunders()
  1778. {
  1779. // create "close_me" event to call high-level window.close()
  1780. let eventName = `close_me_${Math.random().toString(36).substr(2)}`;
  1781. let callClose = () => (console.log('close call'), window.close());
  1782. window.addEventListener(eventName, callClose, true);
  1783.  
  1784. scriptLander(() => {
  1785. // get host of a provided URL with help of an anchor object
  1786. // unfortunately new URL(url, window.location) generates wrong URL in some cases
  1787. let parseURL = document.createElement('A');
  1788. let getHost = (url) => (parseURL.href = url, parseURL.hostname);
  1789. // site went to a new tab and attempts to unload
  1790. // call for high-level close through event
  1791. let closeWindow = () => window.dispatchEvent(new CustomEvent(eventName, {}));
  1792. // check is URL local or goes to different site
  1793. let isLocal = (url) => {
  1794. if (url === location.pathname || url === location.href)
  1795. return true; // URL points to current pathname or full address
  1796. let host = getHost(url);
  1797. let site = location.hostname;
  1798. return host !== '' && // URLs with unusual protocol may have empty 'host'
  1799. (site === host || site.endsWith(`.${host}`) || host.endsWith(`.${site}`));
  1800. };
  1801.  
  1802. let _open = window.open.bind(window);
  1803. let open = (...args) => {
  1804. '[native code]';
  1805. let url = args[0];
  1806. if (url && isLocal(url))
  1807. window.addEventListener('beforeunload', closeWindow, true);
  1808. // jshint validthis:true
  1809. return _open(...args);
  1810. };
  1811.  
  1812. let clickHandler = (e) => {
  1813. if (!e.target.parentNode || !e.isTrusted)
  1814. window.addEventListener('beforeunload', closeWindow, true);
  1815. };
  1816.  
  1817. createWindowOpenWrapper(open, clickHandler);
  1818.  
  1819. console.log("Background redirect prevention enabled.");
  1820. }, `let eventName="${eventName}"`, nullTools, createWindowOpenWrapper);
  1821. }
  1822.  
  1823. // Mix between check for popups and popunders
  1824. // Significantly more agressive than both and can't be used as universal solution
  1825. function preventPopMix()
  1826. {
  1827. if (inIFrame)
  1828. {
  1829. win.top.postMessage({ name: 'sandbox-me', href: win.location.href }, '*');
  1830. return;
  1831. }
  1832.  
  1833. // create "close_me" event to call high-level window.close()
  1834. let eventName = `close_me_${Math.random().toString(36).substr(2)}`;
  1835. let callClose = () => (console.log('close call'), window.close());
  1836. window.addEventListener(eventName, callClose, true);
  1837.  
  1838. scriptLander(() => {
  1839. let _open = window.open,
  1840. parseURL = document.createElement('A');
  1841. // get host of a provided URL with help of an anchor object
  1842. // unfortunately new URL(url, window.location) generates wrong URL in some cases
  1843. let getHost = (url) => (parseURL.href = url, parseURL.host);
  1844. // site went to a new tab and attempts to unload
  1845. // call for high-level close through event
  1846. let closeWindow = () => (_open(window.location,'_self'), window.dispatchEvent(new CustomEvent(eventName, {})));
  1847. // check is URL local or goes to different site
  1848. function isLocal(url)
  1849. {
  1850. let loc = window.location;
  1851. if (url === loc.pathname || url === loc.href)
  1852. return true; // URL points to current pathname or full address
  1853. let host = getHost(url),
  1854. site = loc.host;
  1855. if (host === '')
  1856. return false; // URLs with unusual protocol may have empty 'host'
  1857. if (host.length > site.length)
  1858. [site, host] = [host, site];
  1859. return site.includes(host, site.length - host.length);
  1860. }
  1861.  
  1862. // add check for redirect for 5 seconds, then disable it
  1863. function checkRedirect()
  1864. {
  1865. window.addEventListener('beforeunload', closeWindow, true);
  1866. setTimeout(closeWindow=>window.removeEventListener('beforeunload', closeWindow, true), 5000, closeWindow);
  1867. }
  1868.  
  1869. function open(url, name)
  1870. {
  1871. '[native code]';
  1872. if (url && isLocal(url) && (!name || name === '_blank'))
  1873. {
  1874. console.warn('Suspicious local new window', arguments);
  1875. checkRedirect();
  1876. // jshint validthis:true
  1877. return _open.apply(this, arguments);
  1878. }
  1879. console.warn('Blocked attempt to open a new window', arguments);
  1880. return {
  1881. document: {
  1882. write: () => {},
  1883. writeln: () => {}
  1884. }
  1885. };
  1886. }
  1887.  
  1888. function clickHandler(e)
  1889. {
  1890. let link = e.target,
  1891. url = link.href||'';
  1892. if (e.targetParentNode && e.isTrusted || link.target !== '_blank')
  1893. {
  1894. console.log('Link', link, 'were created dinamically, but looks fine.');
  1895. return true;
  1896. }
  1897. if (isLocal(url) && link.target === '_blank')
  1898. {
  1899. console.log('Suspicious local link', link);
  1900. checkRedirect();
  1901. return;
  1902. }
  1903. console.log('Blocked suspicious click on a link', link);
  1904. e.stopPropagation();
  1905. e.preventDefault();
  1906. }
  1907.  
  1908. createWindowOpenWrapper(open, clickHandler);
  1909.  
  1910. console.log("Mixed popups prevention enabled.");
  1911. }, `let eventName="${eventName}"`, createWindowOpenWrapper);
  1912. }
  1913. // External listener for case when site known to open popups were loaded in iframe
  1914. // It will sandbox any iframe which will send message 'forbid.popups' (preventPopups sends it)
  1915. // Some sites replace frame's window.location with data-url to run in clean context
  1916. if (!inIFrame)
  1917. {
  1918. window.addEventListener(
  1919. 'message', function(e)
  1920. {
  1921. if (!e.data || e.data.name !== 'sandbox-me' || !e.data.href)
  1922. return;
  1923. let src = e.data.href;
  1924. for (let frame of document.querySelectorAll('iframe'))
  1925. if (frame.contentWindow === e.source)
  1926. {
  1927. if (frame.hasAttribute('sandbox'))
  1928. {
  1929. if (!frame.sandbox.contains('allow-popups'))
  1930. return; // exit frame since it's already sandboxed and popups are blocked
  1931. // remove allow-popups if frame already sandboxed
  1932. frame.sandbox.remove('allow-popups');
  1933. } else {
  1934. // set sandbox mode for troublesome frame and allow scripts, forms and a few other actions
  1935. // technically allowing both scripts and same-origin allows removal of the sandbox attribute,
  1936. // but to apply content must be reloaded and this script will re-apply it in the result
  1937. frame.setAttribute('sandbox','allow-forms allow-scripts allow-presentation allow-top-navigation allow-same-origin');
  1938. }
  1939. console.log('Disallowed popups from iframe', frame);
  1940.  
  1941. // reload frame content to apply restrictions
  1942. if (!src) {
  1943. src = frame.src;
  1944. console.log('Unable to get current iframe location, reloading from src', src);
  1945. } else
  1946. console.log('Reloading iframe with URL', src);
  1947. frame.src = 'about:blank';
  1948. frame.src = src;
  1949. }
  1950. }, false
  1951. );
  1952. }
  1953.  
  1954. function selectiveEval() {
  1955. scriptLander(() => {
  1956. let nt = new nullTools();
  1957. let _eval = win.eval.bind(window);
  1958. nt.define(win, 'eval', function(...args) {
  1959. if (/_0x|location\s*?=|location.href\s*?=|location.assign\(|open\(/i.test(args[0])) {
  1960. console.log(`Skipped eval of ${args[0].slice(0, 512)}\u2026`);
  1961. return null;
  1962. }
  1963. return _eval(...args);
  1964. });
  1965. }, nullTools);
  1966. }
  1967.  
  1968. // === Scripts for specific domains ===
  1969.  
  1970. let scripts = {};
  1971. // prevent popups and redirects block
  1972. // Popups
  1973. scripts.preventPopups = {
  1974. other: [
  1975. 'biqle.ru',
  1976. 'chaturbate.com',
  1977. 'dfiles.ru',
  1978. 'eporner.eu',
  1979. 'hentaiz.org',
  1980. 'mirrorcreator.com',
  1981. 'online-multy.ru',
  1982. 'radikal.ru', 'rumedia.ws',
  1983. 'thepiratebay.org',
  1984. 'unionpeer.com',
  1985. 'zippyshare.com'
  1986. ],
  1987. now: preventPopups
  1988. };
  1989. // Popunders (background redirect)
  1990. scripts.preventPopunders = {
  1991. other: [
  1992. 'lostfilm-online.ru',
  1993. 'mediafire.com', 'megapeer.org', 'megapeer.ru',
  1994. 'perfectgirls.net'
  1995. ],
  1996. now: preventPopunders
  1997. };
  1998. // PopMix (both types of popups encountered on site)
  1999. scripts['openload.co'] = {
  2000. other: ['oload.tv', 'oload.info'],
  2001. now: () => {
  2002. let nt = new nullTools();
  2003. nt.define(win, 'CNight', win.CoinHive);
  2004. if (location.pathname.startsWith('/embed/'))
  2005. {
  2006. nt.define(win, 'BetterJsPop', {
  2007. add: ((a, b) => console.warn('BetterJsPop.add', a, b)),
  2008. config: ((o) => console.warn('BetterJsPop.config', o)),
  2009. Browser: { isChrome: true }
  2010. });
  2011. nt.define(win, 'isSandboxed', nt.func(null));
  2012. nt.define(win, 'adblock', false);
  2013. nt.define(win, 'adblock2', false);
  2014. } else
  2015. preventPopMix();
  2016. }
  2017. };
  2018. scripts['turbobit.net'] = preventPopMix;
  2019.  
  2020. // workaround for moradu.com/apu.php load error handler script, not sure which ad network is this
  2021. scripts['tapochek.net'] = () => {
  2022. let _appendChild = Object.getOwnPropertyDescriptor(_Node.prototype, 'appendChild');
  2023. let _appendChild_value = _appendChild.value;
  2024. _appendChild.value = function appendChild(node) {
  2025. if (this === win.document.body)
  2026. if ((node instanceof HTMLScriptElement || node instanceof HTMLStyleElement) &&
  2027. /^https?:\/\/[0-9a-f]{15}\.com\/\d+(\/|\.css)$/.test(node.src) ||
  2028. node instanceof HTMLDivElement && node.style.zIndex > 900000 &&
  2029. node.style.backgroundImage.includes('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'))
  2030. throw '...eenope!';
  2031. return _appendChild_value.apply(this, arguments);
  2032. };
  2033. Object.defineProperty(_Node.prototype, 'appendChild', _appendChild);
  2034.  
  2035. preventPopups();
  2036. };
  2037.  
  2038. scripts['rustorka.com'] = {
  2039. other: ['rustorka.lib'],
  2040. now: () => scriptLander(() => {
  2041. let crumbler = e => { // crumble suspicious cookies
  2042. let base = '=; expires=Thu, 01 Jan 1970 00:00:01 UTC; Max-Age=-99999999; path=/';
  2043. console.log('cookies', document.cookie);
  2044. for (let name of ['adblock', 'gophp', '_692293176245', '_692293176246'])
  2045. document.cookie = `${name}${base}`;
  2046. for (let name of ['st2', 'st3']) {
  2047. document.cookie = `${name}${base}forum`;
  2048. document.cookie = `${name}${base}forum/`;
  2049. }
  2050. console.log('cookies', document.cookie);
  2051. };
  2052. document.addEventListener('DOMContentLoaded', crumbler, false);
  2053. crumbler();
  2054.  
  2055. let nt = new nullTools({trace: true});
  2056. nt.define(win, 'syka', false);
  2057. nt.define(win, '_692293176244', location.href);
  2058. [
  2059. 'MTLuxup', 'MTAdSniper', 'MTutarg', 'MTUAatar', 'MTcityAds', 'MTmxMark',
  2060. 'MTmxMark2', 'MTmdnt', 'MTrfDumedia', 'MXsmTDS', 'MTritorno', 'MTadvice',
  2061. 'cyka', 'MTAdTraff', 'MTExebid', 'MXsockFound'
  2062. ].forEach(name => nt.define(win, name, nt.func(null, name)));
  2063. let _eval_def = Object.getOwnPropertyDescriptor(win, 'eval');
  2064. if (!_eval_def)
  2065. return;
  2066. let _eval_val = _eval_def.value;
  2067. _eval_def.value = (...args) => {
  2068. if (args[0] && args[0].includes('antiadblock'))
  2069. return console.log('Anti-AdBlock script may run another day, but not today.');
  2070. return _eval_val.apply(this, args);
  2071. };
  2072. Object.defineProperty(win, 'eval', _eval_def);
  2073. win.open = (...args) => {
  2074. console.warn(`Site attempted to open "${args[0]}" in a new window.`);
  2075. location.replace(location.href);
  2076. return null;
  2077. };
  2078. window.addEventListener('DOMContentLoaded', () => {
  2079. let link = void 0;
  2080. document.body.addEventListener('mousedown', e => {
  2081. link = e.target.closest('a, select, #fancybox-title-wrap');
  2082. }, false);
  2083. let _open = window.open.bind(window);
  2084. let _getAttribute = _Element.prototype.getAttribute;
  2085. win.open = (...args) => {
  2086. let url = args[0];
  2087. let allow = false;
  2088. if (link instanceof HTMLAnchorElement) {
  2089. // third-party post links
  2090. let href = _getAttribute.call(link, 'href');
  2091. if (link.classList.contains('postLink') &&
  2092. !link.matches(`a[href*="${location.hostname}"]`) &&
  2093. (href === url || link.href === url)) {
  2094. return _open(...args);
  2095. }
  2096. // onclick # links
  2097. if (href === '#' && /window\.open/.test(_getAttribute.call(link, 'onclick'))) {
  2098. return _open(...args);
  2099. }
  2100. // force local links to load in the current window
  2101. if (href[0] === '/' || href.startsWith('./') || href.includes(`//${location.hostname}/`))
  2102. location.assign(href);
  2103. }
  2104. // list of image hostings under upload picture button (new comment)
  2105. if (link instanceof HTMLSelectElement &&
  2106. !url.includes(location.hostname) &&
  2107. link.value === url) {
  2108. return _open(...args);
  2109. }
  2110. // open screenshot in a new window
  2111. if (link instanceof HTMLSpanElement &&
  2112. link.id === 'fancybox-title-wrap') {
  2113. return _open(...args);
  2114. }
  2115. // looks like tabunder
  2116. if (link === null && url === location.href)
  2117. location.replace(url); // reload current page
  2118. // other cases
  2119. console.warn(`Site attempted to open "${url}" in a new window. Source: `, link);
  2120. return {};
  2121. };
  2122. }, true);
  2123. }, nullTools)
  2124. };
  2125.  
  2126. // other
  2127. scripts['1tv.ru'] = () => scriptLander(() => {
  2128. let nt = new nullTools();
  2129. nt.define(win, 'EUMPAntiblockConfig', nt.proxy({url: '//www.1tv.ru/favicon.ico'}));
  2130. let disablePlugins = {
  2131. 'antiblock': false,
  2132. 'stat1tv': false
  2133. };
  2134. let _EUMPConfig = void 0;
  2135. let _EUMPConfig_set = x => {
  2136. if (x.plugins) {
  2137. x.plugins = x.plugins.filter(plugin => (plugin in disablePlugins) ? !(disablePlugins[plugin] = true) : true);
  2138. console.warn(`Player plugins: active [${x.plugins}], disabled [${Object.keys(disablePlugins).filter(x => disablePlugins[x])}]`);
  2139. }
  2140. _EUMPConfig = x;
  2141. };
  2142. if ('EUMPConfig' in win)
  2143. _EUMPConfig_set(win.EUMPConfig);
  2144. Object.defineProperty(win, 'EUMPConfig', {
  2145. enumerable: true,
  2146. get: x => _EUMPConfig,
  2147. set: _EUMPConfig_set
  2148. });
  2149. }, nullTools);
  2150.  
  2151. scripts['2picsun.ru'] = {
  2152. other: [
  2153. 'pics2sun.ru', '3pics-img.ru'
  2154. ],
  2155. now: () => {
  2156. Object.defineProperty(navigator, 'userAgent', {value: 'googlebot'});
  2157. }
  2158. };
  2159.  
  2160. scripts['4pda.ru'] = {
  2161. now: () => {
  2162. // https://greasyfork.org/en/scripts/14470-4pda-unbrender
  2163. let hStyle,
  2164. isForum = document.location.href.search('/forum/') !== -1,
  2165. remove = (node) => (node ? node.parentNode.removeChild(node) : null),
  2166. afterClean = () => remove(hStyle);
  2167.  
  2168. function beforeClean()
  2169. {
  2170. // attach styles before document displayed
  2171. hStyle = createStyle([
  2172. 'html { overflow-y: scroll }',
  2173. 'article + aside * { display: none !important }',
  2174. `section[id] {${(
  2175. 'position: absolute;'+
  2176. 'width: 100%'
  2177. )}}`,
  2178. `#header + div:after {${(
  2179. 'content: "";'+
  2180. 'position: fixed;'+
  2181. 'top: 0;'+
  2182. 'left: 0;'+
  2183. 'width: 100%;'+
  2184. 'height: 100%;'+
  2185. 'background-color: #E6E7E9'
  2186. )}}`,
  2187. // http://codepen.io/Beaugust/pen/DByiE
  2188. '@keyframes spin { 100% { transform: rotate(360deg) } }',
  2189. `article + aside:after {${(
  2190. 'content: "";'+
  2191. 'position: absolute;'+
  2192. 'width: 150px;'+
  2193. 'height: 150px;'+
  2194. 'top: 150px;'+
  2195. 'left: 50%;'+
  2196. 'margin-top: -75px;'+
  2197. 'margin-left: -75px;'+
  2198. 'box-sizing: border-box;'+
  2199. 'border-radius: 100%;'+
  2200. 'border: 10px solid rgba(0, 0, 0, 0.2);'+
  2201. 'border-top-color: rgba(0, 0, 0, 0.6);'+
  2202. 'animation: spin 2s infinite linear'
  2203. )}}`
  2204. ], {id:'ubrHider'}, true);
  2205.  
  2206. // display content of a page if time to load a page is more than 2 seconds to avoid
  2207. // blocking access to a page if it is loading for too long or stuck in a loading state
  2208. setTimeout(2000, afterClean);
  2209. }
  2210.  
  2211. createStyle([
  2212. '#nav .use-ad { display: block !important }',
  2213. 'article:not(.post) + article:not(#id),'+
  2214. '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 }'
  2215. ]);
  2216.  
  2217. if (!isForum)
  2218. beforeClean();
  2219.  
  2220. // save links to non-overridden functions to use later
  2221. let protectedElems;
  2222. // protect/hide changed attributes in case site attempt to restore them
  2223. function styleProtector(eventMode)
  2224. {
  2225. let _toLowerCase = String.prototype.toLowerCase,
  2226. isStyleText = (t) => (_toLowerCase.call(t) === 'style'),
  2227. protectedElems = new WeakMap();
  2228. function protoOverride(element, functionName, isStyleCheck, returnIfProtected)
  2229. {
  2230. let originalFunction = element.prototype[functionName];
  2231. element.prototype[functionName] = function wrapper()
  2232. {
  2233. if (protectedElems.has(this) && isStyleCheck(arguments[0]))
  2234. return returnIfProtected(this, arguments);
  2235. return originalFunction.apply(this, arguments);
  2236. };
  2237. }
  2238. protoOverride(Element, 'removeAttribute', isStyleText, () => undefined);
  2239. protoOverride(Element, 'hasAttribute', isStyleText, (_this) => protectedElems.get(_this) !== null);
  2240. protoOverride(Element, 'setAttribute', isStyleText, (_this, args) => protectedElems.set(_this, args[1]));
  2241. protoOverride(Element, 'getAttribute', isStyleText, (_this) => protectedElems.get(_this));
  2242. if (!eventMode)
  2243. return protectedElems;
  2244. else
  2245. {
  2246. let e = document.createEvent('Event');
  2247. e.initEvent('protoOverride', false, false);
  2248. window.protectedElems = protectedElems;
  2249. window.dispatchEvent(e);
  2250. }
  2251. }
  2252. if (!isFirefox)
  2253. protectedElems = styleProtector(false);
  2254. else
  2255. {
  2256. let script = document.createElement('script');
  2257. script.textContent = `(${styleProtector.toString()})(true);`;
  2258. window.addEventListener(
  2259. 'protoOverride', function protoOverrideCallback(e)
  2260. {
  2261. if (win.protectedElems) {
  2262. protectedElems = win.protectedElems;
  2263. delete win.protectedElems;
  2264. }
  2265. document.removeEventListener('protoOverride', protoOverrideCallback, true);
  2266. }, true
  2267. );
  2268. _appendChild(script);
  2269. _removeChild(script);
  2270. }
  2271.  
  2272. // clean a page
  2273. window.addEventListener(
  2274. 'DOMContentLoaded', function()
  2275. {
  2276. let width = () => window.innerWidth || _de.clientWidth || document.body.clientWidth || 0;
  2277. let height = () => window.innerHeight || _de.clientHeight || document.body.clientHeight || 0;
  2278.  
  2279. if (isForum)
  2280. {
  2281. let si = document.querySelector('#logostrip');
  2282. if (si)
  2283. remove(si.parentNode.nextSibling);
  2284. }
  2285.  
  2286. // clear background in the download frame
  2287. if (location.pathname.startsWith('/forum/dl/')) {
  2288. let setBackground = node => _setAttribute.call(
  2289. node,
  2290. 'style', (_getAttribute.call(node, 'style') || '') +
  2291. ';background-color:#4ebaf6!important'
  2292. );
  2293. setBackground(document.body);
  2294. for (let itm of document.querySelectorAll('body > div'))
  2295. if (!itm.querySelector('.dw-fdwlink, .content') && !itm.classList.contains('footer')) {
  2296. remove(itm);
  2297. } else {
  2298. setBackground(itm);
  2299. }
  2300. }
  2301.  
  2302. if (isForum) // Do not continue if it's a forum
  2303. return;
  2304.  
  2305. {
  2306. let si = document.querySelector('#header');
  2307. if (si)
  2308. {
  2309. let rem = si.previousSibling;
  2310. while (rem)
  2311. {
  2312. si = rem.previousSibling;
  2313. remove(rem);
  2314. rem = si;
  2315. }
  2316. }
  2317. }
  2318.  
  2319. for (let itm of document.querySelectorAll('#nav li[class]'))
  2320. if (itm && itm.querySelector('a[href^="/tag/"]'))
  2321. remove(itm);
  2322.  
  2323. let style, result,
  2324. fakeStyles = new WeakMap(),
  2325. styleProxy = {
  2326. get: function(target, prop)
  2327. {
  2328. let fakeStyle = fakeStyles.get(target);
  2329. return ((prop in fakeStyle) ? fakeStyle : target)[prop];
  2330. },
  2331. set: function(target, prop, value)
  2332. {
  2333. let fakeStyle = fakeStyles.get(target);
  2334. ((prop in fakeStyle) ? fakeStyle : target)[prop] = value;
  2335. return true;
  2336. }
  2337. };
  2338. for (let itm of document.querySelectorAll('DIV, CONTENT, SECTION, A'))
  2339. {
  2340. if ((itm.tagName ==='DIV' || itm.tagName ==='CONTENT' || itm.tagName ==='SECTION') &&
  2341. itm.offsetWidth > 0.95 * width() &&
  2342. itm.offsetHeight > 0.85 * height())
  2343. {
  2344. style = window.getComputedStyle(itm, null);
  2345. result = [];
  2346.  
  2347. if (style.backgroundImage !== 'none')
  2348. result.push('background-image:none!important');
  2349.  
  2350. if (style.backgroundColor !== 'transparent' &&
  2351. style.backgroundColor !== 'rgba(0, 0, 0, 0)')
  2352. result.push('background-color:transparent!important');
  2353.  
  2354. if (result.length)
  2355. {
  2356. if (itm.getAttribute('style'))
  2357. result.unshift(itm.getAttribute('style'));
  2358.  
  2359. fakeStyles.set(itm.style, {
  2360. 'backgroundImage': itm.style.backgroundImage,
  2361. 'backgroundColor': itm.style.backgroundColor
  2362. });
  2363.  
  2364. try {
  2365. Object.defineProperty(itm, 'style', {
  2366. value: new Proxy(itm.style, styleProxy),
  2367. enumerable: true
  2368. });
  2369. } catch (e) {
  2370. console.log('Unable to protect style property.', e);
  2371. }
  2372.  
  2373. if (protectedElems)
  2374. protectedElems.set(itm, _getAttribute.call(itm, 'style'));
  2375.  
  2376. _setAttribute.call(itm, 'style', result.join(';'));
  2377. }
  2378. }
  2379. if (itm.tagName ==='A' &&
  2380. (itm.offsetWidth > 0.95 * width() ||
  2381. itm.offsetHeight > 0.85 * height()))
  2382. {
  2383. if (protectedElems)
  2384. protectedElems.set(itm, _getAttribute.call(itm, 'style'));
  2385.  
  2386. _setAttribute.call(itm, 'style', 'display:none!important');
  2387. }
  2388. }
  2389.  
  2390. for (let itm of document.querySelectorAll('ASIDE>DIV'))
  2391. if ( ((itm.querySelector('script, iframe, a[href*="/ad/www/"]') ||
  2392. itm.querySelector('img[src$=".gif"]:not([height="0"]), img[height="400"]')) &&
  2393. !itm.classList.contains('post') ) || !itm.childNodes.length )
  2394. remove(itm);
  2395.  
  2396. document.body.setAttribute('style', (document.body.getAttribute('style')||'')+';background-color:#E6E7E9!important');
  2397.  
  2398. // display content of the page
  2399. afterClean();
  2400. }
  2401. );
  2402. }
  2403. };
  2404.  
  2405. scripts['adhands.ru'] = () => scriptLander(() => {
  2406. let nt = new nullTools();
  2407. try {
  2408. let _adv;
  2409. Object.defineProperty(win, 'adv', {
  2410. get: () => _adv,
  2411. set: (v) => {
  2412. console.log('Blocked advert on adhands.ru.');
  2413. nt.define(v, 'advert', '');
  2414. _adv = v;
  2415. }
  2416. });
  2417. } catch (ignore) {
  2418. if (!win.adv)
  2419. console.log('Unable to locate advert on adhands.ru.');
  2420. else {
  2421. console.log('Blocked advert on adhands.ru.');
  2422. nt.define(win.adv, 'advert', '');
  2423. }
  2424. }
  2425. }, nullTools);
  2426.  
  2427. scripts['all-episodes.tv'] = () => {
  2428. let nt = new nullTools();
  2429. nt.define(win, 'perX1', 2);
  2430. createStyle('#advtss, #ad3, a[href*="/ad.admitad.com/"] { display:none!important }');
  2431. };
  2432.  
  2433. scripts['allhentai.ru'] = () => {
  2434. selectiveEval();
  2435. preventPopups();
  2436. scriptLander(() => {
  2437. let _onerror = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'onerror');
  2438. if (!_onerror)
  2439. return;
  2440. _onerror.set = (...args) => console.log(args[0].toString());
  2441. Object.defineProperty(HTMLElement.prototype, 'onerror', _onerror);
  2442. });
  2443. };
  2444.  
  2445. scripts['allmovie.pro'] = {
  2446. other: ['rufilmtv.org'],
  2447. dom: function()
  2448. {
  2449. // pretend to be Android to make site use different played for ads
  2450. if (isSafari)
  2451. return;
  2452. Object.defineProperty(navigator, 'userAgent', {
  2453. 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'; },
  2454. enumerable: true
  2455. });
  2456. }
  2457. };
  2458.  
  2459. scripts['anidub-online.ru'] = {
  2460. other: ['online.anidub.com'],
  2461. dom: function()
  2462. {
  2463. if (win.ogonekstart1)
  2464. win.ogonekstart1 = () => console.log("Fire in the hole!");
  2465. },
  2466. now: () => createStyle([
  2467. '.background {background: none!important;}',
  2468. '.background > script + div,'+
  2469. '.background > script ~ div:not([id]):not([class]) + div[id][class]'+
  2470. '{display:none!important}'
  2471. ])
  2472. };
  2473.  
  2474. scripts['drive2.ru'] = () => {
  2475. gardener('.c-block:not([data-metrika="recomm"]),.o-grid__item', />Реклама<\//i);
  2476. scriptLander(() => {
  2477. let _d2 = void 0;
  2478. Object.defineProperty(win, 'd2', {
  2479. get: x => _d2,
  2480. set: o => {
  2481. _d2 = new Proxy(o, {
  2482. set: (tgt, prop, val) => {
  2483. if (['brandingRender', 'dvReveal', '__dv'].includes(prop))
  2484. val = () => null;
  2485. tgt[prop] = val;
  2486. }
  2487. });
  2488. }
  2489. });
  2490. });
  2491. };
  2492.  
  2493. scripts['fishki.net'] = () => {
  2494. scriptLander(() => {
  2495. let nt = new nullTools();
  2496. let fishki = {};
  2497. nt.define(fishki, 'adv', nt.proxy({
  2498. afterAdblockCheck: nt.func(null),
  2499. refreshFloat: nt.func(null)
  2500. }));
  2501. nt.define(fishki, 'is_adblock', false);
  2502. nt.define(win, 'fishki', fishki);
  2503. }, nullTools);
  2504. gardener('.drag_list > .drag_element, .list-view > .paddingtop15, .post-wrap', /543769|Новости\sпартнеров|Полезная\sреклама/);
  2505. };
  2506.  
  2507. scripts['gidonline.club'] = () => createStyle('.tray > div[style] {display: none!important}');
  2508.  
  2509. scripts['hdgo.cc'] = {
  2510. other: ['46.30.43.38', 'couber.be'],
  2511. now: () => (new MutationObserver(
  2512. (ms) => {
  2513. let m, node;
  2514. for (m of ms) for (node of m.addedNodes)
  2515. if (node.tagName instanceof HTMLScriptElement && _getAttribute.call(node, 'onerror') !== null)
  2516. node.removeAttribute('onerror');
  2517. }
  2518. )).observe(document.documentElement, { childList:true, subtree: true })
  2519. };
  2520.  
  2521. scripts['gismeteo.ru'] = {
  2522. other: ['gismeteo.ua'],
  2523. now: () => gardener('div > script', /AdvManager/i, { observe: true, parent: 'div' })
  2524. };
  2525.  
  2526. scripts['hdrezka.ag'] = () => {
  2527. Object.defineProperty(win, 'ab', { value: false, enumerable: true });
  2528. gardener('div[id][onclick][onmouseup][onmousedown]', /onmouseout/i);
  2529. };
  2530.  
  2531. scripts['hideip.me'] = {
  2532. now: () => scriptLander(() => {
  2533. let _innerHTML = Object.getOwnPropertyDescriptor(_Element.prototype, 'innerHTML');
  2534. let _set_innerHTML = _innerHTML.set;
  2535. let _innerText = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'innerText');
  2536. let _get_innerText = _innerText.get;
  2537. let div = document.createElement('div');
  2538. _innerHTML.set = function(...args) {
  2539. _set_innerHTML.call(div, args[0].replace('i','a'));
  2540. if (args[0] && /[рp][еe]кл/.test(_get_innerText.call(div))||
  2541. /(\d\d\d?\.){3}\d\d\d?\:\d/.test(_get_innerText.call(this)) ) {
  2542. console.log('Anti-Adblock killed.');
  2543. return true;
  2544. }
  2545. _set_innerHTML.apply(this, args);
  2546. };
  2547. Object.defineProperty(_Element.prototype, 'innerHTML', _innerHTML);
  2548. Object.defineProperty(win, 'adblock', {
  2549. get: x => false,
  2550. set: x => null,
  2551. enumerable: true
  2552. });
  2553. let _$ = {};
  2554. let _$_map = new WeakMap();
  2555. let _gOPD = Object.getOwnPropertyDescriptor(Object, 'getOwnPropertyDescriptor');
  2556. let _val_gOPD = _gOPD.value;
  2557. _gOPD.value = function(...args) {
  2558. let _res = _val_gOPD.apply(this, args);
  2559. if (args[0] instanceof Window && (args[1] === '$' || args[1] === 'jQuery')) {
  2560. delete _res.get;
  2561. delete _res.set;
  2562. _res.value = win[args[1]];
  2563. }
  2564. return _res;
  2565. };
  2566. Object.defineProperty(Object, 'getOwnPropertyDescriptor', _gOPD);
  2567. let getJQWrap = (n) => {
  2568. let name = n;
  2569. return {
  2570. enumerable: true,
  2571. get: x => _$[name],
  2572. set: x => {
  2573. if (_$_map.has(x)) {
  2574. _$[name] = _$_map.get(x);
  2575. return true;
  2576. }
  2577. if (x === _$.$ || x === _$.jQuery) {
  2578. _$[name] = x;
  2579. return true;
  2580. }
  2581. _$[name] = new Proxy(x, {
  2582. apply: (t, o, args) => {
  2583. let _res = t.apply(o, args);
  2584. if (_$_map.has(_res.is)) {
  2585. _res.is = _$_map.get(_res.is);
  2586. } else {
  2587. let _is = _res.is;
  2588. _res.is = function(...args) {
  2589. if (args[0] === ':hidden')
  2590. return false;
  2591. return _is.apply(this, args);
  2592. };
  2593. _$_map.set(_is, _res.is);
  2594. }
  2595. return _res;
  2596. }
  2597. });
  2598. _$_map.set(x, _$[name]);
  2599. return true;
  2600. }
  2601. };
  2602. };
  2603. Object.defineProperty(win, '$', getJQWrap('$'));
  2604. Object.defineProperty(win, 'jQuery', getJQWrap('jQuery'));
  2605. let _dP = Object.defineProperty;
  2606. Object.defineProperty = function(...args) {
  2607. if (args[0] instanceof Window && (args[1] === '$' || args[1] === 'jQuery'))
  2608. return void 0;
  2609. return _dP.apply(this, args);
  2610. };
  2611. })
  2612. };
  2613.  
  2614. scripts['igra-prestoloff.cx'] = () => scriptLander(() => {
  2615. let nt = new nullTools();
  2616. /*jslint evil: true */ // yes, evil, I know
  2617. let _write = document.write.bind(document);
  2618. /*jslint evil: false */
  2619. nt.define(document, 'write', t => {
  2620. let id = t.match(/jwplayer\("(\w+)"\)/i);
  2621. if (id && id[1]) {
  2622. return _write(`<div id="${id[1]}"></div>${t}`);
  2623. } else {
  2624. return _write('');
  2625. }
  2626. });
  2627. });
  2628.  
  2629. scripts['imageban.ru'] = {
  2630. now: () => {
  2631. Object.defineProperty(win, 'V7x1J', { get: () => null });
  2632. //preventPopunders();
  2633. }
  2634. };
  2635.  
  2636. scripts['kinopoisk.ru'] = {
  2637. now: () => {
  2638. // set no-branding body style
  2639. createStyle('body:not(#id) { background: #d5d5d5 url(/images/noBrandBg.jpg) 50% 0 no-repeat !important }');
  2640. },
  2641. dom: () => {
  2642. (style => style ? style.parentNode.removeChild(style) : console.log('Unable to locate branding style.')
  2643. )(_de.querySelector('#branding-style'));
  2644. }
  2645. };
  2646.  
  2647. scripts['korrespondent.net'] = {
  2648. now: () => scriptLander(() => {
  2649. let nt = new nullTools();
  2650. nt.define(win, 'holder', function(id) {
  2651. let div = document.getElementById(id);
  2652. if (!div)
  2653. return;
  2654. if (div.parentNode.classList.contains('col__sidebar')) {
  2655. div.parentNode.appendChild(div);
  2656. div.style.height = '300px';
  2657. }
  2658. });
  2659. }, nullTools),
  2660. dom: () => {
  2661. for (let frame of document.querySelectorAll('.unit-side-informer > iframe'))
  2662. frame.parentNode.style.width = '1px';
  2663. }
  2664. };
  2665.  
  2666. scripts['mail.ru'] = () => scriptLander(() => {
  2667. let nt = new nullTools();
  2668. // Trick to prevent mail.ru from removing 3rd-party styles
  2669. nt.define(Object.prototype, 'restoreVisibility', nt.func(null), false);
  2670. // Disable some of their counters
  2671. nt.define(win, 'rb_counter', nt.func(null, 'rb_counter'));
  2672. if (location.hostname !== 'e.mail.ru')
  2673. nt.define(win, 'createRadar', nt.func(nt.func(null, 'aRadar'), 'createRadar'));
  2674. else
  2675. nt.define(win, 'aRadar', nt.func(null, 'aRadar'));
  2676.  
  2677. // Disable page scrambler on mail.ru to let extensions easily block ads there
  2678. function defineLocator(root)
  2679. {
  2680. let _locator;
  2681. let fishnet = {
  2682. apply: (target, thisArg, args) => {
  2683. console.log(`locator.${target._name}(${JSON.stringify(args).slice(1,-1)})`);
  2684. return target.apply(thisArg, args);
  2685. }
  2686. };
  2687.  
  2688. function wrapLocator(locator)
  2689. {
  2690. if ('setup' in locator)
  2691. {
  2692. let _setup = locator.setup;
  2693. locator.setup = function(o)
  2694. {
  2695. if ('enable' in o)
  2696. {
  2697. o.enable = false;
  2698. console.log('Disable mimic mode.');
  2699. }
  2700. if ('links' in o)
  2701. {
  2702. o.links = [];
  2703. console.log('Call with empty list of sheets.');
  2704. }
  2705. return _setup.call(this, o);
  2706. };
  2707. locator.insertSheet = () => console.log('Ignore insertSheet.');
  2708. locator.wrap = () => console.log('Ignore wrap.');
  2709. }
  2710. try {
  2711. let names = [];
  2712. for (let name in locator)
  2713. if (locator[name] instanceof Function) {
  2714. locator[name]._name = name;
  2715. locator[name] = new Proxy(locator[name], fishnet);
  2716. names.push(name);
  2717. }
  2718. console.log(`[locator] wrapped properties: ${names.join(', ')}`);
  2719. } catch(e) {
  2720. console.log(e);
  2721. }
  2722. _locator = locator;
  2723. }
  2724.  
  2725. if ('locator' in root && root.locator)
  2726. {
  2727. console.log('Found existing "locator" object. :|');
  2728. _locator = root.locator;
  2729. wrapLocator(root.locator);
  2730. }
  2731.  
  2732. let loc_desc = Object.getOwnPropertyDescriptor(root, 'locator');
  2733. if (!loc_desc || loc_desc.set !== wrapLocator)
  2734. try {
  2735. Object.defineProperty(root, 'locator', {
  2736. set: wrapLocator,
  2737. get: () => _locator
  2738. });
  2739. } catch (err) {
  2740. console.log('Unable to redefine "locator" object!!!', err);
  2741. }
  2742. }
  2743.  
  2744. function defineDetector(mr)
  2745. {
  2746. let __ = mr._ || {};
  2747.  
  2748. if ('HONEYPOT' in __)
  2749. {
  2750. console.log('Disarming existing detector instance. :|', JSON.stringify(__));
  2751. nt.define(__, 'HONEYPOT', '.honeypot_fake_class_to_miss');
  2752. nt.define(__, 'STUCK_IN_POT', false);
  2753. }
  2754.  
  2755. __ = new Proxy(__, {
  2756. get: (t, p) => t[p],
  2757. set: (t, p, v) => {
  2758. console.log(`mr._.${p} =`, v);
  2759. if (['HONEYPOT', 'STUCK_IN_POT'].includes(p))
  2760. console.log('Not changed.');
  2761. t[p] = v; // setter in nt.define will prevent this when needed
  2762. return true;
  2763. }
  2764. });
  2765. Object.defineProperty(mr, '_', {
  2766. enumerable: true,
  2767. value: __
  2768. });
  2769. }
  2770.  
  2771. if (location.hostname === 'e.mail.ru')
  2772. defineLocator(win);
  2773. else {
  2774. try {
  2775. let _mr;
  2776. Object.defineProperty(win, 'mr', {
  2777. enumerable: true,
  2778. get: () => _mr,
  2779. set: (v) => {
  2780. if (v === _mr)
  2781. return true;
  2782. console.log('Trapped new "mr" object.');
  2783. defineLocator(v.mimic ? v.mimic : v);
  2784. defineDetector(v);
  2785. _mr = v;
  2786. }
  2787. });
  2788. if (!('mr' in win))
  2789. throw 'Wat!?';
  2790. } catch (e) {
  2791. console.log('Found existing "mr" object.', e instanceof TypeError ? '' : e);
  2792. defineLocator(win.mr);
  2793. defineDetector(win.mr);
  2794. }
  2795. }
  2796. }, nullTools);
  2797.  
  2798. scripts['megogo.net'] = {
  2799. now: () => {
  2800. let nt = new nullTools();
  2801. nt.define(win, 'adBlock', false);
  2802. nt.define(win, 'showAdBlockMessage', nt.func(null));
  2803. }
  2804. };
  2805.  
  2806. scripts['naruto-base.su'] = () => gardener('div[id^="entryID"],.block', /href="http.*?target="_blank"/i);
  2807.  
  2808. scripts['overclockers.ru'] = {
  2809. now: () => scriptLander(() => {
  2810. let _innerHTML = Object.getOwnPropertyDescriptor(_Element.prototype, 'innerHTML');
  2811. let _set_innerHTML = _innerHTML.set;
  2812. _innerHTML.set = function() {
  2813. if (this === document.body) {
  2814. console.log('Anti-Adblock killed.');
  2815. return true;
  2816. }
  2817. _set_innerHTML.apply(this, arguments);
  2818. };
  2819. Object.defineProperty(_Element.prototype, 'innerHTML', _innerHTML);
  2820. })
  2821. };
  2822. scripts['forums.overclockers.ru'] = {
  2823. now: () => {
  2824. createStyle('.needblock {position: fixed; left: -10000px}');
  2825. Object.defineProperty(win, 'adblck', {
  2826. get: () => 'no',
  2827. set: () => undefined,
  2828. enumerable: true
  2829. });
  2830. }
  2831. };
  2832.  
  2833. scripts['pb.wtf'] = {
  2834. other: ['piratbit.org', 'piratbit.ru'],
  2835. now: () => {
  2836. // line above topic content and images in the slider in the header
  2837. gardener(
  2838. 'a[href^="/exit/"], a[href^="/fxt/"], a[href$="=="]',
  2839. /img|Реклама|center/i,
  2840. { root: '.release-navbar,#page_content', observe: true, parent: 'div,tr' }
  2841. );
  2842. // ads in comments
  2843. gardener('img[data-name="PiraBo"]', /./i, {root:'#main_content .table', observe:true, parent:'tr'});
  2844. }
  2845. };
  2846.  
  2847. scripts['pikabu.ru'] = () => gardener('.story', /story__author[^>]+>ads</i, {root: '.inner_wrap', observe: true});
  2848.  
  2849. scripts['peka2.tv'] = () => {
  2850. let bodyClass = 'body--branding';
  2851. let checkNode = node => {
  2852. for (let className of node.classList)
  2853. if (className.includes('banner') || className === bodyClass) {
  2854. _removeAttribute.call(node, 'style');
  2855. node.classList.remove(className);
  2856. for (let attr of Array.from(node.attributes)) {
  2857. if (attr.name.startsWith('advert'))
  2858. _removeAttribute.call(node, attr.name);
  2859. }
  2860. }
  2861. };
  2862. (new MutationObserver(ms => {
  2863. let m, node;
  2864. for (m of ms) for (node of m.addedNodes)
  2865. if (node instanceof HTMLElement)
  2866. checkNode(node);
  2867. })).observe(_de, {childList: true, subtree: true});
  2868. (new MutationObserver(ms => {
  2869. for (let m of ms)
  2870. checkNode(m.target);
  2871. })).observe(_de, {attributes: true, subtree: true, attributeFilter: ['class']});
  2872. };
  2873.  
  2874. scripts['qrz.ru'] = {
  2875. now: () => {
  2876. let nt = new nullTools();
  2877. nt.define(win, 'ab', false);
  2878. nt.define(win, 'tryMessage', nt.func(null));
  2879. }
  2880. };
  2881.  
  2882. scripts['razlozhi.ru'] = {
  2883. now: () => {
  2884. for (let func of ['createShadowRoot', 'attachShadow'])
  2885. if (func in _Element.prototype)
  2886. _Element.prototype[func] = function(){ return this.cloneNode(); };
  2887. }
  2888. };
  2889.  
  2890. scripts['rbc.ru'] = {
  2891. dom: () => {
  2892. let _preventDefault = Event.prototype.preventDefault;
  2893. Event.prototype.preventDefault = function preventDefault()
  2894. {
  2895. let t = this.target;
  2896. if (t instanceof HTMLAnchorElement || t.closest('A'))
  2897. throw new Error('an.yandex redirect prevention');
  2898. return _preventDefault.call(this);
  2899. };
  2900.  
  2901. function cleaner(nodes)
  2902. {
  2903. for (let node of nodes)
  2904. {
  2905. if (!node.classList || !node.classList.contains('js-yandex-counter'))
  2906. continue;
  2907. node.classList.remove('js-yandex-counter');
  2908. node.removeAttribute('data-yandex-name');
  2909. node.removeAttribute('data-yandex-params');
  2910. }
  2911. }
  2912. cleaner(_de.querySelectorAll('.js-yandex-counter'));
  2913.  
  2914. (new MutationObserver(
  2915. ms => { for (let m of ms) cleaner(m.addedNodes); }
  2916. )).observe(_de, {childList: true, subtree: true});
  2917. }
  2918. };
  2919.  
  2920. scripts['rp5.ru'] = {
  2921. other: ['rp5.by', 'rp5.kz', 'rp5.ua'],
  2922. now: () => gardener('div[id][class]', /\?AdvertMgmt=|adsbygoogle/, { root: '#content-wrapper', log: true })
  2923. };
  2924.  
  2925. scripts['rutube.ru'] = () => scriptLander(() => {
  2926. let _parse = JSON.parse.bind(JSON);
  2927. let _skip_enabled = false;
  2928. JSON.parse = (...args) => {
  2929. let res = _parse(...args),
  2930. log = false;
  2931. if (!res)
  2932. return res;
  2933. // parse player configuration
  2934. if ('appearance' in res || 'video_balancer' in res) {
  2935. log = true;
  2936. if ('appearance' in res) {
  2937. res.appearance.forbid_seek = false;
  2938. res.appearance.forbid_timeline_preview = false;
  2939. }
  2940. _skip_enabled = !!res.remove_unseekable_blocks;
  2941. res.advert = [];
  2942. for (let limit of res.limits)
  2943. limit.limit = 0;
  2944. res.yast = null;
  2945. res.yast_live_online = null;
  2946. Object.defineProperty(res, 'stat', {
  2947. get: x => [],
  2948. set: x => true,
  2949. enumerable: true
  2950. });
  2951. }
  2952.  
  2953. // parse video configuration
  2954. if ('video_url' in res) {
  2955. log = true;
  2956. if ('cuepoints' in res && !_skip_enabled)
  2957. for (let point of res.cuepoints) {
  2958. point.is_pause = false;
  2959. point.show_navigation = true;
  2960. point.forbid_seek = false;
  2961. }
  2962. }
  2963.  
  2964. if (log)
  2965. console.log('[rutube]', res);
  2966. return res;
  2967. };
  2968. });
  2969.  
  2970. scripts['simpsonsua.com.ua'] = () => scriptLander(() => {
  2971. let _addEventListener = Object.getPrototypeOf(HTMLDocument).prototype.addEventListener;
  2972. document.addEventListener = function(event, callback) {
  2973. if (event === 'DOMContentLoaded' && callback.toString().includes('show_warning'))
  2974. return;
  2975. return _addEventListener.apply(this, arguments);
  2976. };
  2977. });
  2978.  
  2979. scripts['spaces.ru'] = () => {
  2980. gardener('div:not(.f-c_fll) > a[href*="spaces.ru/?Cl="]', /./, { parent: 'div' });
  2981. gardener('.js-banner_rotator', /./, { parent: '.widgets-group' });
  2982. };
  2983.  
  2984. scripts['spam-club.blogspot.co.uk'] = () => {
  2985. let _clientHeight = Object.getOwnPropertyDescriptor(_Element.prototype, 'clientHeight'),
  2986. _clientWidth = Object.getOwnPropertyDescriptor(_Element.prototype, 'clientWidth');
  2987. let wrapGetter = (getter) => {
  2988. let _getter = getter;
  2989. return function()
  2990. {
  2991. let _size = _getter.apply(this, arguments);
  2992. return _size ? _size : 1;
  2993. };
  2994. };
  2995. _clientHeight.get = wrapGetter(_clientHeight.get);
  2996. _clientWidth.get = wrapGetter(_clientWidth.get);
  2997. Object.defineProperty(_Element.prototype, 'clientHeight', _clientHeight);
  2998. Object.defineProperty(_Element.prototype, 'clientWidth', _clientWidth);
  2999. let _onload = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'onload'),
  3000. _set_onload = _onload.set;
  3001. _onload.set = function()
  3002. {
  3003. if (this instanceof HTMLImageElement)
  3004. return true;
  3005. _set_onload.apply(this, arguments);
  3006. };
  3007. Object.defineProperty(HTMLElement.prototype, 'onload', _onload);
  3008. };
  3009.  
  3010. scripts['sport-express.ru'] = () => gardener('.js-relap__item',/>Реклама\s+<\//, {root:'.container', observe: true});
  3011.  
  3012. scripts['sports.ru'] = {
  3013. now: () => {
  3014. gardener('.aside-news-list__item', /aside-news-list__advert/i, {root:'.columns-layout__left', observe: true});
  3015. gardener('.material-list__item', /Реклама/i, {root:'.columns-layout', observe: true});
  3016. // extra functionality: shows/hides panel at the top depending on scroll direction
  3017. createStyle([
  3018. '.user-panel__fixed { transition: top 0.2s ease-in-out!important; }',
  3019. '.user-panel-up { top: -40px!important }'
  3020. ], {id: 'userPanelSlide'}, false);
  3021. },
  3022. dom: () => {
  3023. (function lookForPanel()
  3024. {
  3025. let panel = document.querySelector('.user-panel__fixed');
  3026. if (!panel)
  3027. setTimeout(lookForPanel, 100);
  3028. else
  3029. window.addEventListener(
  3030. 'wheel', function(e)
  3031. {
  3032. if (e.deltaY > 0 && !panel.classList.contains('user-panel-up'))
  3033. panel.classList.add('user-panel-up');
  3034. else if (e.deltaY < 0 && panel.classList.contains('user-panel-up'))
  3035. panel.classList.remove('user-panel-up');
  3036. }, false
  3037. );
  3038. })();
  3039. }
  3040. };
  3041.  
  3042. scripts['stealthz.ru'] = {
  3043. dom: () => {
  3044. // skip timeout
  3045. let $ = document.querySelector.bind(document);
  3046. let [timer_1, timer_2] = [$('#timer_1'), $('#timer_2')];
  3047. if (!timer_1 || !timer_2)
  3048. return;
  3049. timer_1.style.display = 'none';
  3050. timer_2.style.display = 'block';
  3051. }
  3052. };
  3053.  
  3054. scripts['yap.ru'] = {
  3055. other: ['yaplakal.com'],
  3056. now: () => {
  3057. gardener('form > table[id^="p_row_"]:nth-of-type(2)', /member1438|Administration/);
  3058. gardener('.icon-comments', /member1438|Administration|\/go\/\?http/, {parent:'tr', siblings:-2});
  3059. }
  3060. };
  3061.  
  3062. scripts['rambler.ru'] = {
  3063. other: ['championat.com','gazeta.ru','media.eagleplatform.com','lenta.ru', 'quto.ru'],
  3064. now: () => scriptLander(() => {
  3065. // Prevent autoplay
  3066. if (!('EaglePlayer' in win)) {
  3067. let _EaglePlayer = void 0;
  3068. Object.defineProperty(win, 'EaglePlayer', {
  3069. enumerable: true,
  3070. get: x => _EaglePlayer,
  3071. set: x => {
  3072. if (x === _EaglePlayer)
  3073. return true;
  3074. _EaglePlayer = x;
  3075. let _init = void 0;
  3076. Object.defineProperty(_EaglePlayer.prototype, 'init', {
  3077. enumerable: true,
  3078. set: x => _init = x,
  3079. get: function() {
  3080. let _self = this;
  3081. if (_self.options) {
  3082. Object.defineProperty(this.options, 'autoplay', {
  3083. enumerable: true,
  3084. get: x => false,
  3085. set: x => null
  3086. });
  3087. }
  3088. if (_self.options && _self.options.el && inIFrame) {
  3089. let addListener = (player) => {
  3090. console.log('Attached autostop');
  3091. player.addEventListener('canplay', e => {
  3092. e.target.play = () => console.log('Applied autostop.');
  3093. setTimeout(player => {
  3094. delete player.play;
  3095. console.log('Detached autostop');
  3096. }, 1500, e.target);
  3097. }, false);
  3098. };
  3099. (new MutationObserver(ms => {
  3100. let m, node;
  3101. for (m of ms) for (node of m.addedNodes)
  3102. if (node instanceof HTMLVideoElement)
  3103. addListener(node);
  3104. })).observe(this.options.el, { childList: true, subtree: true });
  3105. }
  3106. return _init;
  3107. }
  3108. });
  3109. }
  3110. });
  3111. let _setAttribute = _Element.prototype.setAttribute;
  3112. let isAutoplay = /^autoplay$/i;
  3113. _Element.prototype.setAttribute = function setAttribute(name)
  3114. {
  3115. if (!this._stopped && isAutoplay.test(name))
  3116. {
  3117. console.log('Prevented assigning autoplay attribute.');
  3118. return null;
  3119. }
  3120. return _setAttribute.apply(this, arguments);
  3121. };
  3122. } else if (inIFrame) {
  3123. let _setAttribute = _Element.prototype.setAttribute;
  3124. let isAutoplay = /^autoplay$/i;
  3125. _Element.prototype.setAttribute = function setAttribute(name)
  3126. {
  3127. if (!this._stopped && isAutoplay.test(name))
  3128. {
  3129. console.log('Prevented assigning autoplay attribute.');
  3130. this._stopped = true;
  3131. this.play = () => {
  3132. console.log('Prevented attempt to force-start playback.');
  3133. delete this.play;
  3134. };
  3135. return null;
  3136. }
  3137. return _setAttribute.apply(this, arguments);
  3138. };
  3139. }
  3140. if (location.hostname.endsWith('.media.eagleplatform.com'))
  3141. return;
  3142. let CSSRuleProto = 'cssText' in CSSRule.prototype ? CSSRule.prototype : CSSStyleRule.prototype;
  3143. let _cssText = Object.getOwnPropertyDescriptor(CSSRuleProto, 'cssText');
  3144. let _cssText_get = _cssText.get;
  3145. _cssText.configurable = false;
  3146. _cssText.get = function()
  3147. {
  3148. let cssText = _cssText_get.call(this);
  3149. if (cssText.includes('content:'))
  3150. {
  3151. console.log('Blocked access to suspicious cssText:', cssText.slice(0,60), '\u2026', cssText.length);
  3152. return null;
  3153. }
  3154. return cssText;
  3155. };
  3156. Object.defineProperty(CSSRuleProto, 'cssText', _cssText);
  3157. // fake global Adf object
  3158. let nt = new nullTools();
  3159. let Adf_banner = {};
  3160. [
  3161. 'reloadssp', 'sspScroll',
  3162. 'sspRich', 'ssp'
  3163. ].forEach(name => Adf_banner[name] = nt.proxy(() => new Promise((r,j) => r({status: true}))));
  3164. nt.define(win, 'Adf', nt.proxy({
  3165. banner: nt.proxy(Adf_banner)
  3166. }));
  3167. // extra script to remove partner news on gazeta.ru
  3168. if (!location.hostname.includes('gazeta.ru'))
  3169. return;
  3170. (new MutationObserver(
  3171. (ms) => {
  3172. let m, node, header;
  3173. for (m of ms) for (node of m.addedNodes)
  3174. if (node instanceof HTMLDivElement && node.matches('.sausage'))
  3175. {
  3176. header = node.querySelector('.sausage-header');
  3177. if (header && /новости\s+партн[её]ров/i.test(header.textContent))
  3178. node.style.display = 'none';
  3179. }
  3180. }
  3181. )).observe(document.documentElement, { childList:true, subtree: true });
  3182. }, `let inIFrame = ${inIFrame}`, nullTools)
  3183. };
  3184.  
  3185. scripts['reactor.cc'] = {
  3186. other: ['joyreactor.cc', 'pornreactor.cc'],
  3187. now: () => {
  3188. selectiveEval();
  3189. scriptLander(() => {
  3190. let nt = new nullTools();
  3191. win.open = (function(){ throw new Error('Redirect prevention.'); }).bind(window);
  3192. nt.define(win, 'Worker', function(){});
  3193. nt.define(win, 'JRCH', win.CoinHive);
  3194. }, nullTools);
  3195. },
  3196. click: function(e)
  3197. {
  3198. let node = e.target;
  3199. if (node.nodeType === _Node.ELEMENT_NODE &&
  3200. node.style.position === 'absolute' &&
  3201. node.style.zIndex > 0)
  3202. node.parentNode.removeChild(node);
  3203. },
  3204. dom: function()
  3205. {
  3206. let words = new RegExp(
  3207. 'блокировщик рекламы'
  3208. .split('')
  3209. .map(function(e){return e+'[\u200b\u200c\u200d]*';})
  3210. .join('')
  3211. .replace(' ', '\\s*')
  3212. .replace(/[аоре]/g, function(e){return ['[аa]','[оo]','[рp]','[еe]']['аоре'.indexOf(e)];}),
  3213. 'i'),
  3214. can;
  3215. function deeper(spider)
  3216. {
  3217. let c, l, n;
  3218. if (words.test(spider.innerText))
  3219. {
  3220. if (spider.nodeType === _Node.TEXT_NODE)
  3221. return true;
  3222. c = spider.childNodes;
  3223. l = c.length;
  3224. n = 0;
  3225. while(l--)
  3226. if (deeper(c[l]), can)
  3227. n++;
  3228. if (n > 0 && n === c.length && spider.offsetHeight < 750)
  3229. can.push(spider);
  3230. return false;
  3231. }
  3232. return true;
  3233. }
  3234. function probe()
  3235. {
  3236. if (words.test(document.body.innerText))
  3237. {
  3238. can = [];
  3239. deeper(document.body);
  3240. let i = can.length, spider;
  3241. while(i--) {
  3242. spider = can[i];
  3243. if (spider.offsetHeight > 10 && spider.offsetHeight < 750)
  3244. _setAttribute.call(spider, 'style', 'background:none!important');
  3245. }
  3246. }
  3247. }
  3248. (new MutationObserver(probe))
  3249. .observe(document, { childList:true, subtree:true });
  3250. }
  3251. };
  3252.  
  3253. scripts['auto.ru'] = () => {
  3254. let words = /Реклама|Яндекс.Директ|yandex_ad_/;
  3255. let userAdsListAds = (
  3256. '.listing-list > .listing-item,'+
  3257. '.listing-item_type_fixed.listing-item'
  3258. );
  3259. let catalogAds = (
  3260. 'div[class*="layout_catalog-inline"],'+
  3261. 'div[class$="layout_horizontal"]'
  3262. );
  3263. let otherAds = (
  3264. '.advt_auto,'+
  3265. '.sidebar-block,'+
  3266. '.pager-listing + div[class],'+
  3267. '.card > div[class][style],'+
  3268. '.sidebar > div[class],'+
  3269. '.main-page__section + div[class],'+
  3270. '.listing > tbody'
  3271. );
  3272. gardener(userAdsListAds, words, {root:'.listing-wrap', observe:true});
  3273. gardener(catalogAds, words, {root:'.catalog__page,.content__wrapper', observe:true});
  3274. gardener(otherAds, words);
  3275. };
  3276.  
  3277. scripts['rsload.net'] = {
  3278. load: () => {
  3279. let dis = document.querySelector('label[class*="cb-disable"]');
  3280. if (dis)
  3281. dis.click();
  3282. },
  3283. click: () => {
  3284. let t = e.target;
  3285. if (t && t.href && (/:\/\/\d+\.\d+\.\d+\.\d+\//.test(t.href)))
  3286. t.href = t.href.replace('://','://rsload.net:rsload.net@');
  3287. }
  3288. };
  3289.  
  3290. let domain;
  3291. // add alternative domain names if present and wrap functions into objects
  3292. for (let name in scripts)
  3293. {
  3294. if (scripts[name] instanceof Function)
  3295. scripts[name] = { now: scripts[name] };
  3296. for (domain of (scripts[name].other||[]))
  3297. {
  3298. if (domain in scripts)
  3299. console.log('Error in scripts list. Script for', name, 'replaced script for', domain);
  3300. scripts[domain] = scripts[name];
  3301. }
  3302. delete scripts[name].other;
  3303. }
  3304. // look for current domain in the list and run appropriate code
  3305. domain = document.domain;
  3306. while (domain.indexOf('.') > -1)
  3307. {
  3308. if (domain in scripts) for (let when in scripts[domain])
  3309. switch(when)
  3310. {
  3311. case 'now':
  3312. scripts[domain][when]();
  3313. break;
  3314. case 'dom':
  3315. document.addEventListener('DOMContentLoaded', scripts[domain][when], false);
  3316. break;
  3317. default:
  3318. document.addEventListener (when, scripts[domain][when], false);
  3319. }
  3320. domain = domain.slice(domain.indexOf('.') + 1);
  3321. }
  3322.  
  3323. // Batch script lander
  3324. if (!skipLander)
  3325. landScript(batchLand, batchPrepend);
  3326.  
  3327. { // JS Fixes Tools Menu
  3328. let openOptions = function()
  3329. {
  3330. let ovl = _createElement('div'),
  3331. inner = _createElement('div');
  3332. ovl.style = (
  3333. 'position: fixed;'+
  3334. 'top:0; left:0;'+
  3335. 'bottom: 0; right: 0;'+
  3336. 'background: rgba(0,0,0,0.85);'+
  3337. 'z-index: 2147483647;'+
  3338. 'padding: 5em'
  3339. );
  3340. inner.style = (
  3341. 'background: whitesmoke;'+
  3342. 'font-size: 10pt;'+
  3343. 'color: black;'+
  3344. 'padding: 1em'
  3345. );
  3346. inner.textContent = 'JS Fixes Tools';
  3347. inner.appendChild(_createElement('br'));
  3348. inner.appendChild(_createElement('br'));
  3349. ovl.addEventListener(
  3350. 'click', function(e)
  3351. {
  3352. if (e.target === ovl) {
  3353. ovl.parentNode.removeChild(ovl);
  3354. e.preventDefault();
  3355. }
  3356. e.stopPropagation();
  3357. }, false
  3358. );
  3359.  
  3360. let sObjBtn = _createElement('button');
  3361. sObjBtn.onclick = getStrangeObjectsList;
  3362. sObjBtn.textContent = 'Print (in console) list of unusual window properties';
  3363. inner.appendChild(_createElement('br'));
  3364. inner.appendChild(sObjBtn);
  3365.  
  3366. document.body.appendChild(ovl);
  3367. ovl.appendChild(inner);
  3368. };
  3369.  
  3370. // monitor keys pressed for Ctrl+Alt+Shift+J > s > f code
  3371. let opPos = 0, opKey = ['KeyJ','KeyS','KeyF'];
  3372. document.addEventListener(
  3373. 'keydown', function(e)
  3374. {
  3375. if ((e.code === opKey[opPos] || e.location) &&
  3376. (!!opPos || e.altKey && e.ctrlKey && e.shiftKey))
  3377. {
  3378. opPos += e.location ? 0 : 1;
  3379. e.stopPropagation();
  3380. e.preventDefault();
  3381. } else {
  3382. opPos = 0;
  3383. }
  3384. if (opPos === opKey.length)
  3385. {
  3386. opPos = 0;
  3387. openOptions();
  3388. }
  3389. }, false
  3390. );
  3391. }
  3392. })();