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 20180225.2
  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 window,
  37. ifFirefoxUnder58 = isFirefox && 'StopIteration' in window,
  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. if (/Maxthon/.test(navigator.appVersion) || 'InstallTrigger' in window && 'StopIteration' in window ) {
  749. win.WebSocket = new Proxy(win.WebSocket, {
  750. construct: (ws, args) => {
  751. if (isBlocked(args[0])) {
  752. console.log('[WSI] Blocked WS connection:', args[0]);
  753. return {};
  754. }
  755. return new ws(...args);
  756. }
  757. });
  758. }
  759. });
  760.  
  761. if (!isFirefox)
  762. { // scripts for non-Firefox browsers
  763. // https://greasyfork.org/scripts/14720-it-s-not-important
  764. {
  765. let imptt = /((display|(margin|padding)(-top|-bottom)?)\s*:[^;!]*)!\s*important/ig,
  766. ret_b = (a,b) => b,
  767. _toLowerCase = String.prototype.toLowerCase,
  768. protectedNodes = new WeakSet(),
  769. log = false;
  770.  
  771. let logger = function()
  772. {
  773. if (log)
  774. console.log('Some page elements became a bit less important.');
  775. log = false;
  776. };
  777.  
  778. let unimportanter = function(node)
  779. {
  780. let style = (node.nodeType === _Node.ELEMENT_NODE) ?
  781. _getAttribute.call(node, 'style') : null;
  782.  
  783. if (!style || !imptt.test(style) || node.style.display === 'none' ||
  784. (node.src && node.src.slice(0,17) === 'chrome-extension:')) // Web of Trust IFRAME and similar
  785. return false; // get out if we have nothing to do here
  786.  
  787. protectedNodes.add(node);
  788. _setAttribute.call(node, 'style',
  789. style.replace(imptt, ret_b));
  790. log = true;
  791. };
  792.  
  793. (new MutationObserver(
  794. function(mutations)
  795. {
  796. setTimeout(
  797. function(ms)
  798. {
  799. let m, node;
  800. for (m of ms) for (node of m.addedNodes)
  801. unimportanter(node);
  802. logger();
  803. }, 0, mutations
  804. );
  805. }
  806. )).observe(document, {
  807. childList : true,
  808. subtree : true
  809. });
  810.  
  811. Element.prototype.setAttribute = function setAttribute(name, value)
  812. {
  813. "[native code]";
  814. let replaced = value;
  815. if (_toLowerCase.call(name) === 'style' && protectedNodes.has(this))
  816. replaced = value.replace(imptt, ret_b);
  817. log = (replaced !== value);
  818. logger();
  819. return _setAttribute.call(this, name, replaced);
  820. };
  821.  
  822. win.addEventListener (
  823. 'load', function()
  824. {
  825. for (let imp of document.querySelectorAll('[style*="!"]'))
  826. unimportanter(imp);
  827. logger();
  828. }, false
  829. );
  830. }
  831.  
  832. // Naive ABP Style protector
  833. {
  834. let _querySelector = _Document.prototype.querySelector.bind(document);
  835. let _removeChild = _Node.prototype.removeChild;
  836. let _appendChild = _Node.prototype.appendChild;
  837. let createShadow = () => _createElement('shadow');
  838. // Prevent adding fake content entry point
  839. _Node.prototype.appendChild = function(child)
  840. {
  841. if (this instanceof ShadowRoot &&
  842. child instanceof HTMLContentElement)
  843. return _appendChild.call(this, createShadow());
  844. return _appendChild.apply(this, arguments);
  845. };
  846. {
  847. let _shadowSelector = ShadowRoot.prototype.querySelector;
  848. let _innerHTML = Object.getOwnPropertyDescriptor(ShadowRoot.prototype, 'innerHTML');
  849. let _parentNode = Object.getOwnPropertyDescriptor(_Node.prototype, 'parentNode');
  850. if (_innerHTML && _parentNode)
  851. {
  852. let _set = _innerHTML.set;
  853. let _getParent = _parentNode.get;
  854. _innerHTML.configurable = false;
  855. _innerHTML.set = function()
  856. {
  857. _set.apply(this, arguments);
  858. let content = _shadowSelector.call(this, 'content');
  859. if (content)
  860. {
  861. let parent = _getParent.call(content);
  862. _removeChild.call(parent, content);
  863. _appendChild.call(parent, createShadow());
  864. }
  865. };
  866. }
  867. Object.defineProperty(ShadowRoot.prototype, 'innerHTML', _innerHTML);
  868. }
  869. // Locate and apply extra protection to a style on top of what ABP does
  870. let style;
  871. (new Promise(
  872. function(resolve, reject)
  873. {
  874. let getStyle = () => _querySelector('::shadow style');
  875. style = getStyle();
  876. if (style)
  877. return resolve(style);
  878. let intv = setInterval(
  879. function()
  880. {
  881. style = getStyle();
  882. if (!style)
  883. return;
  884. intv = clearInterval(intv);
  885. return resolve(style);
  886. }, 0
  887. );
  888. document.addEventListener(
  889. 'DOMContentLoaded',
  890. function()
  891. {
  892. if (intv)
  893. clearInterval(intv);
  894. style = getStyle();
  895. return style ? resolve(style) : reject();
  896. },
  897. false
  898. );
  899. }
  900. )).then(
  901. function(style)
  902. {
  903. let emptyArr = [],
  904. nullStr = {
  905. get: () => '',
  906. set: () => undefined
  907. };
  908. let shadow = style.parentNode;
  909. Object.defineProperties(shadow, {
  910. childElementCount: { value: 0 },
  911. styleSheets: { value: emptyArr },
  912. firstChild: { value: null },
  913. firstElementChild: { value: null },
  914. lastChild: { value: null },
  915. lastElementChild: { value: null },
  916. childNodes: { value: emptyArr },
  917. children: { value: emptyArr },
  918. innerHTML: { value: nullStr },
  919. });
  920. Object.defineProperties(style, {
  921. innerHTML: { value: nullStr },
  922. textContent: { value: nullStr },
  923. ownerDocument: { value: null },
  924. parentNode: {value: null },
  925. previousElementSibling: { value: null },
  926. previousSibling: { value: null },
  927. disabled: { get: () => true, set: x => null }
  928. });
  929. Object.defineProperties(style.sheet, {
  930. deleteRule: { value: () => null },
  931. disabled: { get: () => true, set: x => null },
  932. cssRules: { value: emptyArr },
  933. rules: { value: emptyArr }
  934. });
  935. }
  936. ).catch(()=>null);
  937. _Node.prototype.removeChild = function(child)
  938. {
  939. if (child === style)
  940. return;
  941. return _removeChild.apply(this, arguments);
  942. };
  943. }
  944. }
  945. if (/^https?:\/\/(mail\.yandex\.|music\.yandex\.|news\.yandex\.|(www\.)?yandex\.[^\/]+\/(yand)?search[\/?])/i.test(win.location.href) ||
  946. /^https?:\/\/tv\.yandex\./i.test(win.location.href))
  947. {
  948. // https://greasyfork.org/en/scripts/809-no-yandex-ads
  949. let yadWord = /Яндекс.Директ/i,
  950. adWords = /Реклама|Ad/i;
  951. let _querySelector = document.querySelector.bind(document),
  952. _querySelectorAll = document.querySelectorAll.bind(document),
  953. _getAttribute = Element.prototype.getAttribute,
  954. _setAttribute = Element.prototype.setAttribute;
  955. // Function to attach an observer to monitor dynamic changes on the page
  956. let pageUpdateObserver = (func, obj, params) => {
  957. if (obj)
  958. (new MutationObserver(func))
  959. .observe(obj, (params || { childList:true, subtree:true }));
  960. };
  961. // Short name for parentNode.removeChild
  962. let remove = (node) => {
  963. if (!node || !node.parentNode)
  964. return false;
  965. console.log('Removed node.');
  966. node.parentNode.removeChild(node);
  967. };
  968. // Yandex search ads in Google Chrome
  969. if ('attachShadow' in Element.prototype)
  970. {
  971. let _attachShadow = Element.prototype.attachShadow;
  972. Element.prototype.attachShadow = function()
  973. {
  974. let node = this,
  975. root = _attachShadow.apply(node, arguments);
  976. pageUpdateObserver(
  977. (ms) => {
  978. for (let m of ms) if (m.addedNodes.length)
  979. if (adWords.test(root.textContent))
  980. remove(node.closest('.serp-item'));
  981. }, root
  982. );
  983. return root;
  984. };
  985. }
  986. // prevent/defuse adblock detector
  987. setInterval(()=>{
  988. localStorage.ic = '';
  989. localStorage._mt__data = '';
  990. },100);
  991. let _doc_proto = ('cookie' in _Document.prototype) ? _Document.prototype : Object.getPrototypeOf(document);
  992. let _cookie = Object.getOwnPropertyDescriptor(_doc_proto, 'cookie');
  993. if (_cookie)
  994. {
  995. let _set_cookie = Function.prototype.call.bind(_cookie.set);
  996. _cookie.set = function(value)
  997. {
  998. if (/^(mda=|yp=|ys=|yabs-|__)/.test(value))
  999. {
  1000. // remove value, set expired
  1001. if (!value.startsWith('yp=')) {
  1002. value = value.replace(/^([^=]+=)[^;]+/,'$1').replace(/(expires=)[\w\s\d,]+/,'$1Thu, 01 Jan 1970 00');
  1003. console.log('expire cookie', value.match(/^[^=]+/)[0]);
  1004. } else {
  1005. let parts = value.split(';');
  1006. let values = parts[0].split('#').filter(part => /\.sp\./.test(part));
  1007. if (values.length)
  1008. values[0] = values[0].replace(/^yp=/, '');
  1009. parts[0] = `yp=${values.join('#')}`;
  1010. value = parts.join(';');
  1011. console.log(`set cookie ${parts[0]}`);
  1012. }
  1013. //return null;
  1014. }
  1015. return _set_cookie(this, value);
  1016. };
  1017. Object.defineProperty(_doc_proto, 'cookie', _cookie);
  1018. }
  1019. // other ads
  1020. document.addEventListener(
  1021. 'DOMContentLoaded', function()
  1022. {
  1023. { // Generic ads removal and fixes
  1024. let node = _querySelector('.serp-header');
  1025. if (node)
  1026. node.style.marginTop = '0';
  1027. for (node of _querySelectorAll(
  1028. '.serp-adv__head + .serp-item,'+
  1029. '#adbanner,'+
  1030. '.serp-adv,'+
  1031. '.b-spec-adv,'+
  1032. 'div[class*="serp-adv__"]:not(.serp-adv__found):not(.serp-adv__displayed)'
  1033. )) remove(node);
  1034. }
  1035. // Search ads
  1036. function removeSearchAds()
  1037. {
  1038. for (let node of _querySelectorAll('.serp-item'))
  1039. if (_getAttribute.call(node, 'role') === 'complementary' ||
  1040. adWords.test((node.querySelector('.label')||{}).textContent))
  1041. remove(node);
  1042. }
  1043. // News ads
  1044. function removeNewsAds()
  1045. {
  1046. let node, block, item, items, mask, classes,
  1047. masks = [
  1048. { class: '.ads__wrapper', regex: /[^,]*?,[^,]*?\.ads__wrapper/ },
  1049. { class: '.ads__pool', regex: /[^,]*?,[^,]*?\.ads__pool/ }
  1050. ];
  1051. for (node of _querySelectorAll('style[nonce]'))
  1052. {
  1053. classes = node.innerText.replace(/\{[^}]+\}+/ig, '|').split('|');
  1054. for (block of classes) for (mask of masks)
  1055. if (block.includes(mask.class))
  1056. {
  1057. block = block.match(mask.regex)[0];
  1058. items = _querySelectorAll(block);
  1059. for (item of items)
  1060. remove(items[0]);
  1061. }
  1062. }
  1063. }
  1064. // Music ads
  1065. function removeMusicAds()
  1066. {
  1067. for (let node of _querySelectorAll('.ads-block'))
  1068. remove(node);
  1069. }
  1070. // Mail ads
  1071. function removeMailAds()
  1072. {
  1073. let slice = Array.prototype.slice,
  1074. nodes = slice.call(_querySelectorAll('.ns-view-folders')),
  1075. node, len, cls;
  1076.  
  1077. for (node of nodes)
  1078. if (!len || len > node.classList.length)
  1079. len = node.classList.length;
  1080.  
  1081. node = nodes.pop();
  1082. while (node)
  1083. {
  1084. if (node.classList.length > len)
  1085. for (cls of slice.call(node.classList))
  1086. if (cls.indexOf('-') === -1)
  1087. {
  1088. remove(node);
  1089. break;
  1090. }
  1091. node = nodes.pop();
  1092. }
  1093. }
  1094. // News fixes
  1095. function removePageAdsClass()
  1096. {
  1097. if (document.body.classList.contains("b-page_ads_yes"))
  1098. {
  1099. document.body.classList.remove("b-page_ads_yes");
  1100. console.log('Page ads class removed.');
  1101. }
  1102. }
  1103. // TV fixes
  1104. function removeTVAds()
  1105. {
  1106. for (let node of _querySelectorAll('div[class^="_"][data-reactid] > div'))
  1107. if (yadWord.test(node.textContent) || node.querySelector('iframe:not([src])'))
  1108. {
  1109. if (node.offsetWidth)
  1110. {
  1111. let pad = document.createElement('div');
  1112. _setAttribute.call(pad, 'style', `width:${node.offsetWidth}px`);
  1113. node.parentNode.appendChild(pad);
  1114. }
  1115. remove(node);
  1116. }
  1117. }
  1118.  
  1119. if (location.hostname.startsWith('mail.')) {
  1120. pageUpdateObserver(
  1121. function(ms, o)
  1122. {
  1123. let aside = _querySelector('.mail-Layout-Aside');
  1124. if (aside) {
  1125. o.disconnect();
  1126. pageUpdateObserver(removeMailAds, aside);
  1127. }
  1128. }, document.body
  1129. );
  1130. removeMailAds();
  1131. } else if (location.hostname.startsWith('music.')) {
  1132. pageUpdateObserver(removeMusicAds, _querySelector('.sidebar'));
  1133. removeMusicAds();
  1134. } else if (location.hostname.startsWith('news.')) {
  1135. pageUpdateObserver(removeNewsAds, document.body);
  1136. pageUpdateObserver(removePageAdsClass, document.body, { attributes:true, attributesFilter:['class'] });
  1137. removeNewsAds();
  1138. removePageAdsClass();
  1139. } else if (location.hostname.startsWith('tv.')) {
  1140. pageUpdateObserver(removeTVAds, document.body);
  1141. removeTVAds();
  1142. } else {
  1143. pageUpdateObserver(removeSearchAds, _querySelector('.main__content'));
  1144. removeSearchAds();
  1145. }
  1146. }
  1147. );
  1148. }
  1149.  
  1150. // Yandex Link Tracking
  1151. if (/^https?:\/\/([^.]+\.)*yandex\.[^\/]+/i.test(win.location.href))
  1152. {
  1153. // remove banner on the start page
  1154. scriptLander(() => {
  1155. let nt = new nullTools({log: false, trace: true});
  1156. let AwapsJsonAPI_Json_prototype = {};
  1157. let AwapsJsonAPI_Json = function(...args) {
  1158. console.log('>> new AwapsJsonAPI.Json(', ...args, ')');
  1159. };
  1160. [
  1161. 'setID', 'addImageContent',
  1162. 'sendCounts', 'expand', 'refreshAd'
  1163. ].forEach(name => AwapsJsonAPI_Json.prototype[name] = nt.proxy(nt.func(null, name)));
  1164. AwapsJsonAPI_Json.prototype.checkBannerVisibility = nt.proxy(nt.func(true, 'checkBannerVisibility'));
  1165. AwapsJsonAPI_Json.prototype.addIframeContent = nt.proxy(function(...args) {
  1166. try {
  1167. let frame = args[1][0].parentNode;
  1168. frame.parentNode.removeChild(frame);
  1169. console.log(`Removed banner placeholder.`);
  1170. } catch(ignore) {
  1171. console.log(`Can't locate frame object to remove.`);
  1172. }
  1173. });
  1174. AwapsJsonAPI_Json.prototype.getHTML = nt.proxy(nt.func('', 'getHTML'));
  1175. AwapsJsonAPI_Json.prototype = nt.proxy(AwapsJsonAPI_Json.prototype);
  1176. AwapsJsonAPI_Json = nt.proxy(AwapsJsonAPI_Json);
  1177. if ('AwapsJsonAPI' in win) {
  1178. console.log('Oops! AwapsJsonAPI already defined.');
  1179. let f = win.AwapsJsonAPI.Json;
  1180. win.AwapsJsonAPI.Json = AwapsJsonAPI_Json;
  1181. if (f && f.prototype)
  1182. f.prototype = AwapsJsonAPI_Json.prototype;
  1183. } else {
  1184. nt.define(win, 'AwapsJsonAPI', nt.proxy({
  1185. Json: AwapsJsonAPI_Json
  1186. }));
  1187. }
  1188.  
  1189. let home = win.home || {};
  1190. let parseExport = x => {
  1191. if (!x)
  1192. return x;
  1193. // remove banner placeholder
  1194. if (x.banner && x.banner.cls) {
  1195. let _parent = `.${x.banner.cls.banner__parent}`;
  1196. document.addEventListener('DOMContentLoaded', () => {
  1197. for (let banner of document.querySelectorAll(_parent)) {
  1198. _setAttribute.call(banner, 'style', 'display:none!important');
  1199. console.log('Hid banner placeholder.');
  1200. }
  1201. }, false);
  1202. }
  1203.  
  1204. // remove banner data and some other stuff
  1205. delete x.banner;
  1206. delete x.consistency;
  1207. delete x['i-bannerid'];
  1208. delete x['i-counter'];
  1209. delete x['ga-counter'];
  1210. delete x['promo-curtain'];
  1211.  
  1212. return x;
  1213. };
  1214. let home_export = parseExport(home.export);
  1215. Object.defineProperty(home, 'export', {
  1216. get: x => home_export,
  1217. set: x => {
  1218. home_export = parseExport(x);
  1219. }
  1220. });
  1221. nt.define(win, 'home', home);
  1222. }, nullTools, '_setAttribute = Element.prototype.setAttribute');
  1223.  
  1224. if ('attachShadow' in Element.prototype) {
  1225. let fakeRoot = () => ({
  1226. firstChild: null,
  1227. appendChild: ()=>null,
  1228. querySelector: ()=>null,
  1229. querySelectorAll: ()=>null
  1230. });
  1231. Element.prototype.createShadowRoot = fakeRoot;
  1232. let shadows = new WeakMap();
  1233. let _attachShadow = Object.getOwnPropertyDescriptor(Element.prototype, 'attachShadow');
  1234. let _call_attachShadow = _attachShadow.value;
  1235. _attachShadow.value = function() {
  1236. return shadows.set(this, fakeRoot()).get(this);
  1237. };
  1238. Object.defineProperty(Element.prototype, 'attachShadow', _attachShadow);
  1239. let _shadowRoot = Object.getOwnPropertyDescriptor(Element.prototype, 'shadowRoot');
  1240. _shadowRoot.set = () => null;
  1241. _shadowRoot.get = function() {
  1242. return shadows.has(this) ? shadows.get(this) : void 0;
  1243. };
  1244. Object.defineProperty(Element.prototype, 'shadowRoot', _shadowRoot);
  1245. }
  1246. // Partially based on https://greasyfork.org/en/scripts/22737-remove-yandex-redirect
  1247. let selectors = (
  1248. 'A[onmousedown*="/jsredir"],'+
  1249. 'A[data-vdir-href],'+
  1250. 'A[data-counter]'
  1251. );
  1252. let removeTrackingAttributes = function(link)
  1253. {
  1254. link.removeAttribute('onmousedown');
  1255. if (link.hasAttribute('data-vdir-href')) {
  1256. link.removeAttribute('data-vdir-href');
  1257. link.removeAttribute('data-orig-href');
  1258. }
  1259. if (link.hasAttribute('data-counter')) {
  1260. link.removeAttribute('data-counter');
  1261. link.removeAttribute('data-bem');
  1262. }
  1263. };
  1264. let removeTracking = function(scope)
  1265. {
  1266. for (let link of scope.querySelectorAll(selectors))
  1267. removeTrackingAttributes(link);
  1268. };
  1269. document.addEventListener('DOMContentLoaded', (e) => removeTracking(e.target));
  1270. (new MutationObserver(
  1271. function(ms)
  1272. {
  1273. let m, node;
  1274. for (m of ms) for (node of m.addedNodes) if (node.nodeType === _Node.ELEMENT_NODE)
  1275. if (node.tagName === 'A' && node.matches(selectors)) {
  1276. removeTrackingAttributes(node);
  1277. } else {
  1278. removeTracking(node);
  1279. }
  1280. }
  1281. )).observe(_de, { childList: true, subtree: true });
  1282.  
  1283. //skip fixes for other sites
  1284. return;
  1285. }
  1286.  
  1287. // https://greasyfork.org/en/scripts/21937-moonwalk-hdgo-kodik-fix v0.8 (adapted)
  1288. document.addEventListener(
  1289. 'DOMContentLoaded', function()
  1290. {//createPlayer();
  1291. function log (name) {
  1292. console.log(`Player FIX: Detected ${name} player in ${location.href}`);
  1293. }
  1294. if (win.adv_enabled !== undefined && win.condition_detected !== undefined)
  1295. {
  1296. log('Moonwalk');
  1297. if (win.adv_enabled)
  1298. win.adv_enabled = false;
  1299. win.condition_detected = false;
  1300. if (win.MXoverrollCallback)
  1301. document.addEventListener(
  1302. 'click', function catcher(e)
  1303. {
  1304. e.stopPropagation();
  1305. win.MXoverrollCallback.call(window);
  1306. document.removeEventListener('click', catcher, true);
  1307. }, true
  1308. );
  1309. }
  1310. else if (win.stat_url !== undefined && win.is_html5 !== undefined && win.is_wp8 !== undefined)
  1311. {
  1312. log('HDGo');
  1313. document.body.onclick = null;
  1314. let tmp = document.querySelector('#swtf');
  1315. if (tmp)
  1316. tmp.style.display = 'none';
  1317. if (win.banner_second !== undefined)
  1318. win.banner_second = 0;
  1319. if (win.$banner_ads !== undefined)
  1320. win.$banner_ads = false;
  1321. if (win.$new_ads !== undefined)
  1322. win.$new_ads = false;
  1323. if (win.createCookie !== undefined)
  1324. win.createCookie('popup', 'true', '999');
  1325. if (win.canRunAds !== undefined && win.canRunAds !== true)
  1326. win.canRunAds = true;
  1327. }
  1328. else if (win.MXoverrollCallback && win.iframeSearch !== undefined)
  1329. {
  1330. log('Kodik');
  1331. let tmp = document.querySelector('.play_button');
  1332. if (tmp)
  1333. tmp.onclick = win.MXoverrollCallback.bind(window);
  1334. win.IsAdBlock = false;
  1335. }
  1336. else if (win.getnextepisode && win.uppodEvent)
  1337. {
  1338. log('Share-Serials.net');
  1339. scriptLander(
  1340. function()
  1341. {
  1342. let _setInterval = win.setInterval,
  1343. _setTimeout = win.setTimeout;
  1344. win.setInterval = function(func)
  1345. {
  1346. if (func instanceof Function && func.toString().indexOf('_delay') > -1)
  1347. {
  1348. let intv = _setInterval.call(
  1349. this, function()
  1350. {
  1351. _setTimeout.call(
  1352. this, function(intv)
  1353. {
  1354. clearInterval(intv);
  1355. let timer = document.querySelector('#timer');
  1356. if (timer)
  1357. timer.click();
  1358. }, 100, intv);
  1359. func.call(this);
  1360. }, 5
  1361. );
  1362.  
  1363. return intv;
  1364. }
  1365. return _setInterval.apply(this, arguments);
  1366. };
  1367. win.setTimeout = function(func) {
  1368. if (func instanceof Function && func.toString().indexOf('adv_showed') > -1)
  1369. {
  1370. return _setTimeout.call(this, func, 0);
  1371. }
  1372. return _setTimeout.apply(this, arguments);
  1373. };
  1374. }
  1375. );
  1376. } else if ('ADC' in win)
  1377. {
  1378. log('vjs-creatives plugin in');
  1379. let replacer = (obj) => {
  1380. for (let name in obj)
  1381. if (obj[name] instanceof Function)
  1382. obj[name] = () => null;
  1383. };
  1384. replacer(win.ADC);
  1385. replacer(win.currentAdSlot);
  1386. }
  1387. UberVK: {
  1388. if (!inIFrame)
  1389. break UberVK;
  1390. let oddNames = 'HD' in win &&
  1391. !Object.getOwnPropertyNames(win).every(n => !n.startsWith('_0x'));
  1392. if (!oddNames)
  1393. break UberVK;
  1394. log('UberVK');
  1395. XMLHttpRequest.prototype.open = () => { throw 404; };
  1396. }
  1397. }, false
  1398. );
  1399.  
  1400. // piguiqproxy.com circumvention prevention
  1401. scriptLander(
  1402. () => {
  1403. let _open = XMLHttpRequest.prototype.open;
  1404. // blacklist of third-party domains requests to which are ignored
  1405. let blacklist = /[/.@](amgload\.net|dsn-fishki\.ru|piguiqproxy\.com|rcdn\.pro)[:/]/i;
  1406. // blacklist of domains where all third-party requests are ignored
  1407. let ondomains = /(^|[/.@])oane\.ws($|[:/])/i;
  1408. // highly suspicious URLs
  1409. let suspicious = /^https?:\/\/[a-z0-9]{6}\.ru\/([a-z0-9\/]{45,}|[a-z0-9]{8,}|ad\/banner\/.+)$/i;
  1410.  
  1411. XMLHttpRequest.prototype.open = function(method, url)
  1412. {
  1413. if (method === 'GET' &&
  1414. (blacklist.test(url) || suspicious.test(url) ||
  1415. ondomains.test(location.hostname) && !ondomains.test(url)))
  1416. {
  1417. this.send = () => null;
  1418. this.setRequestHeader = () => null;
  1419. console.log('Blocked request: ', url);
  1420. return;
  1421. }
  1422. return _open.apply(this, arguments);
  1423. };
  1424. }
  1425. );
  1426.  
  1427. // === Helper functions ===
  1428.  
  1429. // function to search and remove nodes by content
  1430. // selector - standard CSS selector to define set of nodes to check
  1431. // words - regular expression to check content of the suspicious nodes
  1432. // params - object with multiple extra parameters:
  1433. // .log - display log in the console
  1434. // .hide - set display to none instead of removing from the page
  1435. // .parent - parent node to remove if content is found in the child node
  1436. // .siblings - number of simling nodes to remove (excluding text nodes)
  1437. let scRemove = (node) => node.parentNode.removeChild(node);
  1438. let scHide = function(node)
  1439. {
  1440. let style = _getAttribute.call(node, 'style') || '',
  1441. hide = ';display:none!important;';
  1442. if (style.indexOf(hide) < 0)
  1443. _setAttribute.call(node, 'style', style + hide);
  1444. };
  1445.  
  1446. function scissors (selector, words, scope, params)
  1447. {
  1448. let logger = function() { return params.log ? console.log(...arguments) : null; };
  1449. if (!scope.contains(document.body))
  1450. logger('[s] scope', scope);
  1451. let remFunc = (params.hide ? scHide : scRemove),
  1452. iterFunc = (params.siblings > 0 ? 'nextElementSibling' : 'previousElementSibling'),
  1453. toRemove = [],
  1454. siblings;
  1455. for (let node of scope.querySelectorAll(selector))
  1456. {
  1457. // drill up to a parent node if specified, break if not found
  1458. if (params.parent)
  1459. {
  1460. let old = node;
  1461. node = node.closest(params.parent);
  1462. if (node === null || node.contains(scope))
  1463. {
  1464. logger('[s] went out of scope with', old);
  1465. continue;
  1466. }
  1467. }
  1468. logger('[s] processing', node);
  1469. if (toRemove.includes(node))
  1470. continue;
  1471. if (words.test(node.innerHTML))
  1472. {
  1473. // skip node if already marked for removal
  1474. logger('[s] marked for removal');
  1475. toRemove.push(node);
  1476. // add multiple nodes if defined more than one sibling
  1477. siblings = Math.abs(params.siblings) || 0;
  1478. while (siblings)
  1479. {
  1480. node = node[iterFunc];
  1481. if (!node) break; // can't go any further - exit
  1482. logger('[s] adding sibling node', node);
  1483. toRemove.push(node);
  1484. siblings -= 1;
  1485. }
  1486. }
  1487. }
  1488. let toSkip = [];
  1489. for (let node of toRemove)
  1490. if (!toRemove.every(other => other === node || !node.contains(other)))
  1491. toSkip.push(node);
  1492. if (toRemove.length)
  1493. logger(`[s] proceeding with ${params.hide?'hide':'removal'} of`, toRemove, `skip`, toSkip);
  1494. for (let node of toRemove) if (!toSkip.includes(node))
  1495. remFunc(node);
  1496. }
  1497.  
  1498. // function to perform multiple checks if ads inserted with a delay
  1499. // by default does 30 checks withing a 3 seconds unless nonstop mode specified
  1500. // also does 1 extra check when a page completely loads
  1501. // selector and words - passed dow to scissors
  1502. // params - object with multiple extra parameters:
  1503. // .log - display log in the console
  1504. // .root - selector to narrow down scope to scan;
  1505. // .observe - if true then check will be performed continuously;
  1506. // Other parameters passed down to scissors.
  1507. function gardener(selector, words, params)
  1508. {
  1509. let logger = function() { return params.log ? console.log(...arguments) : null; };
  1510. params = params || {};
  1511. logger(`[gardener] selector: '${selector}' detector: ${words} options: ${JSON.stringify(params)}`);
  1512. let scope;
  1513. let globalScope = [_de];
  1514. let domLoaded = false;
  1515. let getScope = root => root ? _de.querySelectorAll(root) : globalScope;
  1516. let onevent = e => {
  1517. logger(`[gardener] cleanup on ${Object.getPrototypeOf(e)} "${e.type}"`);
  1518. for (let node of scope)
  1519. scissors(selector, words, node, params);
  1520. };
  1521. let repeater = n => {
  1522. if (!domLoaded && n) {
  1523. setTimeout(repeater, 500, n - 1);
  1524. scope = getScope(params.root);
  1525. if (!scope) // exit if the root element is not present on the page
  1526. return 0;
  1527. onevent({type: 'Repeater'});
  1528. }
  1529. };
  1530. repeater(20);
  1531. document.addEventListener(
  1532. 'DOMContentLoaded', (e) => {
  1533. domLoaded = true;
  1534. // narrow down scope to a specific element
  1535. scope = getScope(params.root);
  1536. if (!scope) // exit if the root element is not present on the page
  1537. return 0;
  1538. logger('[g] scope', scope);
  1539. // add observe mode if required
  1540. if (params.observe)
  1541. {
  1542. let params = { childList:true, subtree: true };
  1543. let observer = new MutationObserver(
  1544. function(ms)
  1545. {
  1546. for (let m of ms)
  1547. if (m.addedNodes.length)
  1548. onevent(m);
  1549. }
  1550. );
  1551. for (let node of scope)
  1552. observer.observe(node, params);
  1553. logger('[g] observer enabled');
  1554. }
  1555. onevent(e);
  1556. }, false);
  1557. // wait for a full page load to do one extra cut
  1558. win.addEventListener('load', onevent, false);
  1559. }
  1560.  
  1561. // wrap popular methods to open a new tab to catch specific behaviours
  1562. function createWindowOpenWrapper(openFunc, onClickFunc)
  1563. {
  1564. let _createElement = _Document.prototype.createElement,
  1565. _appendChild = Element.prototype.appendChild,
  1566. fakeNative = (f) => (f.toString = () => `function ${f.name}() { [native code] }`);
  1567.  
  1568. let nt = new nullTools();
  1569. fakeNative(openFunc);
  1570.  
  1571. let parser = _createElement.call(document, 'a');
  1572. let openWhitelist = (url, parent) => {
  1573. parser.href = url;
  1574. return parser.hostname === 'www.imdb.com' || parser.hostname === 'www.kinopoisk.ru' ||
  1575. parent.hostname === 'radikal.ru' && url === void 0;
  1576. };
  1577.  
  1578. let redefineOpen = (root) => {
  1579. if ('open' in root) {
  1580. let _open = root.open.bind(root);
  1581. nt.define(root, 'open', (...args) => {
  1582. if (openWhitelist(args[0], location)) {
  1583. console.log('Whitelisted popup:', ...args);
  1584. return _open(...args);
  1585. }
  1586. return openFunc(...args);
  1587. });
  1588. }
  1589. };
  1590. redefineOpen(win);
  1591.  
  1592. function createElement(name) {
  1593. '[native code]';
  1594. // jshint validthis:true
  1595. let el = _createElement.apply(this, arguments);
  1596. // click-dispatch check for Google Chrome and similar browsers
  1597. if (el instanceof HTMLAnchorElement)
  1598. el.addEventListener('click', onClickFunc, false);
  1599. // redefine window.open in first-party frames
  1600. if (el instanceof HTMLIFrameElement || el instanceof HTMLObjectElement)
  1601. el.addEventListener('load', (e) => {
  1602. try {
  1603. redefineOpen(e.target.contentWindow);
  1604. } catch(ignore) {}
  1605. }, false);
  1606. return el;
  1607. }
  1608. fakeNative(createElement);
  1609.  
  1610. let redefineCreateElement = (obj) => {
  1611. for (let root of [obj.document, _Document.prototype]) if ('createElement' in root)
  1612. nt.define(root, 'createElement', createElement);
  1613. };
  1614. redefineCreateElement(win);
  1615.  
  1616. // wrap window.open in newly added first-party frames
  1617. Element.prototype.appendChild = function appendChild()
  1618. {
  1619. '[native code]';
  1620. let el = _appendChild.apply(this, arguments);
  1621. if (el instanceof HTMLIFrameElement) {
  1622. try {
  1623. redefineOpen(el.contentWindow);
  1624. redefineCreateElement(el.contentWindow);
  1625. } catch(ignore) {}
  1626. }
  1627. return el;
  1628. };
  1629. fakeNative(Element.prototype.appendChild);
  1630. }
  1631.  
  1632. // Function to catch and block various methods to open a new window with 3rd-party content.
  1633. // Some advertisement networks went way past simple window.open call to circumvent default popup protection.
  1634. // This funciton blocks window.open, ability to restore original window.open from an IFRAME object,
  1635. // ability to perform an untrusted (not initiated by user) click on a link, click on a link without a parent
  1636. // node or simply a link with piece of javascript code in the HREF attribute.
  1637. function preventPopups()
  1638. {
  1639. // call sandbox-me if in iframe and not whitelisted
  1640. if (inIFrame) {
  1641. win.top.postMessage({ name: 'sandbox-me', href: win.location.href }, '*');
  1642. return;
  1643. }
  1644.  
  1645. scriptLander(() => {
  1646. let open = (...args) => {
  1647. '[native code]';
  1648. console.warn('Site attempted to open a new window', args);
  1649. if (new RegExp(`^https?://${location.hostname}/`).test(args[0])) // skip extra click in case of blocked popunder
  1650. location.assign(args[0]);
  1651. return {
  1652. document: {
  1653. write: () => {},
  1654. writeln: () => {}
  1655. },
  1656. location: {}
  1657. };
  1658. };
  1659.  
  1660. let clickHandler = (e) => {
  1661. let link = e.target;
  1662. if (!link.parentNode || !e.isTrusted ||
  1663. (link.href && link.href.trim().toLowerCase().indexOf('javascript') === 0))
  1664. {
  1665. e.preventDefault();
  1666. console.warn('Blocked suspicious click event', e, 'on', e.target);
  1667. }
  1668. };
  1669.  
  1670. createWindowOpenWrapper(open, clickHandler);
  1671.  
  1672. console.log('Popup prevention enabled.');
  1673. }, nullTools, createWindowOpenWrapper);
  1674. }
  1675.  
  1676. // Helper function to close background tab if site opens itself in a new tab and then
  1677. // loads a 3rd-party page in the background one (thus performing background redirect).
  1678. function preventPopunders()
  1679. {
  1680. // create "close_me" event to call high-level window.close()
  1681. let eventName = `close_me_${Math.random().toString(36).substr(2)}`;
  1682. let callClose = () => (console.log('close call'), window.close());
  1683. window.addEventListener(eventName, callClose, true);
  1684.  
  1685. scriptLander(() => {
  1686. // get host of a provided URL with help of an anchor object
  1687. // unfortunately new URL(url, window.location) generates wrong URL in some cases
  1688. let parseURL = document.createElement('A');
  1689. let getHost = (url) => (parseURL.href = url, parseURL.hostname);
  1690. // site went to a new tab and attempts to unload
  1691. // call for high-level close through event
  1692. let closeWindow = () => window.dispatchEvent(new CustomEvent(eventName, {}));
  1693. // check is URL local or goes to different site
  1694. let isLocal = (url) => {
  1695. if (url === location.pathname || url === location.href)
  1696. return true; // URL points to current pathname or full address
  1697. let host = getHost(url);
  1698. let site = location.hostname;
  1699. return host !== '' && // URLs with unusual protocol may have empty 'host'
  1700. (site === host || site.endsWith(`.${host}`) || host.endsWith(`.${site}`));
  1701. };
  1702.  
  1703. let _open = window.open.bind(window);
  1704. let open = (...args) => {
  1705. '[native code]';
  1706. let url = args[0];
  1707. if (url && isLocal(url))
  1708. window.addEventListener('beforeunload', closeWindow, true);
  1709. // jshint validthis:true
  1710. return _open(...args);
  1711. };
  1712.  
  1713. let clickHandler = (e) => {
  1714. if (!e.target.parentNode || !e.isTrusted)
  1715. window.addEventListener('beforeunload', closeWindow, true);
  1716. };
  1717.  
  1718. createWindowOpenWrapper(open, clickHandler);
  1719.  
  1720. console.log("Background redirect prevention enabled.");
  1721. }, `let eventName="${eventName}"`, nullTools, createWindowOpenWrapper);
  1722. }
  1723.  
  1724. // Mix between check for popups and popunders
  1725. // Significantly more agressive than both and can't be used as universal solution
  1726. function preventPopMix()
  1727. {
  1728. if (inIFrame)
  1729. {
  1730. win.top.postMessage({ name: 'sandbox-me', href: win.location.href }, '*');
  1731. return;
  1732. }
  1733.  
  1734. // create "close_me" event to call high-level window.close()
  1735. let eventName = `close_me_${Math.random().toString(36).substr(2)}`;
  1736. let callClose = () => (console.log('close call'), window.close());
  1737. window.addEventListener(eventName, callClose, true);
  1738.  
  1739. scriptLander(() => {
  1740. let _open = window.open,
  1741. parseURL = document.createElement('A');
  1742. // get host of a provided URL with help of an anchor object
  1743. // unfortunately new URL(url, window.location) generates wrong URL in some cases
  1744. let getHost = (url) => (parseURL.href = url, parseURL.host);
  1745. // site went to a new tab and attempts to unload
  1746. // call for high-level close through event
  1747. let closeWindow = () => (_open(window.location,'_self'), window.dispatchEvent(new CustomEvent(eventName, {})));
  1748. // check is URL local or goes to different site
  1749. function isLocal(url)
  1750. {
  1751. let loc = window.location;
  1752. if (url === loc.pathname || url === loc.href)
  1753. return true; // URL points to current pathname or full address
  1754. let host = getHost(url),
  1755. site = loc.host;
  1756. if (host === '')
  1757. return false; // URLs with unusual protocol may have empty 'host'
  1758. if (host.length > site.length)
  1759. [site, host] = [host, site];
  1760. return site.includes(host, site.length - host.length);
  1761. }
  1762.  
  1763. // add check for redirect for 5 seconds, then disable it
  1764. function checkRedirect()
  1765. {
  1766. window.addEventListener('beforeunload', closeWindow, true);
  1767. setTimeout(closeWindow=>window.removeEventListener('beforeunload', closeWindow, true), 5000, closeWindow);
  1768. }
  1769.  
  1770. function open(url, name)
  1771. {
  1772. '[native code]';
  1773. if (url && isLocal(url) && (!name || name === '_blank'))
  1774. {
  1775. console.warn('Suspicious local new window', arguments);
  1776. checkRedirect();
  1777. // jshint validthis:true
  1778. return _open.apply(this, arguments);
  1779. }
  1780. console.warn('Blocked attempt to open a new window', arguments);
  1781. return {
  1782. document: {
  1783. write: () => {},
  1784. writeln: () => {}
  1785. }
  1786. };
  1787. }
  1788.  
  1789. function clickHandler(e)
  1790. {
  1791. let link = e.target,
  1792. url = link.href||'';
  1793. if (e.targetParentNode && e.isTrusted || link.target !== '_blank')
  1794. {
  1795. console.log('Link', link, 'were created dinamically, but looks fine.');
  1796. return true;
  1797. }
  1798. if (isLocal(url) && link.target === '_blank')
  1799. {
  1800. console.log('Suspicious local link', link);
  1801. checkRedirect();
  1802. return;
  1803. }
  1804. console.log('Blocked suspicious click on a link', link);
  1805. e.stopPropagation();
  1806. e.preventDefault();
  1807. }
  1808.  
  1809. createWindowOpenWrapper(open, clickHandler);
  1810.  
  1811. console.log("Mixed popups prevention enabled.");
  1812. }, `let eventName="${eventName}"`, createWindowOpenWrapper);
  1813. }
  1814. // External listener for case when site known to open popups were loaded in iframe
  1815. // It will sandbox any iframe which will send message 'forbid.popups' (preventPopups sends it)
  1816. // Some sites replace frame's window.location with data-url to run in clean context
  1817. if (!inIFrame)
  1818. {
  1819. window.addEventListener(
  1820. 'message', function(e)
  1821. {
  1822. if (!e.data || e.data.name !== 'sandbox-me' || !e.data.href)
  1823. return;
  1824. let src = e.data.href;
  1825. for (let frame of document.querySelectorAll('iframe'))
  1826. if (frame.contentWindow === e.source)
  1827. {
  1828. if (frame.hasAttribute('sandbox'))
  1829. {
  1830. if (!frame.sandbox.contains('allow-popups'))
  1831. return; // exit frame since it's already sandboxed and popups are blocked
  1832. // remove allow-popups if frame already sandboxed
  1833. frame.sandbox.remove('allow-popups');
  1834. } else {
  1835. // set sandbox mode for troublesome frame and allow scripts, forms and a few other actions
  1836. // technically allowing both scripts and same-origin allows removal of the sandbox attribute,
  1837. // but to apply content must be reloaded and this script will re-apply it in the result
  1838. frame.setAttribute('sandbox','allow-forms allow-scripts allow-presentation allow-top-navigation allow-same-origin');
  1839. }
  1840. console.log('Disallowed popups from iframe', frame);
  1841.  
  1842. // reload frame content to apply restrictions
  1843. if (!src) {
  1844. src = frame.src;
  1845. console.log('Unable to get current iframe location, reloading from src', src);
  1846. } else
  1847. console.log('Reloading iframe with URL', src);
  1848. frame.src = 'about:blank';
  1849. frame.src = src;
  1850. }
  1851. }, false
  1852. );
  1853. }
  1854.  
  1855. function selectiveEval() {
  1856. scriptLander(() => {
  1857. let nt = new nullTools();
  1858. let _eval = win.eval.bind(window);
  1859. nt.define(win, 'eval', function(...args) {
  1860. if (/_0x|location\s*?=|location.href\s*?=|location.assign\(|open\(/i.test(args[0])) {
  1861. console.log(`Skipped eval of ${args[0].slice(0, 512)}\u2026`);
  1862. return null;
  1863. }
  1864. return _eval(...args);
  1865. });
  1866. }, nullTools);
  1867. }
  1868.  
  1869. // === Scripts for specific domains ===
  1870.  
  1871. let scripts = {};
  1872. // prevent popups and redirects block
  1873. // Popups
  1874. scripts.preventPopups = {
  1875. other: [
  1876. 'biqle.ru',
  1877. 'chaturbate.com',
  1878. 'dfiles.ru',
  1879. 'hentaiz.org',
  1880. 'mirrorcreator.com',
  1881. 'online-multy.ru',
  1882. 'radikal.ru', 'rumedia.ws',
  1883. 'seedoff.cc', 'seedoff.tv',
  1884. 'thepiratebay.org', 'torseed.net',
  1885. 'unionpeer.com',
  1886. 'zippyshare.com'
  1887. ],
  1888. now: preventPopups
  1889. };
  1890. // Popunders (background redirect)
  1891. scripts.preventPopunders = {
  1892. other: [
  1893. 'lostfilm-online.ru',
  1894. 'mediafire.com', 'megapeer.org', 'megapeer.ru',
  1895. 'perfectgirls.net'
  1896. ],
  1897. now: preventPopunders
  1898. };
  1899. // PopMix (both types of popups encountered on site)
  1900. scripts['openload.co'] = {
  1901. other: ['oload.tv', 'oload.info'],
  1902. now: () => {
  1903. let nt = new nullTools();
  1904. nt.define(win, 'CNight', win.CoinHive);
  1905. if (location.pathname.startsWith('/embed/'))
  1906. {
  1907. nt.define(win, 'BetterJsPop', {
  1908. add: ((a, b) => console.warn('BetterJsPop.add', a, b)),
  1909. config: ((o) => console.warn('BetterJsPop.config', o)),
  1910. Browser: { isChrome: true }
  1911. });
  1912. nt.define(win, 'isSandboxed', nt.func(null));
  1913. nt.define(win, 'adblock', false);
  1914. nt.define(win, 'adblock2', false);
  1915. } else
  1916. preventPopMix();
  1917. }
  1918. };
  1919. scripts['turbobit.net'] = preventPopMix;
  1920.  
  1921. // workaround for moradu.com/apu.php load error handler script, not sure which ad network is this
  1922. scripts['tapochek.net'] = () => {
  1923. let _appendChild = Object.getOwnPropertyDescriptor(_Node.prototype, 'appendChild');
  1924. let _appendChild_value = _appendChild.value;
  1925. _appendChild.value = function appendChild(node) {
  1926. if (this === win.document.body)
  1927. if ((node instanceof HTMLScriptElement || node instanceof HTMLStyleElement) &&
  1928. /^https?:\/\/[0-9a-f]{15}\.com\/\d+(\/|\.css)$/.test(node.src) ||
  1929. node instanceof HTMLDivElement && node.style.zIndex > 900000 &&
  1930. node.style.backgroundImage.includes('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'))
  1931. throw '...eenope!';
  1932. return _appendChild_value.apply(this, arguments);
  1933. };
  1934. Object.defineProperty(_Node.prototype, 'appendChild', _appendChild);
  1935.  
  1936. preventPopups();
  1937. };
  1938.  
  1939. scripts['rustorka.com'] = {
  1940. other: ['rustorka.lib'],
  1941. now: () => scriptLander(() => {
  1942. let _eval_def = Object.getOwnPropertyDescriptor(win, 'eval');
  1943. if (!_eval_def)
  1944. return;
  1945. let _eval_val = _eval_def.value;
  1946. _eval_def.value = (...args) => {
  1947. if (args[0] && args[0].includes('antiadblock'))
  1948. return console.log('Anti-AdBlock script may run another day, but not today.');
  1949. return _eval_val.apply(this, args);
  1950. };
  1951. Object.defineProperty(win, 'eval', _eval_def);
  1952. }),
  1953. dom: () => scriptLander(() => {
  1954. let link = void 0;
  1955. document.body.addEventListener('mousedown', e => {
  1956. link = e.target.closest('a, select, #fancybox-title-wrap');
  1957. }, false);
  1958. let _open = window.open.bind(window);
  1959. let _getAttribute = Element.prototype.getAttribute;
  1960. win.open = (...args) => {
  1961. let url = args[0];
  1962. let allow = false;
  1963. if (link instanceof HTMLAnchorElement) {
  1964. // third-party post links
  1965. let href = _getAttribute.call(link, 'href');
  1966. if (link.classList.contains('postLink') &&
  1967. !link.matches(`a[href*="${location.hostname}"]`) &&
  1968. (href === url || link.href === url)) {
  1969. return _open(...args);
  1970. }
  1971. // onclick # links
  1972. if (href === '#' && /window\.open/.test(_getAttribute.call(link, 'onclick'))) {
  1973. return _open(...args);
  1974. }
  1975. // force local links to load in the current window
  1976. if (href.includes(`//${location.hostname}/`))
  1977. location.assign(href);
  1978. }
  1979. // list of image hostings under upload picture button (new comment)
  1980. if (link instanceof HTMLSelectElement &&
  1981. !url.includes(location.hostname) &&
  1982. link.value === url) {
  1983. return _open(...args);
  1984. }
  1985. // open screenshot in a new window
  1986. if (link instanceof HTMLSpanElement &&
  1987. link.id === 'fancybox-title-wrap') {
  1988. return _open(...args);
  1989. }
  1990. // looks like tabunder
  1991. if (link === null && url === location.href)
  1992. location.replace(url); // reload current page
  1993. // other cases
  1994. console.warn(`Site attempted to open "${url}" in a new window. Source: `, link);
  1995. return {};
  1996. };
  1997. })
  1998. };
  1999.  
  2000. // other
  2001. scripts['1tv.ru'] = () => scriptLander(() => {
  2002. let nt = new nullTools();
  2003. nt.define(win, 'EUMPAntiblockConfig', nt.proxy({url: '//www.1tv.ru/favicon.ico'}));
  2004. let _EUMPConfig = void 0;
  2005. let disablePlugins = {
  2006. 'antiblock': false,
  2007. 'stat1tv': false
  2008. };
  2009. Object.defineProperty(win, 'EUMPConfig', {
  2010. enumerable: true,
  2011. get: x => _EUMPConfig,
  2012. set: x => {
  2013. let plugins = x.plugins;
  2014. if (plugins) {
  2015. let id;
  2016. for (let plugin in disablePlugins) {
  2017. id = plugins.indexOf(plugin);
  2018. if (id > -1) {
  2019. plugins.splice(id, 1);
  2020. disablePlugins[plugin] = true;
  2021. }
  2022. }
  2023. console.warn(`Player plugins: active [${plugins}], disabled [${Object.keys(disablePlugins).filter(x => disablePlugins[x])}]`);
  2024. }
  2025. _EUMPConfig = x;
  2026. }
  2027. });
  2028. }, nullTools);
  2029.  
  2030. scripts['2picsun.ru'] = {
  2031. other: [
  2032. 'pics2sun.ru', '3pics-img.ru'
  2033. ],
  2034. now: () => {
  2035. Object.defineProperty(navigator, 'userAgent', {value: 'googlebot'});
  2036. }
  2037. };
  2038.  
  2039. scripts['4pda.ru'] = {
  2040. now: () => {
  2041. // https://greasyfork.org/en/scripts/14470-4pda-unbrender
  2042. let hStyle,
  2043. isForum = document.location.href.search('/forum/') !== -1,
  2044. remove = (node) => (node ? node.parentNode.removeChild(node) : null),
  2045. afterClean = () => remove(hStyle);
  2046.  
  2047. function beforeClean()
  2048. {
  2049. // attach styles before document displayed
  2050. hStyle = createStyle([
  2051. 'html { overflow-y: scroll }',
  2052. 'article + aside * { display: none !important }',
  2053. `section[id] {${(
  2054. 'position: absolute;'+
  2055. 'width: 100%'
  2056. )}}`,
  2057. `#header + div:after {${(
  2058. 'content: "";'+
  2059. 'position: fixed;'+
  2060. 'top: 0;'+
  2061. 'left: 0;'+
  2062. 'width: 100%;'+
  2063. 'height: 100%;'+
  2064. 'background-color: #E6E7E9'
  2065. )}}`,
  2066. // http://codepen.io/Beaugust/pen/DByiE
  2067. '@keyframes spin { 100% { transform: rotate(360deg) } }',
  2068. `article + aside:after {${(
  2069. 'content: "";'+
  2070. 'position: absolute;'+
  2071. 'width: 150px;'+
  2072. 'height: 150px;'+
  2073. 'top: 150px;'+
  2074. 'left: 50%;'+
  2075. 'margin-top: -75px;'+
  2076. 'margin-left: -75px;'+
  2077. 'box-sizing: border-box;'+
  2078. 'border-radius: 100%;'+
  2079. 'border: 10px solid rgba(0, 0, 0, 0.2);'+
  2080. 'border-top-color: rgba(0, 0, 0, 0.6);'+
  2081. 'animation: spin 2s infinite linear'
  2082. )}}`
  2083. ], {id:'ubrHider'}, true);
  2084.  
  2085. // display content of a page if time to load a page is more than 2 seconds to avoid
  2086. // blocking access to a page if it is loading for too long or stuck in a loading state
  2087. setTimeout(2000, afterClean);
  2088. }
  2089.  
  2090. createStyle([
  2091. '#nav .use-ad { display: block !important }',
  2092. 'article:not(.post) + article:not(#id),'+
  2093. 'html:not(#id)>body:not(#id) a[target="_blank"] img[height="90"] { display: none !important }'
  2094. ]);
  2095.  
  2096. if (!isForum)
  2097. beforeClean();
  2098.  
  2099. // save links to non-overridden functions to use later
  2100. let protectedElems;
  2101. // protect/hide changed attributes in case site attempt to restore them
  2102. function styleProtector(eventMode)
  2103. {
  2104. let _toLowerCase = String.prototype.toLowerCase,
  2105. isStyleText = (t) => (_toLowerCase.call(t) === 'style'),
  2106. protectedElems = new WeakMap();
  2107. function protoOverride(element, functionName, isStyleCheck, returnIfProtected)
  2108. {
  2109. let originalFunction = element.prototype[functionName];
  2110. element.prototype[functionName] = function wrapper()
  2111. {
  2112. if (protectedElems.has(this) && isStyleCheck(arguments[0]))
  2113. return returnIfProtected(this, arguments);
  2114. return originalFunction.apply(this, arguments);
  2115. };
  2116. }
  2117. protoOverride(Element, 'removeAttribute', isStyleText, () => undefined);
  2118. protoOverride(Element, 'hasAttribute', isStyleText, (_this) => protectedElems.get(_this) !== null);
  2119. protoOverride(Element, 'setAttribute', isStyleText, (_this, args) => protectedElems.set(_this, args[1]));
  2120. protoOverride(Element, 'getAttribute', isStyleText, (_this) => protectedElems.get(_this));
  2121. if (!eventMode)
  2122. return protectedElems;
  2123. else
  2124. {
  2125. let e = document.createEvent('Event');
  2126. e.initEvent('protoOverride', false, false);
  2127. window.protectedElems = protectedElems;
  2128. window.dispatchEvent(e);
  2129. }
  2130. }
  2131. if (!isFirefox)
  2132. protectedElems = styleProtector(false);
  2133. else
  2134. {
  2135. let script = document.createElement('script');
  2136. script.textContent = `(${styleProtector.toString()})(true);`;
  2137. window.addEventListener(
  2138. 'protoOverride', function protoOverrideCallback(e)
  2139. {
  2140. if (win.protectedElems) {
  2141. protectedElems = win.protectedElems;
  2142. delete win.protectedElems;
  2143. }
  2144. document.removeEventListener('protoOverride', protoOverrideCallback, true);
  2145. }, true
  2146. );
  2147. _appendChild(script);
  2148. _removeChild(script);
  2149. }
  2150.  
  2151. // clean a page
  2152. window.addEventListener(
  2153. 'DOMContentLoaded', function()
  2154. {
  2155. let width = () => window.innerWidth || _de.clientWidth || document.body.clientWidth || 0;
  2156. let height = () => window.innerHeight || _de.clientHeight || document.body.clientHeight || 0;
  2157.  
  2158. if (isForum)
  2159. {
  2160. let si = document.querySelector('#logostrip');
  2161. if (si)
  2162. remove(si.parentNode.nextSibling);
  2163. }
  2164.  
  2165. // clear background in the download frame
  2166. if (location.pathname.startsWith('/forum/dl/')) {
  2167. let setBackground = node => _setAttribute.call(
  2168. node,
  2169. 'style', (_getAttribute.call(node, 'style') || '') +
  2170. ';background-color:#4ebaf6!important'
  2171. );
  2172. setBackground(document.body);
  2173. for (let itm of document.querySelectorAll('body > div'))
  2174. if (!itm.querySelector('.dw-fdwlink, .content') && !itm.classList.contains('footer')) {
  2175. remove(itm);
  2176. } else {
  2177. setBackground(itm);
  2178. }
  2179. }
  2180.  
  2181. if (isForum) // Do not continue if it's a forum
  2182. return;
  2183.  
  2184. {
  2185. let si = document.querySelector('#header');
  2186. if (si)
  2187. {
  2188. let rem = si.previousSibling;
  2189. while (rem)
  2190. {
  2191. si = rem.previousSibling;
  2192. remove(rem);
  2193. rem = si;
  2194. }
  2195. }
  2196. }
  2197.  
  2198. for (let itm of document.querySelectorAll('#nav li[class]'))
  2199. if (itm && itm.querySelector('a[href^="/tag/"]'))
  2200. remove(itm);
  2201.  
  2202. let style, result,
  2203. fakeStyles = new WeakMap(),
  2204. styleProxy = {
  2205. get: function(target, prop)
  2206. {
  2207. let fakeStyle = fakeStyles.get(target);
  2208. return ((prop in fakeStyle) ? fakeStyle : target)[prop];
  2209. },
  2210. set: function(target, prop, value)
  2211. {
  2212. let fakeStyle = fakeStyles.get(target);
  2213. ((prop in fakeStyle) ? fakeStyle : target)[prop] = value;
  2214. return true;
  2215. }
  2216. };
  2217. for (let itm of document.querySelectorAll('DIV, A'))
  2218. {
  2219. if (itm.tagName ==='DIV' &&
  2220. itm.offsetWidth > 0.95 * width() &&
  2221. itm.offsetHeight > 0.85 * height())
  2222. {
  2223. style = window.getComputedStyle(itm, null);
  2224. result = [];
  2225.  
  2226. if (style.backgroundImage !== 'none')
  2227. result.push('background-image:none!important');
  2228.  
  2229. if (style.backgroundColor !== 'transparent' &&
  2230. style.backgroundColor !== 'rgba(0, 0, 0, 0)')
  2231. result.push('background-color:transparent!important');
  2232.  
  2233. if (result.length)
  2234. {
  2235. if (itm.getAttribute('style'))
  2236. result.unshift(itm.getAttribute('style'));
  2237.  
  2238. fakeStyles.set(itm.style, {
  2239. 'backgroundImage': itm.style.backgroundImage,
  2240. 'backgroundColor': itm.style.backgroundColor
  2241. });
  2242.  
  2243. try {
  2244. Object.defineProperty(itm, 'style', {
  2245. value: new Proxy(itm.style, styleProxy),
  2246. enumerable: true
  2247. });
  2248. } catch (e) {
  2249. console.log('Unable to protect style property.', e);
  2250. }
  2251.  
  2252. if (protectedElems)
  2253. protectedElems.set(itm, _getAttribute.call(itm, 'style'));
  2254.  
  2255. _setAttribute.call(itm, 'style', result.join(';'));
  2256. }
  2257. }
  2258. if (itm.tagName ==='A' &&
  2259. (itm.offsetWidth > 0.95 * width() ||
  2260. itm.offsetHeight > 0.85 * height()))
  2261. {
  2262. if (protectedElems)
  2263. protectedElems.set(itm, _getAttribute.call(itm, 'style'));
  2264.  
  2265. _setAttribute.call(itm, 'style', 'display:none!important');
  2266. }
  2267. }
  2268.  
  2269. for (let itm of document.querySelectorAll('ASIDE>DIV'))
  2270. if ( ((itm.querySelector('script, iframe, a[href*="/ad/www/"]') ||
  2271. itm.querySelector('img[src$=".gif"]:not([height="0"]), img[height="400"]')) &&
  2272. !itm.classList.contains('post') ) || !itm.childNodes.length )
  2273. remove(itm);
  2274.  
  2275. document.body.setAttribute('style', (document.body.getAttribute('style')||'')+';background-color:#E6E7E9!important');
  2276.  
  2277. // display content of the page
  2278. afterClean();
  2279. }
  2280. );
  2281. }
  2282. };
  2283.  
  2284. scripts['adhands.ru'] = () => scriptLander(() => {
  2285. let nt = new nullTools();
  2286. try {
  2287. let _adv;
  2288. Object.defineProperty(win, 'adv', {
  2289. get: () => _adv,
  2290. set: (v) => {
  2291. console.log('Blocked advert on adhands.ru.');
  2292. nt.define(v, 'advert', '');
  2293. _adv = v;
  2294. }
  2295. });
  2296. } catch (ignore) {
  2297. if (!win.adv)
  2298. console.log('Unable to locate advert on adhands.ru.');
  2299. else {
  2300. console.log('Blocked advert on adhands.ru.');
  2301. nt.define(win.adv, 'advert', '');
  2302. }
  2303. }
  2304. }, nullTools);
  2305.  
  2306. scripts['all-episodes.tv'] = () => {
  2307. let nt = new nullTools();
  2308. nt.define(win, 'perX1', 2);
  2309. createStyle('#advtss, #ad3, a[href*="/ad.admitad.com/"] { display:none!important }');
  2310. };
  2311.  
  2312. scripts['allhentai.ru'] = () => {
  2313. selectiveEval();
  2314. preventPopups();
  2315. scriptLander(() => {
  2316. let _onerror = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'onerror');
  2317. if (!_onerror)
  2318. return;
  2319. _onerror.set = (...args) => console.log(args[0].toString());
  2320. Object.defineProperty(HTMLElement.prototype, 'onerror', _onerror);
  2321. });
  2322. };
  2323.  
  2324. scripts['allmovie.pro'] = {
  2325. other: ['rufilmtv.org'],
  2326. dom: function()
  2327. {
  2328. // pretend to be Android to make site use different played for ads
  2329. if (isSafari)
  2330. return;
  2331. Object.defineProperty(navigator, 'userAgent', {
  2332. 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'; },
  2333. enumerable: true
  2334. });
  2335. }
  2336. };
  2337.  
  2338. scripts['anidub-online.ru'] = {
  2339. other: ['online.anidub.com'],
  2340. dom: function()
  2341. {
  2342. if (win.ogonekstart1)
  2343. win.ogonekstart1 = () => console.log("Fire in the hole!");
  2344. },
  2345. now: () => createStyle([
  2346. '.background {background: none!important;}',
  2347. '.background > script + div,'+
  2348. '.background > script ~ div:not([id]):not([class]) + div[id][class]'+
  2349. '{display:none!important}'
  2350. ])
  2351. };
  2352.  
  2353. scripts['drive2.ru'] = () => gardener('.c-block:not([data-metrika="recomm"]),.o-grid__item', />Реклама<\//i);
  2354.  
  2355. scripts['fishki.net'] = () => {
  2356. scriptLander(() => {
  2357. let nt = new nullTools();
  2358. let fishki = {};
  2359. nt.define(fishki, 'adv', nt.proxy({
  2360. afterAdblockCheck: nt.func(null),
  2361. refreshFloat: nt.func(null)
  2362. }));
  2363. nt.define(fishki, 'is_adblock', false);
  2364. nt.define(win, 'fishki', fishki);
  2365. }, nullTools);
  2366. gardener('.drag_list > .drag_element, .list-view > .paddingtop15, .post-wrap', /543769|Новости\sпартнеров|Полезная\sреклама/);
  2367. };
  2368.  
  2369. scripts['gidonline.club'] = () => createStyle('.tray > div[style] {display: none!important}');
  2370.  
  2371. scripts['hdgo.cc'] = {
  2372. other: ['46.30.43.38', 'couber.be'],
  2373. now: () => (new MutationObserver(
  2374. (ms) => {
  2375. let m, node;
  2376. for (m of ms) for (node of m.addedNodes)
  2377. if (node.tagName instanceof HTMLScriptElement && _getAttribute.call(node, 'onerror') !== null)
  2378. node.removeAttribute('onerror');
  2379. }
  2380. )).observe(document.documentElement, { childList:true, subtree: true })
  2381. };
  2382.  
  2383. scripts['gismeteo.ru'] = {
  2384. other: ['gismeteo.ua'],
  2385. now: () => gardener('div > script', /AdvManager/i, { observe: true, parent: 'div' })
  2386. };
  2387.  
  2388. scripts['hdrezka.ag'] = () => {
  2389. Object.defineProperty(win, 'ab', { value: false, enumerable: true });
  2390. gardener('div[id][onclick][onmouseup][onmousedown]', /onmouseout/i);
  2391. };
  2392.  
  2393. scripts['hideip.me'] = {
  2394. now: () => scriptLander(() => {
  2395. let _innerHTML = Object.getOwnPropertyDescriptor(Element.prototype, 'innerHTML');
  2396. let _set_innerHTML = _innerHTML.set;
  2397. let _innerText = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'innerText');
  2398. let _get_innerText = _innerText.get;
  2399. let div = document.createElement('div');
  2400. _innerHTML.set = function(...args) {
  2401. _set_innerHTML.call(div, args[0].replace('i','a'));
  2402. if (args[0] && /[рp][еe]кл/.test(_get_innerText.call(div))||
  2403. /(\d\d\d?\.){3}\d\d\d?\:\d/.test(_get_innerText.call(this)) ) {
  2404. console.log('Anti-Adblock killed.');
  2405. return true;
  2406. }
  2407. _set_innerHTML.apply(this, args);
  2408. };
  2409. Object.defineProperty(Element.prototype, 'innerHTML', _innerHTML);
  2410. Object.defineProperty(win, 'adblock', {
  2411. get: x => false,
  2412. set: x => null,
  2413. enumerable: true
  2414. });
  2415. let _$ = {};
  2416. let _$_map = new WeakMap();
  2417. let _gOPD = Object.getOwnPropertyDescriptor(Object, 'getOwnPropertyDescriptor');
  2418. let _val_gOPD = _gOPD.value;
  2419. _gOPD.value = function(...args) {
  2420. let _res = _val_gOPD.apply(this, args);
  2421. if (args[0] instanceof Window && (args[1] === '$' || args[1] === 'jQuery')) {
  2422. delete _res.get;
  2423. delete _res.set;
  2424. _res.value = win[args[1]];
  2425. }
  2426. return _res;
  2427. };
  2428. Object.defineProperty(Object, 'getOwnPropertyDescriptor', _gOPD);
  2429. let getJQWrap = (n) => {
  2430. let name = n;
  2431. return {
  2432. enumerable: true,
  2433. get: x => _$[name],
  2434. set: x => {
  2435. if (_$_map.has(x)) {
  2436. _$[name] = _$_map.get(x);
  2437. return true;
  2438. }
  2439. if (x === _$.$ || x === _$.jQuery) {
  2440. _$[name] = x;
  2441. return true;
  2442. }
  2443. _$[name] = new Proxy(x, {
  2444. apply: (t, o, args) => {
  2445. let _res = t.apply(o, args);
  2446. if (_$_map.has(_res.is)) {
  2447. _res.is = _$_map.get(_res.is);
  2448. } else {
  2449. let _is = _res.is;
  2450. _res.is = function(...args) {
  2451. if (args[0] === ':hidden')
  2452. return false;
  2453. return _is.apply(this, args);
  2454. };
  2455. _$_map.set(_is, _res.is);
  2456. }
  2457. return _res;
  2458. }
  2459. });
  2460. _$_map.set(x, _$[name]);
  2461. return true;
  2462. }
  2463. };
  2464. };
  2465. Object.defineProperty(win, '$', getJQWrap('$'));
  2466. Object.defineProperty(win, 'jQuery', getJQWrap('jQuery'));
  2467. let _dP = Object.defineProperty;
  2468. Object.defineProperty = function(...args) {
  2469. if (args[0] instanceof Window && (args[1] === '$' || args[1] === 'jQuery'))
  2470. return void 0;
  2471. return _dP.apply(this, args);
  2472. };
  2473. })
  2474. };
  2475.  
  2476. scripts['igra-prestoloff.cx'] = () => scriptLander(() => {
  2477. let nt = new nullTools();
  2478. /*jslint evil: true */ // yes, evil, I know
  2479. let _write = document.write.bind(document);
  2480. /*jslint evil: false */
  2481. nt.define(document, 'write', t => {
  2482. let id = t.match(/jwplayer\("(\w+)"\)/i);
  2483. if (id && id[1]) {
  2484. return _write(`<div id="${id[1]}"></div>${t}`);
  2485. } else {
  2486. return _write('');
  2487. }
  2488. });
  2489. });
  2490.  
  2491. scripts['imageban.ru'] = {
  2492. now: () => {
  2493. Object.defineProperty(win, 'V7x1J', { get: () => null });
  2494. //preventPopunders();
  2495. }
  2496. };
  2497.  
  2498. scripts['kinopoisk.ru'] = {
  2499. now: () => {
  2500. // set no-branding body style
  2501. createStyle('body:not(#id) { background: #d5d5d5 url(/images/noBrandBg.jpg) 50% 0 no-repeat !important }');
  2502. },
  2503. dom: () => {
  2504. (style => style ? style.parentNode.removeChild(style) : console.log('Unable to locate branding style.')
  2505. )(_de.querySelector('#branding-style'));
  2506. }
  2507. };
  2508.  
  2509. scripts['korrespondent.net'] = {
  2510. now: () => scriptLander(() => {
  2511. let nt = new nullTools();
  2512. nt.define(win, 'holder', function(id) {
  2513. let div = document.getElementById(id);
  2514. if (!div)
  2515. return;
  2516. if (div.parentNode.classList.contains('col__sidebar')) {
  2517. div.parentNode.appendChild(div);
  2518. div.style.height = '300px';
  2519. }
  2520. });
  2521. }, nullTools),
  2522. dom: () => {
  2523. for (let frame of document.querySelectorAll('.unit-side-informer > iframe'))
  2524. frame.parentNode.style.width = '1px';
  2525. }
  2526. };
  2527.  
  2528. scripts['mail.ru'] = () => scriptLander(() => {
  2529. let nt = new nullTools();
  2530. // Trick to prevent mail.ru from removing 3rd-party styles
  2531. nt.define(Object.prototype, 'restoreVisibility', nt.func(null), false);
  2532. // Disable some of their counters
  2533. nt.define(win, 'rb_counter', nt.func(null, 'rb_counter'));
  2534. if (location.hostname !== 'e.mail.ru')
  2535. nt.define(win, 'createRadar', nt.func(nt.func(null, 'aRadar'), 'createRadar'));
  2536. else
  2537. nt.define(win, 'aRadar', nt.func(null, 'aRadar'));
  2538.  
  2539. // Disable page scrambler on mail.ru to let extensions easily block ads there
  2540. function defineLocator(root)
  2541. {
  2542. let _locator;
  2543. let fishnet = {
  2544. apply: (target, thisArg, args) => {
  2545. console.log(`locator.${target._name}(${JSON.stringify(args).slice(1,-1)})`);
  2546. return target.apply(thisArg, args);
  2547. }
  2548. };
  2549.  
  2550. function wrapLocator(locator)
  2551. {
  2552. if ('setup' in locator)
  2553. {
  2554. let _setup = locator.setup;
  2555. locator.setup = function(o)
  2556. {
  2557. if ('enable' in o)
  2558. {
  2559. o.enable = false;
  2560. console.log('Disable mimic mode.');
  2561. }
  2562. if ('links' in o)
  2563. {
  2564. o.links = [];
  2565. console.log('Call with empty list of sheets.');
  2566. }
  2567. return _setup.call(this, o);
  2568. };
  2569. locator.insertSheet = () => console.log('Ignore insertSheet.');
  2570. locator.wrap = () => console.log('Ignore wrap.');
  2571. }
  2572. try {
  2573. let names = [];
  2574. for (let name in locator)
  2575. if (locator[name] instanceof Function) {
  2576. locator[name]._name = name;
  2577. locator[name] = new Proxy(locator[name], fishnet);
  2578. names.push(name);
  2579. }
  2580. console.log(`[locator] wrapped properties: ${names.join(', ')}`);
  2581. } catch(e) {
  2582. console.log(e);
  2583. }
  2584. _locator = locator;
  2585. }
  2586.  
  2587. if ('locator' in root && root.locator)
  2588. {
  2589. console.log('Found existing "locator" object. :|');
  2590. _locator = root.locator;
  2591. wrapLocator(root.locator);
  2592. }
  2593.  
  2594. let loc_desc = Object.getOwnPropertyDescriptor(root, 'locator');
  2595. if (!loc_desc || loc_desc.set !== wrapLocator)
  2596. try {
  2597. Object.defineProperty(root, 'locator', {
  2598. set: wrapLocator,
  2599. get: () => _locator
  2600. });
  2601. } catch (err) {
  2602. console.log('Unable to redefine "locator" object!!!', err);
  2603. }
  2604. }
  2605.  
  2606. function defineDetector(mr)
  2607. {
  2608. let __ = mr._ || {};
  2609.  
  2610. if ('HONEYPOT' in __)
  2611. {
  2612. console.log('Disarming existing detector instance. :|', JSON.stringify(__));
  2613. nt.define(__, 'HONEYPOT', '.honeypot_fake_class_to_miss');
  2614. nt.define(__, 'STUCK_IN_POT', false);
  2615. }
  2616.  
  2617. __ = new Proxy(__, {
  2618. get: (t, p) => t[p],
  2619. set: (t, p, v) => {
  2620. console.log(`mr._.${p} =`, v);
  2621. if (['HONEYPOT', 'STUCK_IN_POT'].includes(p))
  2622. console.log('Not changed.');
  2623. t[p] = v; // setter in nt.define will prevent this when needed
  2624. return true;
  2625. }
  2626. });
  2627. Object.defineProperty(mr, '_', {
  2628. enumerable: true,
  2629. value: __
  2630. });
  2631. }
  2632.  
  2633. if (location.hostname === 'e.mail.ru')
  2634. defineLocator(win);
  2635. else {
  2636. try {
  2637. let _mr;
  2638. Object.defineProperty(win, 'mr', {
  2639. enumerable: true,
  2640. get: () => _mr,
  2641. set: (v) => {
  2642. if (v === _mr)
  2643. return true;
  2644. console.log('Trapped new "mr" object.');
  2645. defineLocator(v.mimic ? v.mimic : v);
  2646. defineDetector(v);
  2647. _mr = v;
  2648. }
  2649. });
  2650. if (!('mr' in win))
  2651. throw 'Wat!?';
  2652. } catch (e) {
  2653. console.log('Found existing "mr" object.', e instanceof TypeError ? '' : e);
  2654. defineLocator(win.mr);
  2655. defineDetector(win.mr);
  2656. }
  2657. }
  2658. }, nullTools);
  2659.  
  2660. scripts['megogo.net'] = {
  2661. now: () => {
  2662. let nt = new nullTools();
  2663. nt.define(win, 'adBlock', false);
  2664. nt.define(win, 'showAdBlockMessage', nt.func(null));
  2665. }
  2666. };
  2667.  
  2668. scripts['naruto-base.su'] = () => gardener('div[id^="entryID"],.block', /href="http.*?target="_blank"/i);
  2669.  
  2670. scripts['overclockers.ru'] = {
  2671. now: () => scriptLander(() => {
  2672. let _innerHTML = Object.getOwnPropertyDescriptor(Element.prototype, 'innerHTML');
  2673. let _set_innerHTML = _innerHTML.set;
  2674. _innerHTML.set = function() {
  2675. if (this === document.body) {
  2676. console.log('Anti-Adblock killed.');
  2677. return true;
  2678. }
  2679. _set_innerHTML.apply(this, arguments);
  2680. };
  2681. Object.defineProperty(Element.prototype, 'innerHTML', _innerHTML);
  2682. })
  2683. };
  2684. scripts['forums.overclockers.ru'] = {
  2685. now: () => {
  2686. createStyle('.needblock {position: fixed; left: -10000px}');
  2687. Object.defineProperty(win, 'adblck', {
  2688. get: () => 'no',
  2689. set: () => undefined,
  2690. enumerable: true
  2691. });
  2692. }
  2693. };
  2694.  
  2695. scripts['pb.wtf'] = {
  2696. other: ['piratbit.org', 'piratbit.ru'],
  2697. now: () => {
  2698. // line above topic content and images in the slider in the header
  2699. gardener(
  2700. 'a[href^="/exit/"], a[href^="/fxt/"], a[href$="=="]',
  2701. /img|Реклама|center/i,
  2702. { root: '.release-navbar,#page_content', observe: true, parent: 'div,tr' }
  2703. );
  2704. // ads in comments
  2705. gardener('img[data-name="PiraBo"]', /./i, {root:'#main_content .table', observe:true, parent:'tr'});
  2706. }
  2707. };
  2708.  
  2709. scripts['pikabu.ru'] = () => gardener('.story', /story__author[^>]+>ads</i, {root: '.inner_wrap', observe: true});
  2710.  
  2711. scripts['peka2.tv'] = () => {
  2712. let bodyClass = 'body--branding';
  2713. let checkNode = node => {
  2714. for (let className of node.classList)
  2715. if (className.includes('banner') || className === bodyClass) {
  2716. _removeAttribute.call(node, 'style');
  2717. node.classList.remove(className);
  2718. for (let attr of Array.from(node.attributes)) {
  2719. if (attr.name.startsWith('advert'))
  2720. _removeAttribute.call(node, attr.name);
  2721. }
  2722. }
  2723. };
  2724. (new MutationObserver(ms => {
  2725. let m, node;
  2726. for (m of ms) for (node of m.addedNodes)
  2727. if (node instanceof HTMLElement)
  2728. checkNode(node);
  2729. })).observe(_de, {childList: true, subtree: true});
  2730. (new MutationObserver(ms => {
  2731. for (let m of ms)
  2732. checkNode(m.target);
  2733. })).observe(_de, {attributes: true, subtree: true, attributeFilter: ['class']});
  2734. };
  2735.  
  2736. scripts['qrz.ru'] = {
  2737. now: () => {
  2738. let nt = new nullTools();
  2739. nt.define(win, 'ab', false);
  2740. nt.define(win, 'tryMessage', nt.func(null));
  2741. }
  2742. };
  2743.  
  2744. scripts['razlozhi.ru'] = {
  2745. now: () => {
  2746. for (let func of ['createShadowRoot', 'attachShadow'])
  2747. if (func in Element.prototype)
  2748. Element.prototype[func] = function(){ return this.cloneNode(); };
  2749. }
  2750. };
  2751.  
  2752. scripts['rbc.ru'] = {
  2753. dom: () => {
  2754. let _preventDefault = Event.prototype.preventDefault;
  2755. Event.prototype.preventDefault = function preventDefault()
  2756. {
  2757. let t = this.target;
  2758. if (t instanceof HTMLAnchorElement || t.closest('A'))
  2759. throw new Error('an.yandex redirect prevention');
  2760. return _preventDefault.call(this);
  2761. };
  2762.  
  2763. function cleaner(nodes)
  2764. {
  2765. for (let node of nodes)
  2766. {
  2767. if (!node.classList || !node.classList.contains('js-yandex-counter'))
  2768. continue;
  2769. node.classList.remove('js-yandex-counter');
  2770. node.removeAttribute('data-yandex-name');
  2771. node.removeAttribute('data-yandex-params');
  2772. }
  2773. }
  2774. cleaner(_de.querySelectorAll('.js-yandex-counter'));
  2775.  
  2776. (new MutationObserver(
  2777. ms => { for (let m of ms) cleaner(m.addedNodes); }
  2778. )).observe(_de, {childList: true, subtree: true});
  2779. }
  2780. };
  2781.  
  2782. scripts['rp5.ru'] = {
  2783. other: ['rp5.by', 'rp5.kz', 'rp5.ua'],
  2784. now: () => gardener('div[id][class]', /\?AdvertMgmt=|adsbygoogle/, { root: '#content-wrapper', log: true })
  2785. };
  2786.  
  2787. scripts['rutube.ru'] = () => scriptLander(() => {
  2788. let _parse = JSON.parse.bind(JSON);
  2789. let _skip_enabled = false;
  2790. JSON.parse = (...args) => {
  2791. let res = _parse(...args),
  2792. log = false;
  2793. if (!res)
  2794. return res;
  2795. // parse player configuration
  2796. if ('appearance' in res || 'video_balancer' in res) {
  2797. log = true;
  2798. if ('appearance' in res) {
  2799. res.appearance.forbid_seek = false;
  2800. res.appearance.forbid_timeline_preview = false;
  2801. }
  2802. _skip_enabled = !!res.remove_unseekable_blocks;
  2803. res.advert = [];
  2804. for (let limit of res.limits)
  2805. limit.limit = 0;
  2806. res.yast = null;
  2807. res.yast_live_online = null;
  2808. Object.defineProperty(res, 'stat', {
  2809. get: x => [],
  2810. set: x => true,
  2811. enumerable: true
  2812. });
  2813. }
  2814.  
  2815. // parse video configuration
  2816. if ('video_url' in res) {
  2817. log = true;
  2818. if ('cuepoints' in res && !_skip_enabled)
  2819. for (let point of res.cuepoints) {
  2820. point.is_pause = false;
  2821. point.show_navigation = true;
  2822. point.forbid_seek = false;
  2823. }
  2824. }
  2825.  
  2826. if (log)
  2827. console.log('[rutube]', res);
  2828. return res;
  2829. };
  2830. });
  2831.  
  2832. scripts['simpsonsua.com.ua'] = () => scriptLander(() => {
  2833. let _addEventListener = Object.getPrototypeOf(HTMLDocument).prototype.addEventListener;
  2834. document.addEventListener = function(event, callback) {
  2835. if (event === 'DOMContentLoaded' && callback.toString().includes('show_warning'))
  2836. return;
  2837. return _addEventListener.apply(this, arguments);
  2838. };
  2839. });
  2840.  
  2841. scripts['spaces.ru'] = () => {
  2842. gardener('div:not(.f-c_fll) > a[href*="spaces.ru/?Cl="]', /./, { parent: 'div' });
  2843. gardener('.js-banner_rotator', /./, { parent: '.widgets-group' });
  2844. };
  2845.  
  2846. scripts['spam-club.blogspot.co.uk'] = () => {
  2847. let _clientHeight = Object.getOwnPropertyDescriptor(Element.prototype, 'clientHeight'),
  2848. _clientWidth = Object.getOwnPropertyDescriptor(Element.prototype, 'clientWidth');
  2849. let wrapGetter = (getter) => {
  2850. let _getter = getter;
  2851. return function()
  2852. {
  2853. let _size = _getter.apply(this, arguments);
  2854. return _size ? _size : 1;
  2855. };
  2856. };
  2857. _clientHeight.get = wrapGetter(_clientHeight.get);
  2858. _clientWidth.get = wrapGetter(_clientWidth.get);
  2859. Object.defineProperty(Element.prototype, 'clientHeight', _clientHeight);
  2860. Object.defineProperty(Element.prototype, 'clientWidth', _clientWidth);
  2861. let _onload = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'onload'),
  2862. _set_onload = _onload.set;
  2863. _onload.set = function()
  2864. {
  2865. if (this instanceof HTMLImageElement)
  2866. return true;
  2867. _set_onload.apply(this, arguments);
  2868. };
  2869. Object.defineProperty(HTMLElement.prototype, 'onload', _onload);
  2870. };
  2871.  
  2872. scripts['sport-express.ru'] = () => gardener('.js-relap__item',/>Реклама\s+<\//, {root:'.container', observe: true});
  2873.  
  2874. scripts['sports.ru'] = {
  2875. now: () => {
  2876. gardener('.aside-news-list__item', /aside-news-list__advert/i, {root:'.columns-layout__left', observe: true});
  2877. gardener('.material-list__item', /Реклама/i, {root:'.columns-layout', observe: true});
  2878. // extra functionality: shows/hides panel at the top depending on scroll direction
  2879. createStyle([
  2880. '.user-panel__fixed { transition: top 0.2s ease-in-out!important; }',
  2881. '.user-panel-up { top: -40px!important }'
  2882. ], {id: 'userPanelSlide'}, false);
  2883. },
  2884. dom: () => {
  2885. (function lookForPanel()
  2886. {
  2887. let panel = document.querySelector('.user-panel__fixed');
  2888. if (!panel)
  2889. setTimeout(lookForPanel, 100);
  2890. else
  2891. window.addEventListener(
  2892. 'wheel', function(e)
  2893. {
  2894. if (e.deltaY > 0 && !panel.classList.contains('user-panel-up'))
  2895. panel.classList.add('user-panel-up');
  2896. else if (e.deltaY < 0 && panel.classList.contains('user-panel-up'))
  2897. panel.classList.remove('user-panel-up');
  2898. }, false
  2899. );
  2900. })();
  2901. }
  2902. };
  2903.  
  2904. scripts['stealthz.ru'] = {
  2905. dom: () => {
  2906. // skip timeout
  2907. let $ = document.querySelector.bind(document);
  2908. let [timer_1, timer_2] = [$('#timer_1'), $('#timer_2')];
  2909. if (!timer_1 || !timer_2)
  2910. return;
  2911. timer_1.style.display = 'none';
  2912. timer_2.style.display = 'block';
  2913. }
  2914. };
  2915.  
  2916. scripts['yap.ru'] = {
  2917. other: ['yaplakal.com'],
  2918. now: () => {
  2919. gardener('form > table[id^="p_row_"]:nth-of-type(2)', /member1438|Administration/);
  2920. gardener('.icon-comments', /member1438|Administration|\/go\/\?http/, {parent:'tr', siblings:-2});
  2921. }
  2922. };
  2923.  
  2924. scripts['rambler.ru'] = {
  2925. other: ['championat.com','gazeta.ru','media.eagleplatform.com','lenta.ru', 'quto.ru'],
  2926. now: () => scriptLander(() => {
  2927. // Prevent autoplay
  2928. if (!('EaglePlayer' in win)) {
  2929. let _EaglePlayer = void 0;
  2930. Object.defineProperty(win, 'EaglePlayer', {
  2931. enumerable: true,
  2932. get: x => _EaglePlayer,
  2933. set: x => {
  2934. if (x === _EaglePlayer)
  2935. return true;
  2936. _EaglePlayer = x;
  2937. let _init = void 0;
  2938. Object.defineProperty(_EaglePlayer.prototype, 'init', {
  2939. enumerable: true,
  2940. set: x => _init = x,
  2941. get: function() {
  2942. let _self = this;
  2943. if (_self.options) {
  2944. Object.defineProperty(this.options, 'autoplay', {
  2945. enumerable: true,
  2946. get: x => false,
  2947. set: x => null
  2948. });
  2949. }
  2950. if (_self.options && _self.options.el && inIFrame) {
  2951. let addListener = (player) => {
  2952. console.log('Attached autostop');
  2953. player.addEventListener('canplay', e => {
  2954. e.target.play = () => console.log('Applied autostop.');
  2955. setTimeout(player => {
  2956. delete player.play;
  2957. console.log('Detached autostop');
  2958. }, 1500, e.target);
  2959. }, false);
  2960. };
  2961. (new MutationObserver(ms => {
  2962. let m, node;
  2963. for (m of ms) for (node of m.addedNodes)
  2964. if (node instanceof HTMLVideoElement)
  2965. addListener(node);
  2966. })).observe(this.options.el, { childList: true, subtree: true });
  2967. }
  2968. return _init;
  2969. }
  2970. });
  2971. }
  2972. });
  2973. let _setAttribute = Element.prototype.setAttribute;
  2974. let isAutoplay = /^autoplay$/i;
  2975. Element.prototype.setAttribute = function setAttribute(name)
  2976. {
  2977. if (!this._stopped && isAutoplay.test(name))
  2978. {
  2979. console.log('Prevented assigning autoplay attribute.');
  2980. return null;
  2981. }
  2982. return _setAttribute.apply(this, arguments);
  2983. };
  2984. } else if (inIFrame) {
  2985. let _setAttribute = Element.prototype.setAttribute;
  2986. let isAutoplay = /^autoplay$/i;
  2987. Element.prototype.setAttribute = function setAttribute(name)
  2988. {
  2989. if (!this._stopped && isAutoplay.test(name))
  2990. {
  2991. console.log('Prevented assigning autoplay attribute.');
  2992. this._stopped = true;
  2993. this.play = () => {
  2994. console.log('Prevented attempt to force-start playback.');
  2995. delete this.play;
  2996. };
  2997. return null;
  2998. }
  2999. return _setAttribute.apply(this, arguments);
  3000. };
  3001. }
  3002. if (location.hostname.endsWith('.media.eagleplatform.com'))
  3003. return;
  3004. let CSSRuleProto = 'cssText' in CSSRule.prototype ? CSSRule.prototype : CSSStyleRule.prototype;
  3005. let _cssText = Object.getOwnPropertyDescriptor(CSSRuleProto, 'cssText');
  3006. let _cssText_get = _cssText.get;
  3007. _cssText.configurable = false;
  3008. _cssText.get = function()
  3009. {
  3010. let cssText = _cssText_get.call(this);
  3011. if (cssText.includes('content:'))
  3012. {
  3013. console.log('Blocked access to suspicious cssText:', cssText.slice(0,60), '\u2026', cssText.length);
  3014. return null;
  3015. }
  3016. return cssText;
  3017. };
  3018. Object.defineProperty(CSSRuleProto, 'cssText', _cssText);
  3019. // fake global Adf object
  3020. let nt = new nullTools();
  3021. let Adf_banner = {};
  3022. [
  3023. 'reloadssp', 'sspScroll',
  3024. 'sspRich', 'ssp'
  3025. ].forEach(name => Adf_banner[name] = nt.proxy(() => new Promise((r,j) => r({status: true}))));
  3026. nt.define(win, 'Adf', nt.proxy({
  3027. banner: nt.proxy(Adf_banner)
  3028. }));
  3029. // extra script to remove partner news on gazeta.ru
  3030. if (!location.hostname.includes('gazeta.ru'))
  3031. return;
  3032. (new MutationObserver(
  3033. (ms) => {
  3034. let m, node, header;
  3035. for (m of ms) for (node of m.addedNodes)
  3036. if (node instanceof HTMLDivElement && node.matches('.sausage'))
  3037. {
  3038. header = node.querySelector('.sausage-header');
  3039. if (header && /новости\s+партн[её]ров/i.test(header.textContent))
  3040. node.style.display = 'none';
  3041. }
  3042. }
  3043. )).observe(document.documentElement, { childList:true, subtree: true });
  3044. }, `let inIFrame = ${inIFrame}`, nullTools)
  3045. };
  3046.  
  3047. scripts['reactor.cc'] = {
  3048. other: ['joyreactor.cc', 'pornreactor.cc'],
  3049. now: () => {
  3050. selectiveEval();
  3051. scriptLander(() => {
  3052. let nt = new nullTools();
  3053. win.open = (function(){ throw new Error('Redirect prevention.'); }).bind(window);
  3054. nt.define(win, 'Worker', function(){});
  3055. nt.define(win, 'JRCH', win.CoinHive);
  3056. }, nullTools);
  3057. },
  3058. click: function(e)
  3059. {
  3060. let node = e.target;
  3061. if (node.nodeType === _Node.ELEMENT_NODE &&
  3062. node.style.position === 'absolute' &&
  3063. node.style.zIndex > 0)
  3064. node.parentNode.removeChild(node);
  3065. },
  3066. dom: function()
  3067. {
  3068. let words = new RegExp(
  3069. 'блокировщик рекламы'
  3070. .split('')
  3071. .map(function(e){return e+'[\u200b\u200c\u200d]*';})
  3072. .join('')
  3073. .replace(' ', '\\s*')
  3074. .replace(/[аоре]/g, function(e){return ['[аa]','[оo]','[рp]','[еe]']['аоре'.indexOf(e)];}),
  3075. 'i'),
  3076. can;
  3077. function deeper(spider)
  3078. {
  3079. let c, l, n;
  3080. if (words.test(spider.innerText))
  3081. {
  3082. if (spider.nodeType === _Node.TEXT_NODE)
  3083. return true;
  3084. c = spider.childNodes;
  3085. l = c.length;
  3086. n = 0;
  3087. while(l--)
  3088. if (deeper(c[l]), can)
  3089. n++;
  3090. if (n > 0 && n === c.length && spider.offsetHeight < 750)
  3091. can.push(spider);
  3092. return false;
  3093. }
  3094. return true;
  3095. }
  3096. function probe()
  3097. {
  3098. if (words.test(document.body.innerText))
  3099. {
  3100. can = [];
  3101. deeper(document.body);
  3102. let i = can.length, spider;
  3103. while(i--) {
  3104. spider = can[i];
  3105. if (spider.offsetHeight > 10 && spider.offsetHeight < 750)
  3106. _setAttribute.call(spider, 'style', 'background:none!important');
  3107. }
  3108. }
  3109. }
  3110. (new MutationObserver(probe))
  3111. .observe(document, { childList:true, subtree:true });
  3112. }
  3113. };
  3114.  
  3115. scripts['auto.ru'] = () => {
  3116. let words = /Реклама|Яндекс.Директ|yandex_ad_/;
  3117. let userAdsListAds = (
  3118. '.listing-list > .listing-item,'+
  3119. '.listing-item_type_fixed.listing-item'
  3120. );
  3121. let catalogAds = (
  3122. 'div[class*="layout_catalog-inline"],'+
  3123. 'div[class$="layout_horizontal"]'
  3124. );
  3125. let otherAds = (
  3126. '.advt_auto,'+
  3127. '.sidebar-block,'+
  3128. '.pager-listing + div[class],'+
  3129. '.card > div[class][style],'+
  3130. '.sidebar > div[class],'+
  3131. '.main-page__section + div[class],'+
  3132. '.listing > tbody'
  3133. );
  3134. gardener(userAdsListAds, words, {root:'.listing-wrap', observe:true});
  3135. gardener(catalogAds, words, {root:'.catalog__page,.content__wrapper', observe:true});
  3136. gardener(otherAds, words);
  3137. };
  3138.  
  3139. scripts['rsload.net'] = {
  3140. load: () => {
  3141. let dis = document.querySelector('label[class*="cb-disable"]');
  3142. if (dis)
  3143. dis.click();
  3144. },
  3145. click: () => {
  3146. let t = e.target;
  3147. if (t && t.href && (/:\/\/\d+\.\d+\.\d+\.\d+\//.test(t.href)))
  3148. t.href = t.href.replace('://','://rsload.net:rsload.net@');
  3149. }
  3150. };
  3151.  
  3152. let domain;
  3153. // add alternative domain names if present and wrap functions into objects
  3154. for (let name in scripts)
  3155. {
  3156. if (scripts[name] instanceof Function)
  3157. scripts[name] = { now: scripts[name] };
  3158. for (domain of (scripts[name].other||[]))
  3159. {
  3160. if (domain in scripts)
  3161. console.log('Error in scripts list. Script for', name, 'replaced script for', domain);
  3162. scripts[domain] = scripts[name];
  3163. }
  3164. delete scripts[name].other;
  3165. }
  3166. // look for current domain in the list and run appropriate code
  3167. domain = document.domain;
  3168. while (domain.indexOf('.') > -1)
  3169. {
  3170. if (domain in scripts) for (let when in scripts[domain])
  3171. switch(when)
  3172. {
  3173. case 'now':
  3174. scripts[domain][when]();
  3175. break;
  3176. case 'dom':
  3177. document.addEventListener('DOMContentLoaded', scripts[domain][when], false);
  3178. break;
  3179. default:
  3180. document.addEventListener (when, scripts[domain][when], false);
  3181. }
  3182. domain = domain.slice(domain.indexOf('.') + 1);
  3183. }
  3184.  
  3185. // Batch script lander
  3186. if (!skipLander)
  3187. landScript(batchLand, batchPrepend);
  3188.  
  3189. { // JS Fixes Tools Menu
  3190. let openOptions = function()
  3191. {
  3192. let ovl = _createElement('div'),
  3193. inner = _createElement('div');
  3194. ovl.style = (
  3195. 'position: fixed;'+
  3196. 'top:0; left:0;'+
  3197. 'bottom: 0; right: 0;'+
  3198. 'background: rgba(0,0,0,0.85);'+
  3199. 'z-index: 2147483647;'+
  3200. 'padding: 5em'
  3201. );
  3202. inner.style = (
  3203. 'background: whitesmoke;'+
  3204. 'font-size: 10pt;'+
  3205. 'color: black;'+
  3206. 'padding: 1em'
  3207. );
  3208. inner.textContent = 'JS Fixes Tools';
  3209. inner.appendChild(_createElement('br'));
  3210. inner.appendChild(_createElement('br'));
  3211. ovl.addEventListener(
  3212. 'click', function(e)
  3213. {
  3214. if (e.target === ovl) {
  3215. ovl.parentNode.removeChild(ovl);
  3216. e.preventDefault();
  3217. }
  3218. e.stopPropagation();
  3219. }, false
  3220. );
  3221.  
  3222. let sObjBtn = _createElement('button');
  3223. sObjBtn.onclick = getStrangeObjectsList;
  3224. sObjBtn.textContent = 'Print (in console) list of unusual window properties';
  3225. inner.appendChild(_createElement('br'));
  3226. inner.appendChild(sObjBtn);
  3227.  
  3228. document.body.appendChild(ovl);
  3229. ovl.appendChild(inner);
  3230. };
  3231.  
  3232. // monitor keys pressed for Ctrl+Alt+Shift+J > s > f code
  3233. let opPos = 0, opKey = ['KeyJ','KeyS','KeyF'];
  3234. document.addEventListener(
  3235. 'keydown', function(e)
  3236. {
  3237. if ((e.code === opKey[opPos] || e.location) &&
  3238. (!!opPos || e.altKey && e.ctrlKey && e.shiftKey))
  3239. {
  3240. opPos += e.location ? 0 : 1;
  3241. e.stopPropagation();
  3242. e.preventDefault();
  3243. } else {
  3244. opPos = 0;
  3245. }
  3246. if (opPos === opKey.length)
  3247. {
  3248. opPos = 0;
  3249. openOptions();
  3250. }
  3251. }, false
  3252. );
  3253. }
  3254. })();