RU AdList JS Fixes

try to take over the world!

当前为 2018-10-24 提交的版本,查看 最新版本

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