RU AdList JS Fixes

try to take over the world!

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

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