RU AdList JS Fixes

try to take over the world!

目前為 2018-05-12 提交的版本,檢視 最新版本

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