RU AdList JS Fixes

try to take over the world!

当前为 2018-02-26 提交的版本,查看 最新版本

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