RU AdList JS Fixes

try to take over the world!

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

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