RU AdList JS Fixes

try to take over the world!

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

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