RU AdList JS Fixes

try to take over the world!

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

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