RU AdList JS Fixes

try to take over the world!

目前为 2018-11-21 提交的版本。查看 最新版本

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