RU AdList JS Fixes

try to take over the world!

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

  1. // ==UserScript==
  2. // @name RU AdList JS Fixes
  3. // @namespace ruadlist_js_fixes
  4. // @version 20180316.0
  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|kingoablc\.com|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 crumbler = e => { // crumble suspicious cookies
  1955. let base = '=; expires=Thu, 01 Jan 1970 00:00:01 UTC; Max-Age=-99999999; path=/';
  1956. console.log('cookies', document.cookie);
  1957. for (let name of ['adblock', 'gophp', '_692293176245', '_692293176246'])
  1958. document.cookie = `${name}${base}`;
  1959. for (let name of ['st2', 'st3']) {
  1960. document.cookie = `${name}${base}forum`;
  1961. document.cookie = `${name}${base}forum/`;
  1962. }
  1963. console.log('cookies', document.cookie);
  1964. };
  1965. document.addEventListener('DOMContentLoaded', crumbler, false);
  1966. crumbler();
  1967.  
  1968. let nt = new nullTools({trace: true});
  1969. nt.define(win, 'syka', false);
  1970. nt.define(win, '_692293176244', location.href);
  1971. [
  1972. 'MTLuxup', 'MTAdSniper', 'MTutarg', 'MTUAatar', 'MTcityAds', 'MTmxMark',
  1973. 'MTmxMark2', 'MTmdnt', 'MTrfDumedia', 'MXsmTDS', 'MTritorno', 'MTadvice',
  1974. 'cyka', 'MTAdTraff', 'MTExebid', 'MXsockFound'
  1975. ].forEach(p => nt.define(win, p, nt.func(null, p)));
  1976. let _eval_def = Object.getOwnPropertyDescriptor(win, 'eval');
  1977. if (!_eval_def)
  1978. return;
  1979. let _eval_val = _eval_def.value;
  1980. _eval_def.value = (...args) => {
  1981. if (args[0] && args[0].includes('antiadblock'))
  1982. return console.log('Anti-AdBlock script may run another day, but not today.');
  1983. return _eval_val.apply(this, args);
  1984. };
  1985. Object.defineProperty(win, 'eval', _eval_def);
  1986. win.open = (...args) => {
  1987. console.warn(`Site attempted to open "${args[0]}" in a new window.`);
  1988. location.replace(location.href);
  1989. return null;
  1990. };
  1991. window.addEventListener('DOMContentLoaded', () => {
  1992. let link = void 0;
  1993. document.body.addEventListener('mousedown', e => {
  1994. link = e.target.closest('a, select, #fancybox-title-wrap');
  1995. }, false);
  1996. let _open = window.open.bind(window);
  1997. let _getAttribute = Element.prototype.getAttribute;
  1998. win.open = (...args) => {
  1999. let url = args[0];
  2000. let allow = false;
  2001. if (link instanceof HTMLAnchorElement) {
  2002. // third-party post links
  2003. let href = _getAttribute.call(link, 'href');
  2004. if (link.classList.contains('postLink') &&
  2005. !link.matches(`a[href*="${location.hostname}"]`) &&
  2006. (href === url || link.href === url)) {
  2007. return _open(...args);
  2008. }
  2009. // onclick # links
  2010. if (href === '#' && /window\.open/.test(_getAttribute.call(link, 'onclick'))) {
  2011. return _open(...args);
  2012. }
  2013. // force local links to load in the current window
  2014. if (href[0] === '/' || href.startsWith('./') || href.includes(`//${location.hostname}/`))
  2015. location.assign(href);
  2016. }
  2017. // list of image hostings under upload picture button (new comment)
  2018. if (link instanceof HTMLSelectElement &&
  2019. !url.includes(location.hostname) &&
  2020. link.value === url) {
  2021. return _open(...args);
  2022. }
  2023. // open screenshot in a new window
  2024. if (link instanceof HTMLSpanElement &&
  2025. link.id === 'fancybox-title-wrap') {
  2026. return _open(...args);
  2027. }
  2028. // looks like tabunder
  2029. if (link === null && url === location.href)
  2030. location.replace(url); // reload current page
  2031. // other cases
  2032. console.warn(`Site attempted to open "${url}" in a new window. Source: `, link);
  2033. return {};
  2034. };
  2035. }, true);
  2036. }, nullTools)
  2037. };
  2038.  
  2039. // other
  2040. scripts['1tv.ru'] = () => scriptLander(() => {
  2041. let nt = new nullTools();
  2042. nt.define(win, 'EUMPAntiblockConfig', nt.proxy({url: '//www.1tv.ru/favicon.ico'}));
  2043. let disablePlugins = {
  2044. 'antiblock': false,
  2045. 'stat1tv': false
  2046. };
  2047. let _EUMPConfig = void 0;
  2048. let _EUMPConfig_set = x => {
  2049. if (x.plugins) {
  2050. x.plugins = x.plugins.filter(plugin => (plugin in disablePlugins) ? !(disablePlugins[plugin] = true) : true);
  2051. console.warn(`Player plugins: active [${x.plugins}], disabled [${Object.keys(disablePlugins).filter(x => disablePlugins[x])}]`);
  2052. }
  2053. _EUMPConfig = x;
  2054. };
  2055. if ('EUMPConfig' in win)
  2056. _EUMPConfig_set(win.EUMPConfig);
  2057. Object.defineProperty(win, 'EUMPConfig', {
  2058. enumerable: true,
  2059. get: x => _EUMPConfig,
  2060. set: _EUMPConfig_set
  2061. });
  2062. }, nullTools);
  2063.  
  2064. scripts['2picsun.ru'] = {
  2065. other: [
  2066. 'pics2sun.ru', '3pics-img.ru'
  2067. ],
  2068. now: () => {
  2069. Object.defineProperty(navigator, 'userAgent', {value: 'googlebot'});
  2070. }
  2071. };
  2072.  
  2073. scripts['4pda.ru'] = {
  2074. now: () => {
  2075. // https://greasyfork.org/en/scripts/14470-4pda-unbrender
  2076. let hStyle,
  2077. isForum = document.location.href.search('/forum/') !== -1,
  2078. remove = (node) => (node ? node.parentNode.removeChild(node) : null),
  2079. afterClean = () => remove(hStyle);
  2080.  
  2081. function beforeClean()
  2082. {
  2083. // attach styles before document displayed
  2084. hStyle = createStyle([
  2085. 'html { overflow-y: scroll }',
  2086. 'article + aside * { display: none !important }',
  2087. `section[id] {${(
  2088. 'position: absolute;'+
  2089. 'width: 100%'
  2090. )}}`,
  2091. `#header + div:after {${(
  2092. 'content: "";'+
  2093. 'position: fixed;'+
  2094. 'top: 0;'+
  2095. 'left: 0;'+
  2096. 'width: 100%;'+
  2097. 'height: 100%;'+
  2098. 'background-color: #E6E7E9'
  2099. )}}`,
  2100. // http://codepen.io/Beaugust/pen/DByiE
  2101. '@keyframes spin { 100% { transform: rotate(360deg) } }',
  2102. `article + aside:after {${(
  2103. 'content: "";'+
  2104. 'position: absolute;'+
  2105. 'width: 150px;'+
  2106. 'height: 150px;'+
  2107. 'top: 150px;'+
  2108. 'left: 50%;'+
  2109. 'margin-top: -75px;'+
  2110. 'margin-left: -75px;'+
  2111. 'box-sizing: border-box;'+
  2112. 'border-radius: 100%;'+
  2113. 'border: 10px solid rgba(0, 0, 0, 0.2);'+
  2114. 'border-top-color: rgba(0, 0, 0, 0.6);'+
  2115. 'animation: spin 2s infinite linear'
  2116. )}}`
  2117. ], {id:'ubrHider'}, true);
  2118.  
  2119. // display content of a page if time to load a page is more than 2 seconds to avoid
  2120. // blocking access to a page if it is loading for too long or stuck in a loading state
  2121. setTimeout(2000, afterClean);
  2122. }
  2123.  
  2124. createStyle([
  2125. '#nav .use-ad { display: block !important }',
  2126. 'article:not(.post) + article:not(#id),'+
  2127. 'html:not(#id)>body:not(#id) a[target="_blank"] img[height="90"] { display: none !important }'
  2128. ]);
  2129.  
  2130. if (!isForum)
  2131. beforeClean();
  2132.  
  2133. // save links to non-overridden functions to use later
  2134. let protectedElems;
  2135. // protect/hide changed attributes in case site attempt to restore them
  2136. function styleProtector(eventMode)
  2137. {
  2138. let _toLowerCase = String.prototype.toLowerCase,
  2139. isStyleText = (t) => (_toLowerCase.call(t) === 'style'),
  2140. protectedElems = new WeakMap();
  2141. function protoOverride(element, functionName, isStyleCheck, returnIfProtected)
  2142. {
  2143. let originalFunction = element.prototype[functionName];
  2144. element.prototype[functionName] = function wrapper()
  2145. {
  2146. if (protectedElems.has(this) && isStyleCheck(arguments[0]))
  2147. return returnIfProtected(this, arguments);
  2148. return originalFunction.apply(this, arguments);
  2149. };
  2150. }
  2151. protoOverride(Element, 'removeAttribute', isStyleText, () => undefined);
  2152. protoOverride(Element, 'hasAttribute', isStyleText, (_this) => protectedElems.get(_this) !== null);
  2153. protoOverride(Element, 'setAttribute', isStyleText, (_this, args) => protectedElems.set(_this, args[1]));
  2154. protoOverride(Element, 'getAttribute', isStyleText, (_this) => protectedElems.get(_this));
  2155. if (!eventMode)
  2156. return protectedElems;
  2157. else
  2158. {
  2159. let e = document.createEvent('Event');
  2160. e.initEvent('protoOverride', false, false);
  2161. window.protectedElems = protectedElems;
  2162. window.dispatchEvent(e);
  2163. }
  2164. }
  2165. if (!isFirefox)
  2166. protectedElems = styleProtector(false);
  2167. else
  2168. {
  2169. let script = document.createElement('script');
  2170. script.textContent = `(${styleProtector.toString()})(true);`;
  2171. window.addEventListener(
  2172. 'protoOverride', function protoOverrideCallback(e)
  2173. {
  2174. if (win.protectedElems) {
  2175. protectedElems = win.protectedElems;
  2176. delete win.protectedElems;
  2177. }
  2178. document.removeEventListener('protoOverride', protoOverrideCallback, true);
  2179. }, true
  2180. );
  2181. _appendChild(script);
  2182. _removeChild(script);
  2183. }
  2184.  
  2185. // clean a page
  2186. window.addEventListener(
  2187. 'DOMContentLoaded', function()
  2188. {
  2189. let width = () => window.innerWidth || _de.clientWidth || document.body.clientWidth || 0;
  2190. let height = () => window.innerHeight || _de.clientHeight || document.body.clientHeight || 0;
  2191.  
  2192. if (isForum)
  2193. {
  2194. let si = document.querySelector('#logostrip');
  2195. if (si)
  2196. remove(si.parentNode.nextSibling);
  2197. }
  2198.  
  2199. // clear background in the download frame
  2200. if (location.pathname.startsWith('/forum/dl/')) {
  2201. let setBackground = node => _setAttribute.call(
  2202. node,
  2203. 'style', (_getAttribute.call(node, 'style') || '') +
  2204. ';background-color:#4ebaf6!important'
  2205. );
  2206. setBackground(document.body);
  2207. for (let itm of document.querySelectorAll('body > div'))
  2208. if (!itm.querySelector('.dw-fdwlink, .content') && !itm.classList.contains('footer')) {
  2209. remove(itm);
  2210. } else {
  2211. setBackground(itm);
  2212. }
  2213. }
  2214.  
  2215. if (isForum) // Do not continue if it's a forum
  2216. return;
  2217.  
  2218. {
  2219. let si = document.querySelector('#header');
  2220. if (si)
  2221. {
  2222. let rem = si.previousSibling;
  2223. while (rem)
  2224. {
  2225. si = rem.previousSibling;
  2226. remove(rem);
  2227. rem = si;
  2228. }
  2229. }
  2230. }
  2231.  
  2232. for (let itm of document.querySelectorAll('#nav li[class]'))
  2233. if (itm && itm.querySelector('a[href^="/tag/"]'))
  2234. remove(itm);
  2235.  
  2236. let style, result,
  2237. fakeStyles = new WeakMap(),
  2238. styleProxy = {
  2239. get: function(target, prop)
  2240. {
  2241. let fakeStyle = fakeStyles.get(target);
  2242. return ((prop in fakeStyle) ? fakeStyle : target)[prop];
  2243. },
  2244. set: function(target, prop, value)
  2245. {
  2246. let fakeStyle = fakeStyles.get(target);
  2247. ((prop in fakeStyle) ? fakeStyle : target)[prop] = value;
  2248. return true;
  2249. }
  2250. };
  2251. for (let itm of document.querySelectorAll('DIV, A'))
  2252. {
  2253. if (itm.tagName ==='DIV' &&
  2254. itm.offsetWidth > 0.95 * width() &&
  2255. itm.offsetHeight > 0.85 * height())
  2256. {
  2257. style = window.getComputedStyle(itm, null);
  2258. result = [];
  2259.  
  2260. if (style.backgroundImage !== 'none')
  2261. result.push('background-image:none!important');
  2262.  
  2263. if (style.backgroundColor !== 'transparent' &&
  2264. style.backgroundColor !== 'rgba(0, 0, 0, 0)')
  2265. result.push('background-color:transparent!important');
  2266.  
  2267. if (result.length)
  2268. {
  2269. if (itm.getAttribute('style'))
  2270. result.unshift(itm.getAttribute('style'));
  2271.  
  2272. fakeStyles.set(itm.style, {
  2273. 'backgroundImage': itm.style.backgroundImage,
  2274. 'backgroundColor': itm.style.backgroundColor
  2275. });
  2276.  
  2277. try {
  2278. Object.defineProperty(itm, 'style', {
  2279. value: new Proxy(itm.style, styleProxy),
  2280. enumerable: true
  2281. });
  2282. } catch (e) {
  2283. console.log('Unable to protect style property.', e);
  2284. }
  2285.  
  2286. if (protectedElems)
  2287. protectedElems.set(itm, _getAttribute.call(itm, 'style'));
  2288.  
  2289. _setAttribute.call(itm, 'style', result.join(';'));
  2290. }
  2291. }
  2292. if (itm.tagName ==='A' &&
  2293. (itm.offsetWidth > 0.95 * width() ||
  2294. itm.offsetHeight > 0.85 * height()))
  2295. {
  2296. if (protectedElems)
  2297. protectedElems.set(itm, _getAttribute.call(itm, 'style'));
  2298.  
  2299. _setAttribute.call(itm, 'style', 'display:none!important');
  2300. }
  2301. }
  2302.  
  2303. for (let itm of document.querySelectorAll('ASIDE>DIV'))
  2304. if ( ((itm.querySelector('script, iframe, a[href*="/ad/www/"]') ||
  2305. itm.querySelector('img[src$=".gif"]:not([height="0"]), img[height="400"]')) &&
  2306. !itm.classList.contains('post') ) || !itm.childNodes.length )
  2307. remove(itm);
  2308.  
  2309. document.body.setAttribute('style', (document.body.getAttribute('style')||'')+';background-color:#E6E7E9!important');
  2310.  
  2311. // display content of the page
  2312. afterClean();
  2313. }
  2314. );
  2315. }
  2316. };
  2317.  
  2318. scripts['adhands.ru'] = () => scriptLander(() => {
  2319. let nt = new nullTools();
  2320. try {
  2321. let _adv;
  2322. Object.defineProperty(win, 'adv', {
  2323. get: () => _adv,
  2324. set: (v) => {
  2325. console.log('Blocked advert on adhands.ru.');
  2326. nt.define(v, 'advert', '');
  2327. _adv = v;
  2328. }
  2329. });
  2330. } catch (ignore) {
  2331. if (!win.adv)
  2332. console.log('Unable to locate advert on adhands.ru.');
  2333. else {
  2334. console.log('Blocked advert on adhands.ru.');
  2335. nt.define(win.adv, 'advert', '');
  2336. }
  2337. }
  2338. }, nullTools);
  2339.  
  2340. scripts['all-episodes.tv'] = () => {
  2341. let nt = new nullTools();
  2342. nt.define(win, 'perX1', 2);
  2343. createStyle('#advtss, #ad3, a[href*="/ad.admitad.com/"] { display:none!important }');
  2344. };
  2345.  
  2346. scripts['allhentai.ru'] = () => {
  2347. selectiveEval();
  2348. preventPopups();
  2349. scriptLander(() => {
  2350. let _onerror = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'onerror');
  2351. if (!_onerror)
  2352. return;
  2353. _onerror.set = (...args) => console.log(args[0].toString());
  2354. Object.defineProperty(HTMLElement.prototype, 'onerror', _onerror);
  2355. });
  2356. };
  2357.  
  2358. scripts['allmovie.pro'] = {
  2359. other: ['rufilmtv.org'],
  2360. dom: function()
  2361. {
  2362. // pretend to be Android to make site use different played for ads
  2363. if (isSafari)
  2364. return;
  2365. Object.defineProperty(navigator, 'userAgent', {
  2366. 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'; },
  2367. enumerable: true
  2368. });
  2369. }
  2370. };
  2371.  
  2372. scripts['anidub-online.ru'] = {
  2373. other: ['online.anidub.com'],
  2374. dom: function()
  2375. {
  2376. if (win.ogonekstart1)
  2377. win.ogonekstart1 = () => console.log("Fire in the hole!");
  2378. },
  2379. now: () => createStyle([
  2380. '.background {background: none!important;}',
  2381. '.background > script + div,'+
  2382. '.background > script ~ div:not([id]):not([class]) + div[id][class]'+
  2383. '{display:none!important}'
  2384. ])
  2385. };
  2386.  
  2387. scripts['drive2.ru'] = () => gardener('.c-block:not([data-metrika="recomm"]),.o-grid__item', />Реклама<\//i);
  2388.  
  2389. scripts['fishki.net'] = () => {
  2390. scriptLander(() => {
  2391. let nt = new nullTools();
  2392. let fishki = {};
  2393. nt.define(fishki, 'adv', nt.proxy({
  2394. afterAdblockCheck: nt.func(null),
  2395. refreshFloat: nt.func(null)
  2396. }));
  2397. nt.define(fishki, 'is_adblock', false);
  2398. nt.define(win, 'fishki', fishki);
  2399. }, nullTools);
  2400. gardener('.drag_list > .drag_element, .list-view > .paddingtop15, .post-wrap', /543769|Новости\sпартнеров|Полезная\sреклама/);
  2401. };
  2402.  
  2403. scripts['gidonline.club'] = () => createStyle('.tray > div[style] {display: none!important}');
  2404.  
  2405. scripts['hdgo.cc'] = {
  2406. other: ['46.30.43.38', 'couber.be'],
  2407. now: () => (new MutationObserver(
  2408. (ms) => {
  2409. let m, node;
  2410. for (m of ms) for (node of m.addedNodes)
  2411. if (node.tagName instanceof HTMLScriptElement && _getAttribute.call(node, 'onerror') !== null)
  2412. node.removeAttribute('onerror');
  2413. }
  2414. )).observe(document.documentElement, { childList:true, subtree: true })
  2415. };
  2416.  
  2417. scripts['gismeteo.ru'] = {
  2418. other: ['gismeteo.ua'],
  2419. now: () => gardener('div > script', /AdvManager/i, { observe: true, parent: 'div' })
  2420. };
  2421.  
  2422. scripts['hdrezka.ag'] = () => {
  2423. Object.defineProperty(win, 'ab', { value: false, enumerable: true });
  2424. gardener('div[id][onclick][onmouseup][onmousedown]', /onmouseout/i);
  2425. };
  2426.  
  2427. scripts['hideip.me'] = {
  2428. now: () => scriptLander(() => {
  2429. let _innerHTML = Object.getOwnPropertyDescriptor(Element.prototype, 'innerHTML');
  2430. let _set_innerHTML = _innerHTML.set;
  2431. let _innerText = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'innerText');
  2432. let _get_innerText = _innerText.get;
  2433. let div = document.createElement('div');
  2434. _innerHTML.set = function(...args) {
  2435. _set_innerHTML.call(div, args[0].replace('i','a'));
  2436. if (args[0] && /[рp][еe]кл/.test(_get_innerText.call(div))||
  2437. /(\d\d\d?\.){3}\d\d\d?\:\d/.test(_get_innerText.call(this)) ) {
  2438. console.log('Anti-Adblock killed.');
  2439. return true;
  2440. }
  2441. _set_innerHTML.apply(this, args);
  2442. };
  2443. Object.defineProperty(Element.prototype, 'innerHTML', _innerHTML);
  2444. Object.defineProperty(win, 'adblock', {
  2445. get: x => false,
  2446. set: x => null,
  2447. enumerable: true
  2448. });
  2449. let _$ = {};
  2450. let _$_map = new WeakMap();
  2451. let _gOPD = Object.getOwnPropertyDescriptor(Object, 'getOwnPropertyDescriptor');
  2452. let _val_gOPD = _gOPD.value;
  2453. _gOPD.value = function(...args) {
  2454. let _res = _val_gOPD.apply(this, args);
  2455. if (args[0] instanceof Window && (args[1] === '$' || args[1] === 'jQuery')) {
  2456. delete _res.get;
  2457. delete _res.set;
  2458. _res.value = win[args[1]];
  2459. }
  2460. return _res;
  2461. };
  2462. Object.defineProperty(Object, 'getOwnPropertyDescriptor', _gOPD);
  2463. let getJQWrap = (n) => {
  2464. let name = n;
  2465. return {
  2466. enumerable: true,
  2467. get: x => _$[name],
  2468. set: x => {
  2469. if (_$_map.has(x)) {
  2470. _$[name] = _$_map.get(x);
  2471. return true;
  2472. }
  2473. if (x === _$.$ || x === _$.jQuery) {
  2474. _$[name] = x;
  2475. return true;
  2476. }
  2477. _$[name] = new Proxy(x, {
  2478. apply: (t, o, args) => {
  2479. let _res = t.apply(o, args);
  2480. if (_$_map.has(_res.is)) {
  2481. _res.is = _$_map.get(_res.is);
  2482. } else {
  2483. let _is = _res.is;
  2484. _res.is = function(...args) {
  2485. if (args[0] === ':hidden')
  2486. return false;
  2487. return _is.apply(this, args);
  2488. };
  2489. _$_map.set(_is, _res.is);
  2490. }
  2491. return _res;
  2492. }
  2493. });
  2494. _$_map.set(x, _$[name]);
  2495. return true;
  2496. }
  2497. };
  2498. };
  2499. Object.defineProperty(win, '$', getJQWrap('$'));
  2500. Object.defineProperty(win, 'jQuery', getJQWrap('jQuery'));
  2501. let _dP = Object.defineProperty;
  2502. Object.defineProperty = function(...args) {
  2503. if (args[0] instanceof Window && (args[1] === '$' || args[1] === 'jQuery'))
  2504. return void 0;
  2505. return _dP.apply(this, args);
  2506. };
  2507. })
  2508. };
  2509.  
  2510. scripts['igra-prestoloff.cx'] = () => scriptLander(() => {
  2511. let nt = new nullTools();
  2512. /*jslint evil: true */ // yes, evil, I know
  2513. let _write = document.write.bind(document);
  2514. /*jslint evil: false */
  2515. nt.define(document, 'write', t => {
  2516. let id = t.match(/jwplayer\("(\w+)"\)/i);
  2517. if (id && id[1]) {
  2518. return _write(`<div id="${id[1]}"></div>${t}`);
  2519. } else {
  2520. return _write('');
  2521. }
  2522. });
  2523. });
  2524.  
  2525. scripts['imageban.ru'] = {
  2526. now: () => {
  2527. Object.defineProperty(win, 'V7x1J', { get: () => null });
  2528. //preventPopunders();
  2529. }
  2530. };
  2531.  
  2532. scripts['kinopoisk.ru'] = {
  2533. now: () => {
  2534. // set no-branding body style
  2535. createStyle('body:not(#id) { background: #d5d5d5 url(/images/noBrandBg.jpg) 50% 0 no-repeat !important }');
  2536. },
  2537. dom: () => {
  2538. (style => style ? style.parentNode.removeChild(style) : console.log('Unable to locate branding style.')
  2539. )(_de.querySelector('#branding-style'));
  2540. }
  2541. };
  2542.  
  2543. scripts['korrespondent.net'] = {
  2544. now: () => scriptLander(() => {
  2545. let nt = new nullTools();
  2546. nt.define(win, 'holder', function(id) {
  2547. let div = document.getElementById(id);
  2548. if (!div)
  2549. return;
  2550. if (div.parentNode.classList.contains('col__sidebar')) {
  2551. div.parentNode.appendChild(div);
  2552. div.style.height = '300px';
  2553. }
  2554. });
  2555. }, nullTools),
  2556. dom: () => {
  2557. for (let frame of document.querySelectorAll('.unit-side-informer > iframe'))
  2558. frame.parentNode.style.width = '1px';
  2559. }
  2560. };
  2561.  
  2562. scripts['mail.ru'] = () => scriptLander(() => {
  2563. let nt = new nullTools();
  2564. // Trick to prevent mail.ru from removing 3rd-party styles
  2565. nt.define(Object.prototype, 'restoreVisibility', nt.func(null), false);
  2566. // Disable some of their counters
  2567. nt.define(win, 'rb_counter', nt.func(null, 'rb_counter'));
  2568. if (location.hostname !== 'e.mail.ru')
  2569. nt.define(win, 'createRadar', nt.func(nt.func(null, 'aRadar'), 'createRadar'));
  2570. else
  2571. nt.define(win, 'aRadar', nt.func(null, 'aRadar'));
  2572.  
  2573. // Disable page scrambler on mail.ru to let extensions easily block ads there
  2574. function defineLocator(root)
  2575. {
  2576. let _locator;
  2577. let fishnet = {
  2578. apply: (target, thisArg, args) => {
  2579. console.log(`locator.${target._name}(${JSON.stringify(args).slice(1,-1)})`);
  2580. return target.apply(thisArg, args);
  2581. }
  2582. };
  2583.  
  2584. function wrapLocator(locator)
  2585. {
  2586. if ('setup' in locator)
  2587. {
  2588. let _setup = locator.setup;
  2589. locator.setup = function(o)
  2590. {
  2591. if ('enable' in o)
  2592. {
  2593. o.enable = false;
  2594. console.log('Disable mimic mode.');
  2595. }
  2596. if ('links' in o)
  2597. {
  2598. o.links = [];
  2599. console.log('Call with empty list of sheets.');
  2600. }
  2601. return _setup.call(this, o);
  2602. };
  2603. locator.insertSheet = () => console.log('Ignore insertSheet.');
  2604. locator.wrap = () => console.log('Ignore wrap.');
  2605. }
  2606. try {
  2607. let names = [];
  2608. for (let name in locator)
  2609. if (locator[name] instanceof Function) {
  2610. locator[name]._name = name;
  2611. locator[name] = new Proxy(locator[name], fishnet);
  2612. names.push(name);
  2613. }
  2614. console.log(`[locator] wrapped properties: ${names.join(', ')}`);
  2615. } catch(e) {
  2616. console.log(e);
  2617. }
  2618. _locator = locator;
  2619. }
  2620.  
  2621. if ('locator' in root && root.locator)
  2622. {
  2623. console.log('Found existing "locator" object. :|');
  2624. _locator = root.locator;
  2625. wrapLocator(root.locator);
  2626. }
  2627.  
  2628. let loc_desc = Object.getOwnPropertyDescriptor(root, 'locator');
  2629. if (!loc_desc || loc_desc.set !== wrapLocator)
  2630. try {
  2631. Object.defineProperty(root, 'locator', {
  2632. set: wrapLocator,
  2633. get: () => _locator
  2634. });
  2635. } catch (err) {
  2636. console.log('Unable to redefine "locator" object!!!', err);
  2637. }
  2638. }
  2639.  
  2640. function defineDetector(mr)
  2641. {
  2642. let __ = mr._ || {};
  2643.  
  2644. if ('HONEYPOT' in __)
  2645. {
  2646. console.log('Disarming existing detector instance. :|', JSON.stringify(__));
  2647. nt.define(__, 'HONEYPOT', '.honeypot_fake_class_to_miss');
  2648. nt.define(__, 'STUCK_IN_POT', false);
  2649. }
  2650.  
  2651. __ = new Proxy(__, {
  2652. get: (t, p) => t[p],
  2653. set: (t, p, v) => {
  2654. console.log(`mr._.${p} =`, v);
  2655. if (['HONEYPOT', 'STUCK_IN_POT'].includes(p))
  2656. console.log('Not changed.');
  2657. t[p] = v; // setter in nt.define will prevent this when needed
  2658. return true;
  2659. }
  2660. });
  2661. Object.defineProperty(mr, '_', {
  2662. enumerable: true,
  2663. value: __
  2664. });
  2665. }
  2666.  
  2667. if (location.hostname === 'e.mail.ru')
  2668. defineLocator(win);
  2669. else {
  2670. try {
  2671. let _mr;
  2672. Object.defineProperty(win, 'mr', {
  2673. enumerable: true,
  2674. get: () => _mr,
  2675. set: (v) => {
  2676. if (v === _mr)
  2677. return true;
  2678. console.log('Trapped new "mr" object.');
  2679. defineLocator(v.mimic ? v.mimic : v);
  2680. defineDetector(v);
  2681. _mr = v;
  2682. }
  2683. });
  2684. if (!('mr' in win))
  2685. throw 'Wat!?';
  2686. } catch (e) {
  2687. console.log('Found existing "mr" object.', e instanceof TypeError ? '' : e);
  2688. defineLocator(win.mr);
  2689. defineDetector(win.mr);
  2690. }
  2691. }
  2692. }, nullTools);
  2693.  
  2694. scripts['megogo.net'] = {
  2695. now: () => {
  2696. let nt = new nullTools();
  2697. nt.define(win, 'adBlock', false);
  2698. nt.define(win, 'showAdBlockMessage', nt.func(null));
  2699. }
  2700. };
  2701.  
  2702. scripts['naruto-base.su'] = () => gardener('div[id^="entryID"],.block', /href="http.*?target="_blank"/i);
  2703.  
  2704. scripts['overclockers.ru'] = {
  2705. now: () => scriptLander(() => {
  2706. let _innerHTML = Object.getOwnPropertyDescriptor(Element.prototype, 'innerHTML');
  2707. let _set_innerHTML = _innerHTML.set;
  2708. _innerHTML.set = function() {
  2709. if (this === document.body) {
  2710. console.log('Anti-Adblock killed.');
  2711. return true;
  2712. }
  2713. _set_innerHTML.apply(this, arguments);
  2714. };
  2715. Object.defineProperty(Element.prototype, 'innerHTML', _innerHTML);
  2716. })
  2717. };
  2718. scripts['forums.overclockers.ru'] = {
  2719. now: () => {
  2720. createStyle('.needblock {position: fixed; left: -10000px}');
  2721. Object.defineProperty(win, 'adblck', {
  2722. get: () => 'no',
  2723. set: () => undefined,
  2724. enumerable: true
  2725. });
  2726. }
  2727. };
  2728.  
  2729. scripts['pb.wtf'] = {
  2730. other: ['piratbit.org', 'piratbit.ru'],
  2731. now: () => {
  2732. // line above topic content and images in the slider in the header
  2733. gardener(
  2734. 'a[href^="/exit/"], a[href^="/fxt/"], a[href$="=="]',
  2735. /img|Реклама|center/i,
  2736. { root: '.release-navbar,#page_content', observe: true, parent: 'div,tr' }
  2737. );
  2738. // ads in comments
  2739. gardener('img[data-name="PiraBo"]', /./i, {root:'#main_content .table', observe:true, parent:'tr'});
  2740. }
  2741. };
  2742.  
  2743. scripts['pikabu.ru'] = () => gardener('.story', /story__author[^>]+>ads</i, {root: '.inner_wrap', observe: true});
  2744.  
  2745. scripts['peka2.tv'] = () => {
  2746. let bodyClass = 'body--branding';
  2747. let checkNode = node => {
  2748. for (let className of node.classList)
  2749. if (className.includes('banner') || className === bodyClass) {
  2750. _removeAttribute.call(node, 'style');
  2751. node.classList.remove(className);
  2752. for (let attr of Array.from(node.attributes)) {
  2753. if (attr.name.startsWith('advert'))
  2754. _removeAttribute.call(node, attr.name);
  2755. }
  2756. }
  2757. };
  2758. (new MutationObserver(ms => {
  2759. let m, node;
  2760. for (m of ms) for (node of m.addedNodes)
  2761. if (node instanceof HTMLElement)
  2762. checkNode(node);
  2763. })).observe(_de, {childList: true, subtree: true});
  2764. (new MutationObserver(ms => {
  2765. for (let m of ms)
  2766. checkNode(m.target);
  2767. })).observe(_de, {attributes: true, subtree: true, attributeFilter: ['class']});
  2768. };
  2769.  
  2770. scripts['qrz.ru'] = {
  2771. now: () => {
  2772. let nt = new nullTools();
  2773. nt.define(win, 'ab', false);
  2774. nt.define(win, 'tryMessage', nt.func(null));
  2775. }
  2776. };
  2777.  
  2778. scripts['razlozhi.ru'] = {
  2779. now: () => {
  2780. for (let func of ['createShadowRoot', 'attachShadow'])
  2781. if (func in Element.prototype)
  2782. Element.prototype[func] = function(){ return this.cloneNode(); };
  2783. }
  2784. };
  2785.  
  2786. scripts['rbc.ru'] = {
  2787. dom: () => {
  2788. let _preventDefault = Event.prototype.preventDefault;
  2789. Event.prototype.preventDefault = function preventDefault()
  2790. {
  2791. let t = this.target;
  2792. if (t instanceof HTMLAnchorElement || t.closest('A'))
  2793. throw new Error('an.yandex redirect prevention');
  2794. return _preventDefault.call(this);
  2795. };
  2796.  
  2797. function cleaner(nodes)
  2798. {
  2799. for (let node of nodes)
  2800. {
  2801. if (!node.classList || !node.classList.contains('js-yandex-counter'))
  2802. continue;
  2803. node.classList.remove('js-yandex-counter');
  2804. node.removeAttribute('data-yandex-name');
  2805. node.removeAttribute('data-yandex-params');
  2806. }
  2807. }
  2808. cleaner(_de.querySelectorAll('.js-yandex-counter'));
  2809.  
  2810. (new MutationObserver(
  2811. ms => { for (let m of ms) cleaner(m.addedNodes); }
  2812. )).observe(_de, {childList: true, subtree: true});
  2813. }
  2814. };
  2815.  
  2816. scripts['rp5.ru'] = {
  2817. other: ['rp5.by', 'rp5.kz', 'rp5.ua'],
  2818. now: () => gardener('div[id][class]', /\?AdvertMgmt=|adsbygoogle/, { root: '#content-wrapper', log: true })
  2819. };
  2820.  
  2821. scripts['rutube.ru'] = () => scriptLander(() => {
  2822. let _parse = JSON.parse.bind(JSON);
  2823. let _skip_enabled = false;
  2824. JSON.parse = (...args) => {
  2825. let res = _parse(...args),
  2826. log = false;
  2827. if (!res)
  2828. return res;
  2829. // parse player configuration
  2830. if ('appearance' in res || 'video_balancer' in res) {
  2831. log = true;
  2832. if ('appearance' in res) {
  2833. res.appearance.forbid_seek = false;
  2834. res.appearance.forbid_timeline_preview = false;
  2835. }
  2836. _skip_enabled = !!res.remove_unseekable_blocks;
  2837. res.advert = [];
  2838. for (let limit of res.limits)
  2839. limit.limit = 0;
  2840. res.yast = null;
  2841. res.yast_live_online = null;
  2842. Object.defineProperty(res, 'stat', {
  2843. get: x => [],
  2844. set: x => true,
  2845. enumerable: true
  2846. });
  2847. }
  2848.  
  2849. // parse video configuration
  2850. if ('video_url' in res) {
  2851. log = true;
  2852. if ('cuepoints' in res && !_skip_enabled)
  2853. for (let point of res.cuepoints) {
  2854. point.is_pause = false;
  2855. point.show_navigation = true;
  2856. point.forbid_seek = false;
  2857. }
  2858. }
  2859.  
  2860. if (log)
  2861. console.log('[rutube]', res);
  2862. return res;
  2863. };
  2864. });
  2865.  
  2866. scripts['simpsonsua.com.ua'] = () => scriptLander(() => {
  2867. let _addEventListener = Object.getPrototypeOf(HTMLDocument).prototype.addEventListener;
  2868. document.addEventListener = function(event, callback) {
  2869. if (event === 'DOMContentLoaded' && callback.toString().includes('show_warning'))
  2870. return;
  2871. return _addEventListener.apply(this, arguments);
  2872. };
  2873. });
  2874.  
  2875. scripts['spaces.ru'] = () => {
  2876. gardener('div:not(.f-c_fll) > a[href*="spaces.ru/?Cl="]', /./, { parent: 'div' });
  2877. gardener('.js-banner_rotator', /./, { parent: '.widgets-group' });
  2878. };
  2879.  
  2880. scripts['spam-club.blogspot.co.uk'] = () => {
  2881. let _clientHeight = Object.getOwnPropertyDescriptor(Element.prototype, 'clientHeight'),
  2882. _clientWidth = Object.getOwnPropertyDescriptor(Element.prototype, 'clientWidth');
  2883. let wrapGetter = (getter) => {
  2884. let _getter = getter;
  2885. return function()
  2886. {
  2887. let _size = _getter.apply(this, arguments);
  2888. return _size ? _size : 1;
  2889. };
  2890. };
  2891. _clientHeight.get = wrapGetter(_clientHeight.get);
  2892. _clientWidth.get = wrapGetter(_clientWidth.get);
  2893. Object.defineProperty(Element.prototype, 'clientHeight', _clientHeight);
  2894. Object.defineProperty(Element.prototype, 'clientWidth', _clientWidth);
  2895. let _onload = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'onload'),
  2896. _set_onload = _onload.set;
  2897. _onload.set = function()
  2898. {
  2899. if (this instanceof HTMLImageElement)
  2900. return true;
  2901. _set_onload.apply(this, arguments);
  2902. };
  2903. Object.defineProperty(HTMLElement.prototype, 'onload', _onload);
  2904. };
  2905.  
  2906. scripts['sport-express.ru'] = () => gardener('.js-relap__item',/>Реклама\s+<\//, {root:'.container', observe: true});
  2907.  
  2908. scripts['sports.ru'] = {
  2909. now: () => {
  2910. gardener('.aside-news-list__item', /aside-news-list__advert/i, {root:'.columns-layout__left', observe: true});
  2911. gardener('.material-list__item', /Реклама/i, {root:'.columns-layout', observe: true});
  2912. // extra functionality: shows/hides panel at the top depending on scroll direction
  2913. createStyle([
  2914. '.user-panel__fixed { transition: top 0.2s ease-in-out!important; }',
  2915. '.user-panel-up { top: -40px!important }'
  2916. ], {id: 'userPanelSlide'}, false);
  2917. },
  2918. dom: () => {
  2919. (function lookForPanel()
  2920. {
  2921. let panel = document.querySelector('.user-panel__fixed');
  2922. if (!panel)
  2923. setTimeout(lookForPanel, 100);
  2924. else
  2925. window.addEventListener(
  2926. 'wheel', function(e)
  2927. {
  2928. if (e.deltaY > 0 && !panel.classList.contains('user-panel-up'))
  2929. panel.classList.add('user-panel-up');
  2930. else if (e.deltaY < 0 && panel.classList.contains('user-panel-up'))
  2931. panel.classList.remove('user-panel-up');
  2932. }, false
  2933. );
  2934. })();
  2935. }
  2936. };
  2937.  
  2938. scripts['stealthz.ru'] = {
  2939. dom: () => {
  2940. // skip timeout
  2941. let $ = document.querySelector.bind(document);
  2942. let [timer_1, timer_2] = [$('#timer_1'), $('#timer_2')];
  2943. if (!timer_1 || !timer_2)
  2944. return;
  2945. timer_1.style.display = 'none';
  2946. timer_2.style.display = 'block';
  2947. }
  2948. };
  2949.  
  2950. scripts['yap.ru'] = {
  2951. other: ['yaplakal.com'],
  2952. now: () => {
  2953. gardener('form > table[id^="p_row_"]:nth-of-type(2)', /member1438|Administration/);
  2954. gardener('.icon-comments', /member1438|Administration|\/go\/\?http/, {parent:'tr', siblings:-2});
  2955. }
  2956. };
  2957.  
  2958. scripts['rambler.ru'] = {
  2959. other: ['championat.com','gazeta.ru','media.eagleplatform.com','lenta.ru', 'quto.ru'],
  2960. now: () => scriptLander(() => {
  2961. // Prevent autoplay
  2962. if (!('EaglePlayer' in win)) {
  2963. let _EaglePlayer = void 0;
  2964. Object.defineProperty(win, 'EaglePlayer', {
  2965. enumerable: true,
  2966. get: x => _EaglePlayer,
  2967. set: x => {
  2968. if (x === _EaglePlayer)
  2969. return true;
  2970. _EaglePlayer = x;
  2971. let _init = void 0;
  2972. Object.defineProperty(_EaglePlayer.prototype, 'init', {
  2973. enumerable: true,
  2974. set: x => _init = x,
  2975. get: function() {
  2976. let _self = this;
  2977. if (_self.options) {
  2978. Object.defineProperty(this.options, 'autoplay', {
  2979. enumerable: true,
  2980. get: x => false,
  2981. set: x => null
  2982. });
  2983. }
  2984. if (_self.options && _self.options.el && inIFrame) {
  2985. let addListener = (player) => {
  2986. console.log('Attached autostop');
  2987. player.addEventListener('canplay', e => {
  2988. e.target.play = () => console.log('Applied autostop.');
  2989. setTimeout(player => {
  2990. delete player.play;
  2991. console.log('Detached autostop');
  2992. }, 1500, e.target);
  2993. }, false);
  2994. };
  2995. (new MutationObserver(ms => {
  2996. let m, node;
  2997. for (m of ms) for (node of m.addedNodes)
  2998. if (node instanceof HTMLVideoElement)
  2999. addListener(node);
  3000. })).observe(this.options.el, { childList: true, subtree: true });
  3001. }
  3002. return _init;
  3003. }
  3004. });
  3005. }
  3006. });
  3007. let _setAttribute = Element.prototype.setAttribute;
  3008. let isAutoplay = /^autoplay$/i;
  3009. Element.prototype.setAttribute = function setAttribute(name)
  3010. {
  3011. if (!this._stopped && isAutoplay.test(name))
  3012. {
  3013. console.log('Prevented assigning autoplay attribute.');
  3014. return null;
  3015. }
  3016. return _setAttribute.apply(this, arguments);
  3017. };
  3018. } else if (inIFrame) {
  3019. let _setAttribute = Element.prototype.setAttribute;
  3020. let isAutoplay = /^autoplay$/i;
  3021. Element.prototype.setAttribute = function setAttribute(name)
  3022. {
  3023. if (!this._stopped && isAutoplay.test(name))
  3024. {
  3025. console.log('Prevented assigning autoplay attribute.');
  3026. this._stopped = true;
  3027. this.play = () => {
  3028. console.log('Prevented attempt to force-start playback.');
  3029. delete this.play;
  3030. };
  3031. return null;
  3032. }
  3033. return _setAttribute.apply(this, arguments);
  3034. };
  3035. }
  3036. if (location.hostname.endsWith('.media.eagleplatform.com'))
  3037. return;
  3038. let CSSRuleProto = 'cssText' in CSSRule.prototype ? CSSRule.prototype : CSSStyleRule.prototype;
  3039. let _cssText = Object.getOwnPropertyDescriptor(CSSRuleProto, 'cssText');
  3040. let _cssText_get = _cssText.get;
  3041. _cssText.configurable = false;
  3042. _cssText.get = function()
  3043. {
  3044. let cssText = _cssText_get.call(this);
  3045. if (cssText.includes('content:'))
  3046. {
  3047. console.log('Blocked access to suspicious cssText:', cssText.slice(0,60), '\u2026', cssText.length);
  3048. return null;
  3049. }
  3050. return cssText;
  3051. };
  3052. Object.defineProperty(CSSRuleProto, 'cssText', _cssText);
  3053. // fake global Adf object
  3054. let nt = new nullTools();
  3055. let Adf_banner = {};
  3056. [
  3057. 'reloadssp', 'sspScroll',
  3058. 'sspRich', 'ssp'
  3059. ].forEach(name => Adf_banner[name] = nt.proxy(() => new Promise((r,j) => r({status: true}))));
  3060. nt.define(win, 'Adf', nt.proxy({
  3061. banner: nt.proxy(Adf_banner)
  3062. }));
  3063. // extra script to remove partner news on gazeta.ru
  3064. if (!location.hostname.includes('gazeta.ru'))
  3065. return;
  3066. (new MutationObserver(
  3067. (ms) => {
  3068. let m, node, header;
  3069. for (m of ms) for (node of m.addedNodes)
  3070. if (node instanceof HTMLDivElement && node.matches('.sausage'))
  3071. {
  3072. header = node.querySelector('.sausage-header');
  3073. if (header && /новости\s+партн[её]ров/i.test(header.textContent))
  3074. node.style.display = 'none';
  3075. }
  3076. }
  3077. )).observe(document.documentElement, { childList:true, subtree: true });
  3078. }, `let inIFrame = ${inIFrame}`, nullTools)
  3079. };
  3080.  
  3081. scripts['reactor.cc'] = {
  3082. other: ['joyreactor.cc', 'pornreactor.cc'],
  3083. now: () => {
  3084. selectiveEval();
  3085. scriptLander(() => {
  3086. let nt = new nullTools();
  3087. win.open = (function(){ throw new Error('Redirect prevention.'); }).bind(window);
  3088. nt.define(win, 'Worker', function(){});
  3089. nt.define(win, 'JRCH', win.CoinHive);
  3090. }, nullTools);
  3091. },
  3092. click: function(e)
  3093. {
  3094. let node = e.target;
  3095. if (node.nodeType === _Node.ELEMENT_NODE &&
  3096. node.style.position === 'absolute' &&
  3097. node.style.zIndex > 0)
  3098. node.parentNode.removeChild(node);
  3099. },
  3100. dom: function()
  3101. {
  3102. let words = new RegExp(
  3103. 'блокировщик рекламы'
  3104. .split('')
  3105. .map(function(e){return e+'[\u200b\u200c\u200d]*';})
  3106. .join('')
  3107. .replace(' ', '\\s*')
  3108. .replace(/[аоре]/g, function(e){return ['[аa]','[оo]','[рp]','[еe]']['аоре'.indexOf(e)];}),
  3109. 'i'),
  3110. can;
  3111. function deeper(spider)
  3112. {
  3113. let c, l, n;
  3114. if (words.test(spider.innerText))
  3115. {
  3116. if (spider.nodeType === _Node.TEXT_NODE)
  3117. return true;
  3118. c = spider.childNodes;
  3119. l = c.length;
  3120. n = 0;
  3121. while(l--)
  3122. if (deeper(c[l]), can)
  3123. n++;
  3124. if (n > 0 && n === c.length && spider.offsetHeight < 750)
  3125. can.push(spider);
  3126. return false;
  3127. }
  3128. return true;
  3129. }
  3130. function probe()
  3131. {
  3132. if (words.test(document.body.innerText))
  3133. {
  3134. can = [];
  3135. deeper(document.body);
  3136. let i = can.length, spider;
  3137. while(i--) {
  3138. spider = can[i];
  3139. if (spider.offsetHeight > 10 && spider.offsetHeight < 750)
  3140. _setAttribute.call(spider, 'style', 'background:none!important');
  3141. }
  3142. }
  3143. }
  3144. (new MutationObserver(probe))
  3145. .observe(document, { childList:true, subtree:true });
  3146. }
  3147. };
  3148.  
  3149. scripts['auto.ru'] = () => {
  3150. let words = /Реклама|Яндекс.Директ|yandex_ad_/;
  3151. let userAdsListAds = (
  3152. '.listing-list > .listing-item,'+
  3153. '.listing-item_type_fixed.listing-item'
  3154. );
  3155. let catalogAds = (
  3156. 'div[class*="layout_catalog-inline"],'+
  3157. 'div[class$="layout_horizontal"]'
  3158. );
  3159. let otherAds = (
  3160. '.advt_auto,'+
  3161. '.sidebar-block,'+
  3162. '.pager-listing + div[class],'+
  3163. '.card > div[class][style],'+
  3164. '.sidebar > div[class],'+
  3165. '.main-page__section + div[class],'+
  3166. '.listing > tbody'
  3167. );
  3168. gardener(userAdsListAds, words, {root:'.listing-wrap', observe:true});
  3169. gardener(catalogAds, words, {root:'.catalog__page,.content__wrapper', observe:true});
  3170. gardener(otherAds, words);
  3171. };
  3172.  
  3173. scripts['rsload.net'] = {
  3174. load: () => {
  3175. let dis = document.querySelector('label[class*="cb-disable"]');
  3176. if (dis)
  3177. dis.click();
  3178. },
  3179. click: () => {
  3180. let t = e.target;
  3181. if (t && t.href && (/:\/\/\d+\.\d+\.\d+\.\d+\//.test(t.href)))
  3182. t.href = t.href.replace('://','://rsload.net:rsload.net@');
  3183. }
  3184. };
  3185.  
  3186. let domain;
  3187. // add alternative domain names if present and wrap functions into objects
  3188. for (let name in scripts)
  3189. {
  3190. if (scripts[name] instanceof Function)
  3191. scripts[name] = { now: scripts[name] };
  3192. for (domain of (scripts[name].other||[]))
  3193. {
  3194. if (domain in scripts)
  3195. console.log('Error in scripts list. Script for', name, 'replaced script for', domain);
  3196. scripts[domain] = scripts[name];
  3197. }
  3198. delete scripts[name].other;
  3199. }
  3200. // look for current domain in the list and run appropriate code
  3201. domain = document.domain;
  3202. while (domain.indexOf('.') > -1)
  3203. {
  3204. if (domain in scripts) for (let when in scripts[domain])
  3205. switch(when)
  3206. {
  3207. case 'now':
  3208. scripts[domain][when]();
  3209. break;
  3210. case 'dom':
  3211. document.addEventListener('DOMContentLoaded', scripts[domain][when], false);
  3212. break;
  3213. default:
  3214. document.addEventListener (when, scripts[domain][when], false);
  3215. }
  3216. domain = domain.slice(domain.indexOf('.') + 1);
  3217. }
  3218.  
  3219. // Batch script lander
  3220. if (!skipLander)
  3221. landScript(batchLand, batchPrepend);
  3222.  
  3223. { // JS Fixes Tools Menu
  3224. let openOptions = function()
  3225. {
  3226. let ovl = _createElement('div'),
  3227. inner = _createElement('div');
  3228. ovl.style = (
  3229. 'position: fixed;'+
  3230. 'top:0; left:0;'+
  3231. 'bottom: 0; right: 0;'+
  3232. 'background: rgba(0,0,0,0.85);'+
  3233. 'z-index: 2147483647;'+
  3234. 'padding: 5em'
  3235. );
  3236. inner.style = (
  3237. 'background: whitesmoke;'+
  3238. 'font-size: 10pt;'+
  3239. 'color: black;'+
  3240. 'padding: 1em'
  3241. );
  3242. inner.textContent = 'JS Fixes Tools';
  3243. inner.appendChild(_createElement('br'));
  3244. inner.appendChild(_createElement('br'));
  3245. ovl.addEventListener(
  3246. 'click', function(e)
  3247. {
  3248. if (e.target === ovl) {
  3249. ovl.parentNode.removeChild(ovl);
  3250. e.preventDefault();
  3251. }
  3252. e.stopPropagation();
  3253. }, false
  3254. );
  3255.  
  3256. let sObjBtn = _createElement('button');
  3257. sObjBtn.onclick = getStrangeObjectsList;
  3258. sObjBtn.textContent = 'Print (in console) list of unusual window properties';
  3259. inner.appendChild(_createElement('br'));
  3260. inner.appendChild(sObjBtn);
  3261.  
  3262. document.body.appendChild(ovl);
  3263. ovl.appendChild(inner);
  3264. };
  3265.  
  3266. // monitor keys pressed for Ctrl+Alt+Shift+J > s > f code
  3267. let opPos = 0, opKey = ['KeyJ','KeyS','KeyF'];
  3268. document.addEventListener(
  3269. 'keydown', function(e)
  3270. {
  3271. if ((e.code === opKey[opPos] || e.location) &&
  3272. (!!opPos || e.altKey && e.ctrlKey && e.shiftKey))
  3273. {
  3274. opPos += e.location ? 0 : 1;
  3275. e.stopPropagation();
  3276. e.preventDefault();
  3277. } else {
  3278. opPos = 0;
  3279. }
  3280. if (opPos === opKey.length)
  3281. {
  3282. opPos = 0;
  3283. openOptions();
  3284. }
  3285. }, false
  3286. );
  3287. }
  3288. })();