RU AdList JS Fixes

try to take over the world!

当前为 2018-10-23 提交的版本,查看 最新版本

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