RU AdList JS Fixes

try to take over the world!

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

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