RU AdList JS Fixes

try to take over the world!

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

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