Greasy Fork 还支持 简体中文。

RU AdList JS Fixes

try to take over the world!

目前為 2018-09-19 提交的版本,檢視 最新版本

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