RU AdList JS Fixes

try to take over the world!

目前為 2018-10-22 提交的版本,檢視 最新版本

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