RU AdList JS Fixes

try to take over the world!

当前为 2018-08-09 提交的版本,查看 最新版本

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