RU AdList JS Fixes

try to take over the world!

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

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