Greasy Fork 还支持 简体中文。

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 20180810.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. for (let prop of ['mz_str', 'blur']) {
  1450. let desc = Object.getOwnPropertyDescriptor(win, prop);
  1451. if (!desc || desc.configurable)
  1452. Object.defineProperty(win, prop, {
  1453. configurable: false
  1454. });
  1455. }
  1456. // main script
  1457. let knownRoots = new WeakSet();
  1458. function wrapAPI(root) {
  1459. if (knownRoots.has(root))
  1460. return;
  1461. knownRoots.add(root);
  1462. let _proto = void 0;
  1463. try {
  1464. _proto = root.XMLHttpRequest.prototype;
  1465. } catch(ignore) {
  1466. return;
  1467. };
  1468. let _open = _proto.open;
  1469. // blacklist of third-party domains requests to which are ignored
  1470. let blacklist = /[/.@](amgload\.net|dsn-fishki\.ru|kingoablc\.com|klcheck\.com|piguiqproxy\.com|rcdn\.pro|smcheck\.org|zmctrack\.net)([:/]|$)/i;
  1471. // blacklist of domains where all third-party requests are ignored
  1472. let ondomains = /(^|[/.@])oane\.ws($|[:/])/i;
  1473. // highly suspicious URLs
  1474. let suspicious = /^https?:\/\/(csp-)?([a-z0-9]{6}){1,2}\.ru\//i;
  1475. let on_get_ban = /^https?:\/\/(csp-)?([a-z0-9]{6}){1,2}\.ru\/([a-z0-9/]{40,}|[a-z0-9]{8,}|ad\/banner\/.+)$/i;
  1476. let on_post_ban = /^https?:\/\/(csp-)?([a-z0-9]{6}){1,2}\.ru\/([a-z0-9]{6,})$/i;
  1477.  
  1478. let xhrStopList = new WeakSet();
  1479.  
  1480. function checkRequest(fname, method, url) {
  1481. if (blacklist.test(url) ||
  1482. ondomains.test(location.hostname) && !ondomains.test(url) ||
  1483. method === 'GET' && on_get_ban.test(url) ||
  1484. method === 'POST' && on_post_ban.test(url)) {
  1485. console.log(`Blocked ${fname} ${method} request:`, url);
  1486. return true;
  1487. }
  1488. if (suspicious.test(url))
  1489. console.warn(`Suspicious ${fname} ${method} request:`, url);
  1490. return false;
  1491. }
  1492.  
  1493. _proto.open = function open() {
  1494. if (checkRequest('xhr', ...arguments)) {
  1495. xhrStopList.add(this);
  1496. return;
  1497. }
  1498. return _open.apply(this, arguments);
  1499. };
  1500. ['send', 'setRequestHeader', 'getAllResponseHeaders'].forEach(
  1501. name => {
  1502. let func = _proto[name];
  1503. _proto[name] = function(...args) {
  1504. return xhrStopList.has(this) ? null : func.apply(this, args);
  1505. }
  1506. }
  1507. );
  1508.  
  1509. let _fetch = root.fetch;
  1510. root.fetch = (...args) => {
  1511. let url = args[0];
  1512. let method = args[1] ? args[1].method : void 0;
  1513. if (args[0] instanceof Request) {
  1514. url = args[0].url;
  1515. method = args[0].method;
  1516. }
  1517. if (checkRequest('fetch', method, url))
  1518. return new Promise(() => null);
  1519. return _fetch.call(root, ...args);
  1520. };
  1521. }
  1522.  
  1523. wrapAPI(win);
  1524.  
  1525. let _contentWindow = Object.getOwnPropertyDescriptor(HTMLIFrameElement.prototype, 'contentWindow');
  1526. let _get_contentWindow = _contentWindow.get;
  1527. _contentWindow.get = function() {
  1528. let _cw = _get_contentWindow.apply(this, arguments);
  1529. if (_cw)
  1530. wrapAPI(_cw);
  1531. return _cw;
  1532. };
  1533. Object.defineProperty(HTMLIFrameElement.prototype, 'contentWindow', _contentWindow);
  1534.  
  1535. win.stop = () => {
  1536. console.warn('window.stop() ...y tho?');
  1537. for (let sheet of _document.styleSheets)
  1538. if (sheet.disabled) {
  1539. sheet.disabled = false;
  1540. console.log('Re-enabled:', sheet);
  1541. }
  1542. }
  1543. }
  1544. );
  1545.  
  1546. // === Helper functions ===
  1547.  
  1548. // function to search and remove nodes by content
  1549. // selector - standard CSS selector to define set of nodes to check
  1550. // words - regular expression to check content of the suspicious nodes
  1551. // params - object with multiple extra parameters:
  1552. // .log - display log in the console
  1553. // .hide - set display to none instead of removing from the page
  1554. // .parent - parent node to remove if content is found in the child node
  1555. // .siblings - number of simling nodes to remove (excluding text nodes)
  1556. let scRemove = (node) => node.parentNode.removeChild(node);
  1557. let scHide = function(node) {
  1558. let style = _getAttribute.call(node, 'style') || '',
  1559. hide = ';display:none!important;';
  1560. if (style.indexOf(hide) < 0)
  1561. _setAttribute.call(node, 'style', style + hide);
  1562. };
  1563.  
  1564. function scissors (selector, words, scope, params) {
  1565. let logger = (...args) => { if (params.log) console.log(...args) };
  1566. if (!scope.contains(_document.body))
  1567. logger('[s] scope', scope);
  1568. let remFunc = (params.hide ? scHide : scRemove),
  1569. iterFunc = (params.siblings > 0 ? 'nextElementSibling' : 'previousElementSibling'),
  1570. toRemove = [],
  1571. siblings;
  1572. for (let node of scope.querySelectorAll(selector)) {
  1573. // drill up to a parent node if specified, break if not found
  1574. if (params.parent) {
  1575. let old = node;
  1576. node = node.closest(params.parent);
  1577. if (node === null || node.contains(scope)) {
  1578. logger('[s] went out of scope with', old);
  1579. continue;
  1580. }
  1581. }
  1582. logger('[s] processing', node);
  1583. if (toRemove.includes(node))
  1584. continue;
  1585. if (words.test(node.innerHTML)) {
  1586. // skip node if already marked for removal
  1587. logger('[s] marked for removal');
  1588. toRemove.push(node);
  1589. // add multiple nodes if defined more than one sibling
  1590. siblings = Math.abs(params.siblings) || 0;
  1591. while (siblings) {
  1592. node = node[iterFunc];
  1593. if (!node) break; // can't go any further - exit
  1594. logger('[s] adding sibling node', node);
  1595. toRemove.push(node);
  1596. siblings -= 1;
  1597. }
  1598. }
  1599. }
  1600. let toSkip = [];
  1601. for (let node of toRemove)
  1602. if (!toRemove.every(other => other === node || !node.contains(other)))
  1603. toSkip.push(node);
  1604. if (toRemove.length)
  1605. logger(`[s] proceeding with ${params.hide?'hide':'removal'} of`, toRemove, `skip`, toSkip);
  1606. for (let node of toRemove) if (!toSkip.includes(node))
  1607. remFunc(node);
  1608. }
  1609.  
  1610. // function to perform multiple checks if ads inserted with a delay
  1611. // by default does 30 checks withing a 3 seconds unless nonstop mode specified
  1612. // also does 1 extra check when a page completely loads
  1613. // selector and words - passed dow to scissors
  1614. // params - object with multiple extra parameters:
  1615. // .log - display log in the console
  1616. // .root - selector to narrow down scope to scan;
  1617. // .observe - if true then check will be performed continuously;
  1618. // Other parameters passed down to scissors.
  1619. function gardener(selector, words, params) {
  1620. let logger = (...args) => { if(params.log) console.log(...args) };
  1621. params = params || {};
  1622. logger(`[gardener] selector: '${selector}' detector: ${words} options: ${JSON.stringify(params)}`);
  1623. let scope;
  1624. let globalScope = [_de];
  1625. let domLoaded = false;
  1626. let getScope = root => root ? _de.querySelectorAll(root) : globalScope;
  1627. let onevent = e => {
  1628. logger(`[gardener] cleanup on ${Object.getPrototypeOf(e)} "${e.type}"`);
  1629. for (let node of scope)
  1630. scissors(selector, words, node, params);
  1631. };
  1632. let repeater = n => {
  1633. if (!domLoaded && n) {
  1634. setTimeout(repeater, 500, n - 1);
  1635. scope = getScope(params.root);
  1636. if (!scope) // exit if the root element is not present on the page
  1637. return 0;
  1638. onevent({type: 'Repeater'});
  1639. }
  1640. };
  1641. repeater(20);
  1642. _document.addEventListener(
  1643. 'DOMContentLoaded', (e) => {
  1644. domLoaded = true;
  1645. // narrow down scope to a specific element
  1646. scope = getScope(params.root);
  1647. if (!scope) // exit if the root element is not present on the page
  1648. return 0;
  1649. logger('[g] scope', scope);
  1650. // add observe mode if required
  1651. if (params.observe) {
  1652. let params = { childList:true, subtree: true };
  1653. let observer = new MutationObserver(
  1654. function(ms) {
  1655. for (let m of ms)
  1656. if (m.addedNodes.length)
  1657. onevent(m);
  1658. }
  1659. );
  1660. for (let node of scope)
  1661. observer.observe(node, params);
  1662. logger('[g] observer enabled');
  1663. }
  1664. onevent(e);
  1665. }, false);
  1666. // wait for a full page load to do one extra cut
  1667. win.addEventListener('load', onevent, false);
  1668. }
  1669.  
  1670. // wrap popular methods to open a new tab to catch specific behaviours
  1671. function createWindowOpenWrapper(openFunc) {
  1672. let _createElement = _Document.prototype.createElement,
  1673. _appendChild = _Element.prototype.appendChild,
  1674. fakeNative = (f) => (f.toString = () => `function ${f.name}() { [native code] }`);
  1675.  
  1676. let nt = new nullTools();
  1677. fakeNative(openFunc);
  1678.  
  1679. let parser = _createElement.call(_document, 'a');
  1680. let openWhitelist = (url, parent) => {
  1681. parser.href = url;
  1682. return parser.hostname === 'www.imdb.com' || parser.hostname === 'www.kinopoisk.ru' ||
  1683. parent.hostname === 'radikal.ru' && url === void 0;
  1684. };
  1685.  
  1686. let redefineOpen = (root) => {
  1687. if ('open' in root) {
  1688. let _open = root.open.bind(root);
  1689. nt.define(root, 'open', (...args) => {
  1690. if (openWhitelist(args[0], location)) {
  1691. console.log('Whitelisted popup:', ...args);
  1692. return _open(...args);
  1693. }
  1694. return openFunc(...args);
  1695. });
  1696. }
  1697. };
  1698. redefineOpen(win);
  1699.  
  1700. function createElement() {
  1701. '[native code]';
  1702. let el = _createElement.apply(this, arguments);
  1703. // redefine window.open in first-party frames
  1704. if (el instanceof HTMLIFrameElement || el instanceof HTMLObjectElement)
  1705. el.addEventListener('load', (e) => {
  1706. try {
  1707. redefineOpen(e.target.contentWindow);
  1708. } catch(ignore) {}
  1709. }, false);
  1710. return el;
  1711. }
  1712. fakeNative(createElement);
  1713.  
  1714. let redefineCreateElement = (obj) => {
  1715. for (let root of [obj.document, _Document.prototype]) if ('createElement' in root)
  1716. nt.define(root, 'createElement', createElement);
  1717. };
  1718. redefineCreateElement(win);
  1719.  
  1720. // wrap window.open in newly added first-party frames
  1721. _Element.prototype.appendChild = function appendChild() {
  1722. '[native code]';
  1723. let el = _appendChild.apply(this, arguments);
  1724. if (el instanceof HTMLIFrameElement)
  1725. try {
  1726. redefineOpen(el.contentWindow);
  1727. redefineCreateElement(el.contentWindow);
  1728. } catch(ignore) {}
  1729. return el;
  1730. };
  1731. fakeNative(_Element.prototype.appendChild);
  1732. }
  1733.  
  1734. // Function to catch and block various methods to open a new window with 3rd-party content.
  1735. // Some advertisement networks went way past simple window.open call to circumvent default popup protection.
  1736. // This funciton blocks window.open, ability to restore original window.open from an IFRAME object,
  1737. // ability to perform an untrusted (not initiated by user) click on a link, click on a link without a parent
  1738. // node or simply a link with piece of javascript code in the HREF attribute.
  1739. function preventPopups() {
  1740. // call sandbox-me if in iframe and not whitelisted
  1741. if (inIFrame) {
  1742. win.top.postMessage({ name: 'sandbox-me', href: win.location.href }, '*');
  1743. return;
  1744. }
  1745.  
  1746. scriptLander(() => {
  1747. let nt = new nullTools({log:true});
  1748. let open = (...args) => {
  1749. '[native code]';
  1750. console.warn('Site attempted to open a new window', ...args);
  1751. return {
  1752. document: nt.proxy({
  1753. write: nt.func({}, 'write'),
  1754. writeln: nt.func({}, 'writeln')
  1755. }),
  1756. location: nt.proxy({})
  1757. };
  1758. };
  1759.  
  1760. createWindowOpenWrapper(open);
  1761.  
  1762. console.log('Popup prevention enabled.');
  1763. }, nullTools, createWindowOpenWrapper);
  1764. }
  1765.  
  1766. // Helper function to close background tab if site opens itself in a new tab and then
  1767. // loads a 3rd-party page in the background one (thus performing background redirect).
  1768. function preventPopunders() {
  1769. // create "close_me" event to call high-level window.close()
  1770. let eventName = `close_me_${Math.random().toString(36).substr(2)}`;
  1771. let callClose = () => {
  1772. console.log('close call');
  1773. window.close();
  1774. };
  1775. window.addEventListener(eventName, callClose, true);
  1776.  
  1777. scriptLander(() => {
  1778. // get host of a provided URL with help of an anchor object
  1779. // unfortunately new URL(url, window.location) generates wrong URL in some cases
  1780. let parseURL = _document.createElement('A');
  1781. let getHost = url => {
  1782. parseURL.href = url;
  1783. return parseURL.hostname
  1784. };
  1785. // site went to a new tab and attempts to unload
  1786. // call for high-level close through event
  1787. let closeWindow = () => window.dispatchEvent(new CustomEvent(eventName, {}));
  1788. // check is URL local or goes to different site
  1789. let isLocal = (url) => {
  1790. if (url === location.pathname || url === location.href)
  1791. return true; // URL points to current pathname or full address
  1792. let host = getHost(url);
  1793. let site = location.hostname;
  1794. return host !== '' && // URLs with unusual protocol may have empty 'host'
  1795. (site === host || site.endsWith(`.${host}`) || host.endsWith(`.${site}`));
  1796. };
  1797.  
  1798. let _open = window.open.bind(window);
  1799. let open = (...args) => {
  1800. '[native code]';
  1801. let url = args[0];
  1802. if (url && isLocal(url))
  1803. window.addEventListener('beforeunload', closeWindow, true);
  1804. return _open(...args);
  1805. };
  1806.  
  1807. createWindowOpenWrapper(open);
  1808.  
  1809. console.log("Background redirect prevention enabled.");
  1810. }, `let eventName="${eventName}"`, nullTools, createWindowOpenWrapper);
  1811. }
  1812.  
  1813. // Mix between check for popups and popunders
  1814. // Significantly more agressive than both and can't be used as universal solution
  1815. function preventPopMix() {
  1816. if (inIFrame) {
  1817. win.top.postMessage({ name: 'sandbox-me', href: win.location.href }, '*');
  1818. return;
  1819. }
  1820.  
  1821. // create "close_me" event to call high-level window.close()
  1822. let eventName = `close_me_${Math.random().toString(36).substr(2)}`;
  1823. let callClose = () => {
  1824. console.log('close call');
  1825. window.close();
  1826. };
  1827. window.addEventListener(eventName, callClose, true);
  1828.  
  1829. scriptLander(() => {
  1830. let _open = window.open,
  1831. parseURL = _document.createElement('A');
  1832. // get host of a provided URL with help of an anchor object
  1833. // unfortunately new URL(url, window.location) generates wrong URL in some cases
  1834. let getHost = (url) => {
  1835. parseURL.href = url;
  1836. return parseURL.host;
  1837. };
  1838. // site went to a new tab and attempts to unload
  1839. // call for high-level close through event
  1840. let closeWindow = () => {
  1841. _open(window.location,'_self');
  1842. window.dispatchEvent(new CustomEvent(eventName, {}));
  1843. };
  1844. // check is URL local or goes to different site
  1845. function isLocal(url) {
  1846. let loc = window.location;
  1847. if (url === loc.pathname || url === loc.href)
  1848. return true; // URL points to current pathname or full address
  1849. let host = getHost(url),
  1850. site = loc.host;
  1851. if (host === '')
  1852. return false; // URLs with unusual protocol may have empty 'host'
  1853. if (host.length > site.length)
  1854. [site, host] = [host, site];
  1855. return site.includes(host, site.length - host.length);
  1856. }
  1857.  
  1858. // add check for redirect for 5 seconds, then disable it
  1859. function checkRedirect() {
  1860. window.addEventListener('beforeunload', closeWindow, true);
  1861. setTimeout(closeWindow=>window.removeEventListener('beforeunload', closeWindow, true), 5000, closeWindow);
  1862. }
  1863.  
  1864. function open(url, name) {
  1865. '[native code]';
  1866. if (url && isLocal(url) && (!name || name === '_blank')) {
  1867. console.warn('Suspicious local new window', arguments);
  1868. checkRedirect();
  1869. return _open.apply(this, arguments);
  1870. }
  1871. console.warn('Blocked attempt to open a new window', arguments);
  1872. return {
  1873. document: {
  1874. write: () => {},
  1875. writeln: () => {}
  1876. }
  1877. };
  1878. }
  1879.  
  1880. function clickHandler(e) {
  1881. let link = e.target,
  1882. url = link.href||'';
  1883. if (e.targetParentNode && e.isTrusted || link.target !== '_blank') {
  1884. console.log('Link', link, 'were created dinamically, but looks fine.');
  1885. return true;
  1886. }
  1887. if (isLocal(url) && link.target === '_blank') {
  1888. console.log('Suspicious local link', link);
  1889. checkRedirect();
  1890. return;
  1891. }
  1892. console.log('Blocked suspicious click on a link', link);
  1893. e.stopPropagation();
  1894. e.preventDefault();
  1895. }
  1896.  
  1897. createWindowOpenWrapper(open, clickHandler);
  1898.  
  1899. console.log("Mixed popups prevention enabled.");
  1900. }, `let eventName="${eventName}"`, createWindowOpenWrapper);
  1901. }
  1902. // External listener for case when site known to open popups were loaded in iframe
  1903. // It will sandbox any iframe which will send message 'forbid.popups' (preventPopups sends it)
  1904. // Some sites replace frame's window.location with data-url to run in clean context
  1905. if (!inIFrame) window.addEventListener(
  1906. 'message', function(e) {
  1907. if (!e.data || e.data.name !== 'sandbox-me' || !e.data.href)
  1908. return;
  1909. let src = e.data.href;
  1910. for (let frame of _document.querySelectorAll('iframe'))
  1911. if (frame.contentWindow === e.source) {
  1912. if (frame.hasAttribute('sandbox')) {
  1913. if (!frame.sandbox.contains('allow-popups'))
  1914. return; // exit frame since it's already sandboxed and popups are blocked
  1915. // remove allow-popups if frame already sandboxed
  1916. frame.sandbox.remove('allow-popups');
  1917. } else
  1918. // set sandbox mode for troublesome frame and allow scripts, forms and a few other actions
  1919. // technically allowing both scripts and same-origin allows removal of the sandbox attribute,
  1920. // but to apply content must be reloaded and this script will re-apply it in the result
  1921. frame.setAttribute('sandbox','allow-forms allow-scripts allow-presentation allow-top-navigation allow-same-origin');
  1922. console.log('Disallowed popups from iframe', frame);
  1923.  
  1924. // reload frame content to apply restrictions
  1925. if (!src) {
  1926. src = frame.src;
  1927. console.log('Unable to get current iframe location, reloading from src', src);
  1928. } else
  1929. console.log('Reloading iframe with URL', src);
  1930. frame.src = 'about:blank';
  1931. frame.src = src;
  1932. }
  1933. }, false
  1934. );
  1935.  
  1936. function selectiveEval() {
  1937. scriptLander(() => {
  1938. let nt = new nullTools();
  1939. let _eval = win.eval.bind(window);
  1940. nt.define(win, 'eval', function(...args) {
  1941. if (/_0x|location\s*?=|location.href\s*?=|location.assign\(|open\(/i.test(args[0])) {
  1942. console.log(`Skipped eval of ${args[0].slice(0, 512)}\u2026`);
  1943. return null;
  1944. }
  1945. return _eval(...args);
  1946. });
  1947. }, nullTools);
  1948. }
  1949.  
  1950. // === Scripts for specific domains ===
  1951.  
  1952. let scripts = {};
  1953. // prevent popups and redirects block
  1954. // Popups
  1955. scripts.preventPopups = {
  1956. other: [
  1957. 'biqle.ru',
  1958. 'chaturbate.com',
  1959. 'dfiles.ru',
  1960. 'eporner.eu',
  1961. 'hentaiz.org',
  1962. 'mirrorcreator.com',
  1963. 'online-multy.ru',
  1964. 'radikal.ru', 'rumedia.ws',
  1965. 'thepiratebay.org',
  1966. 'unionpeer.com',
  1967. 'zippyshare.com'
  1968. ],
  1969. now: preventPopups
  1970. };
  1971. // Popunders (background redirect)
  1972. scripts.preventPopunders = {
  1973. other: [
  1974. 'lostfilm-online.ru',
  1975. 'mediafire.com', 'megapeer.org', 'megapeer.ru',
  1976. 'perfectgirls.net'
  1977. ],
  1978. now: preventPopunders
  1979. };
  1980. // PopMix (both types of popups encountered on site)
  1981. scripts['openload.co'] = {
  1982. other: ['oload.tv', 'oload.info'],
  1983. now: () => {
  1984. let nt = new nullTools();
  1985. nt.define(win, 'CNight', win.CoinHive);
  1986. if (location.pathname.startsWith('/embed/')) {
  1987. nt.define(win, 'BetterJsPop', {
  1988. add: ((a, b) => console.warn('BetterJsPop.add', a, b)),
  1989. config: ((o) => console.warn('BetterJsPop.config', o)),
  1990. Browser: { isChrome: true }
  1991. });
  1992. nt.define(win, 'isSandboxed', nt.func(null));
  1993. nt.define(win, 'adblock', false);
  1994. nt.define(win, 'adblock2', false);
  1995. } else preventPopMix();
  1996. }
  1997. };
  1998. scripts['turbobit.net'] = preventPopMix;
  1999.  
  2000. scripts['tapochek.net'] = () => {
  2001. // workaround for moradu.com/apu.php load error handler script, not sure which ad network is this
  2002. let _appendChild = Object.getOwnPropertyDescriptor(_Node.prototype, 'appendChild');
  2003. let _appendChild_value = _appendChild.value;
  2004. _appendChild.value = function appendChild(node) {
  2005. if (this === _document.body)
  2006. if ((node instanceof HTMLScriptElement || node instanceof HTMLStyleElement) &&
  2007. /^https?:\/\/[0-9a-f]{15}\.com\/\d+(\/|\.css)$/.test(node.src) ||
  2008. node instanceof HTMLDivElement && node.style.zIndex > 900000 &&
  2009. node.style.backgroundImage.includes('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'))
  2010. throw '...eenope!';
  2011. return _appendChild_value.apply(this, arguments);
  2012. };
  2013. Object.defineProperty(_Node.prototype, 'appendChild', _appendChild);
  2014.  
  2015. // disable window focus tricks and changing location
  2016. let focusHandlerName = /\WfocusAchieved\(/
  2017. let _toString = Function.prototype.toString;
  2018. let _setInterval = win.setInterval;
  2019. win.setInterval = (...args) => {
  2020. if (args.length && focusHandlerName.test(_toString.call(args[0]))) {
  2021. console.log('skip setInterval for', ...args);
  2022. return -1;
  2023. }
  2024. return _setInterval(...args);
  2025. };
  2026. let _addEventListener = win.addEventListener;
  2027. win.addEventListener = function(...args) {
  2028. if (args.length && args[0] === 'focus' && focusHandlerName.test(_toString.call(args[1]))) {
  2029. console.log('skip addEventListener for', ...args);
  2030. return void 0;
  2031. }
  2032. return _addEventListener.apply(this, args);
  2033. };
  2034.  
  2035. // generic popup prevention
  2036. preventPopups();
  2037. };
  2038.  
  2039. scripts['rustorka.com'] = {
  2040. other: ['rustorka.lib', 'rustorka.net'],
  2041. now: () => scriptLander(() => {
  2042. let crumbler = () => {
  2043. // crumble suspicious cookies
  2044. let base = '=; expires=Thu, 01 Jan 1970 00:00:01 UTC; Max-Age=-99999999; path=/';
  2045. console.log('cookies', _document.cookie);
  2046. for (let name of ['adblock', 'gophp', '_692293176245', '_692293176246'])
  2047. _document.cookie = `${name}${base}`;
  2048. for (let name of ['st2', 'st3']) {
  2049. _document.cookie = `${name}${base}forum`;
  2050. _document.cookie = `${name}${base}forum/`;
  2051. }
  2052. console.log('cookies', _document.cookie);
  2053. };
  2054. _document.addEventListener('DOMContentLoaded', crumbler, false);
  2055. crumbler();
  2056.  
  2057. let nt = new nullTools({trace: true});
  2058. nt.define(win, 'syka', false);
  2059. nt.define(win, '_692293176244', location.href);
  2060. [
  2061. 'MTLuxup', 'MTAdSniper', 'MTutarg', 'MTUAatar', 'MTcityAds', 'MTmxMark',
  2062. 'MTmxMark2', 'MTmdnt', 'MTrfDumedia', 'MXsmTDS', 'MTritorno', 'MTadvice',
  2063. 'cyka', 'MTAdTraff', 'MTExebid', 'MXsockFound'
  2064. ].forEach(name => nt.define(win, name, nt.func(null, name)));
  2065. let _eval_def = Object.getOwnPropertyDescriptor(win, 'eval');
  2066. if (!_eval_def)
  2067. return;
  2068. let _eval_val = _eval_def.value;
  2069. _eval_def.value = (...args) => {
  2070. if (args[0] && args[0].includes('antiadblock'))
  2071. return console.log('Anti-AdBlock script may run another day, but not today.');
  2072. return _eval_val.apply(this, args);
  2073. };
  2074. Object.defineProperty(win, 'eval', _eval_def);
  2075. win.open = (...args) => {
  2076. console.warn(`Site attempted to open "${args[0]}" in a new window.`);
  2077. location.replace(location.href);
  2078. return null;
  2079. };
  2080. window.addEventListener('DOMContentLoaded', () => {
  2081. let link = void 0;
  2082. _document.body.addEventListener('mousedown', e => {
  2083. link = e.target.closest('a, select, #fancybox-title-wrap');
  2084. }, false);
  2085. let _open = window.open.bind(window);
  2086. let _getAttribute = _Element.prototype.getAttribute;
  2087. win.open = (...args) => {
  2088. let url = args[0];
  2089. if (link instanceof HTMLAnchorElement) {
  2090. // third-party post links
  2091. let href = _getAttribute.call(link, 'href');
  2092. if (link.classList.contains('postLink') &&
  2093. !link.matches(`a[href*="${location.hostname}"]`) &&
  2094. (href === url || link.href === url))
  2095. return _open(...args);
  2096. // onclick # links
  2097. if (href === '#' && /window\.open/.test(_getAttribute.call(link, 'onclick')))
  2098. return _open(...args);
  2099. // force local links to load in the current window
  2100. if (href[0] === '/' || href.startsWith('./') || href.includes(`//${location.hostname}/`))
  2101. location.assign(href);
  2102. }
  2103. // list of image hostings under upload picture button (new comment)
  2104. if (link instanceof HTMLSelectElement &&
  2105. !url.includes(location.hostname) &&
  2106. link.value === url)
  2107. return _open(...args);
  2108. // open screenshot in a new window
  2109. if (link instanceof HTMLSpanElement &&
  2110. link.id === 'fancybox-title-wrap')
  2111. return _open(...args);
  2112. // looks like tabunder
  2113. if (link === null && url === location.href)
  2114. location.replace(url); // reload current page
  2115. // other cases
  2116. console.warn(`Site attempted to open "${url}" in a new window. Source: `, link);
  2117. return {};
  2118. };
  2119. }, true);
  2120. }, nullTools)
  2121. };
  2122.  
  2123. // other
  2124. scripts['1tv.ru'] = {
  2125. other: ['mediavitrina.ru'],
  2126. now: () => scriptLander(() => {
  2127. let nt = new nullTools();
  2128. nt.define(win, 'EUMPAntiblockConfig', nt.proxy({url: '//www.1tv.ru/favicon.ico'}));
  2129. let disablePlugins = {
  2130. 'antiblock': false,
  2131. 'stat1tv': false
  2132. };
  2133. let _EUMPConfig = void 0;
  2134. let _EUMPConfig_set = x => {
  2135. if (x.plugins) {
  2136. x.plugins = x.plugins.filter(plugin => (plugin in disablePlugins) ? !(disablePlugins[plugin] = true) : true);
  2137. console.warn(`Player plugins: active [${x.plugins}], disabled [${Object.keys(disablePlugins).filter(x => disablePlugins[x])}]`);
  2138. }
  2139. _EUMPConfig = x;
  2140. };
  2141. if ('EUMPConfig' in win)
  2142. _EUMPConfig_set(win.EUMPConfig);
  2143. Object.defineProperty(win, 'EUMPConfig', {
  2144. enumerable: true,
  2145. get: () => _EUMPConfig,
  2146. set: _EUMPConfig_set
  2147. });
  2148. }, nullTools)
  2149. };
  2150.  
  2151. scripts['2picsun.ru'] = {
  2152. other: [
  2153. 'pics2sun.ru', '3pics-img.ru'
  2154. ],
  2155. now: () => {
  2156. Object.defineProperty(navigator, 'userAgent', {value: 'googlebot'});
  2157. }
  2158. };
  2159.  
  2160. scripts['4pda.ru'] = {
  2161. now: () => {
  2162. // https://greasyfork.org/en/scripts/14470-4pda-unbrender
  2163. let isForum = location.pathname.startsWith('/forum/'),
  2164. remove = node => (node && node.parentNode.removeChild(node)),
  2165. hide = node => (node && (node.style.display = 'none'));
  2166.  
  2167. // save links to non-overridden functions to use later
  2168. let protectedElems;
  2169. // protect/hide changed attributes in case site attempt to restore them
  2170. function styleProtector(eventMode) {
  2171. let _toLowerCase = String.prototype.toLowerCase,
  2172. isStyleText = (t) => (_toLowerCase.call(t) === 'style'),
  2173. protectedElems = new WeakMap();
  2174. function protoOverride(element, functionName, isStyleCheck, returnIfProtected) {
  2175. let originalFunction = element.prototype[functionName];
  2176. element.prototype[functionName] = function wrapper() {
  2177. if (protectedElems.has(this) && isStyleCheck(arguments[0]))
  2178. return returnIfProtected(this, arguments);
  2179. return originalFunction.apply(this, arguments);
  2180. };
  2181. }
  2182. protoOverride(Element, 'removeAttribute', isStyleText, () => undefined);
  2183. protoOverride(Element, 'hasAttribute', isStyleText, (_this) => protectedElems.get(_this) !== null);
  2184. protoOverride(Element, 'setAttribute', isStyleText, (_this, args) => protectedElems.set(_this, args[1]));
  2185. protoOverride(Element, 'getAttribute', isStyleText, (_this) => protectedElems.get(_this));
  2186. if (!eventMode)
  2187. return protectedElems;
  2188. let e = _document.createEvent('Event');
  2189. e.initEvent('protoOverride', false, false);
  2190. window.protectedElems = protectedElems;
  2191. window.dispatchEvent(e);
  2192. }
  2193. if (!isFirefox)
  2194. protectedElems = styleProtector(false);
  2195. else {
  2196. let script = _document.createElement('script');
  2197. script.textContent = `(${styleProtector.toString()})(true);`;
  2198. window.addEventListener(
  2199. 'protoOverride', function protoOverrideCallback() {
  2200. if (win.protectedElems) {
  2201. protectedElems = win.protectedElems;
  2202. delete win.protectedElems;
  2203. }
  2204. _document.removeEventListener('protoOverride', protoOverrideCallback, true);
  2205. }, true
  2206. );
  2207. _appendChild(script);
  2208. _removeChild(script);
  2209. }
  2210.  
  2211. // clean a page
  2212. window.addEventListener(
  2213. 'DOMContentLoaded', function() {
  2214. let width = () => window.innerWidth || _de.clientWidth || _document.body.clientWidth || 0;
  2215. let height = () => window.innerHeight || _de.clientHeight || _document.body.clientHeight || 0;
  2216.  
  2217. HeaderAds: {
  2218. // hide ads above HEADER
  2219. let header = _document.querySelector('.drop-search');
  2220. if (!header) {
  2221. console.warn('Unable to locate header element');
  2222. break HeaderAds;
  2223. }
  2224. header = header.parentNode.parentNode;
  2225. for (let itm of header.parentNode.children)
  2226. if (itm !== header)
  2227. hide(itm);
  2228. else break;
  2229. }
  2230.  
  2231. if (isForum) {
  2232. let itm = _document.querySelector('#logostrip');
  2233. if (itm)
  2234. remove(itm.parentNode.nextSibling);
  2235. // clear background in the download frame
  2236. if (location.pathname.startsWith('/forum/dl/')) {
  2237. let setBackground = node => _setAttribute.call(
  2238. node,
  2239. 'style', (_getAttribute.call(node, 'style') || '') +
  2240. ';background-color:#4ebaf6!important'
  2241. );
  2242. setBackground(_document.body);
  2243. for (let itm of _document.querySelectorAll('body > div'))
  2244. if (!itm.querySelector('.dw-fdwlink, .content') && !itm.classList.contains('footer'))
  2245. remove(itm);
  2246. else
  2247. setBackground(itm);
  2248. }
  2249. // exist from DOMContentLoaded since the rest is not for forum
  2250. return;
  2251. }
  2252.  
  2253. FixNavMenu: {
  2254. // restore DevDB link in the navigation
  2255. let itm = _document.querySelector('#nav li a[href$="/devdb/"]')
  2256. if (!itm) {
  2257. console.warn('Unable to locate navigation menu');
  2258. break FixNavMenu;
  2259. }
  2260. itm.closest('li').style.display = 'block';
  2261. // hide ad link from the navigation
  2262. hide(_document.querySelector('#nav li a[data-dotrack]'));
  2263. }
  2264. SidebarAds: {
  2265. // remove ads from sidebar
  2266. let aside = _document.querySelectorAll('[class]:not([id]) > [id]:not([class]) > :first-child + :last-child');
  2267. if (!aside.length) {
  2268. console.warn('Unable to locate sidebar');
  2269. break SidebarAds;
  2270. }
  2271. let post;
  2272. for (let side of aside) {
  2273. console.log('Processing potential sidebar:', side);
  2274. for (let itm of Array.from(side.children)) {
  2275. post = itm.classList.contains('post');
  2276. if (itm.querySelector('iframe') && !post)
  2277. remove(itm);
  2278. if (itm.querySelector('script, a[target="_blank"] > img') && !post || !itm.children.length)
  2279. hide(itm);
  2280. }
  2281. }
  2282. }
  2283.  
  2284. _document.body.setAttribute('style', (_document.body.getAttribute('style')||'')+';background-color:#E6E7E9!important');
  2285.  
  2286. let extra = 'background-image:none!important;background-color:transparent!important',
  2287. fakeStyles = new WeakMap(),
  2288. styleProxy = {
  2289. get: (target, prop) => fakeStyles.get(target)[prop] || target[prop],
  2290. set: function(target, prop, value) {
  2291. let fakeStyle = fakeStyles.get(target);
  2292. ((prop in fakeStyle) ? fakeStyle : target)[prop] = value;
  2293. return true;
  2294. }
  2295. };
  2296. for (let itm of _document.querySelectorAll('[id]:not(A), A')) {
  2297. if (!(itm.offsetWidth > 0.95 * width() &&
  2298. itm.offsetHeight > 0.85 * height()))
  2299. continue;
  2300. if (itm.tagName !== 'A') {
  2301. fakeStyles.set(itm.style, {
  2302. 'backgroundImage': itm.style.backgroundImage,
  2303. 'backgroundColor': itm.style.backgroundColor
  2304. });
  2305.  
  2306. try {
  2307. Object.defineProperty(itm, 'style', {
  2308. value: new Proxy(itm.style, styleProxy),
  2309. enumerable: true
  2310. });
  2311. } catch (e) {
  2312. console.log('Unable to protect style property.', e);
  2313. }
  2314.  
  2315. if (protectedElems)
  2316. protectedElems.set(itm, _getAttribute.call(itm, 'style'));
  2317.  
  2318. _setAttribute.call(itm, 'style', `${(_getAttribute.call(itm, 'style') || '')};${extra}`);
  2319. }
  2320. if (itm.tagName === 'A') {
  2321. if (protectedElems)
  2322. protectedElems.set(itm, _getAttribute.call(itm, 'style'));
  2323. _setAttribute.call(itm, 'style', 'display:none!important');
  2324. }
  2325. }
  2326. }
  2327. );
  2328. }
  2329. };
  2330.  
  2331. scripts['adhands.ru'] = () => scriptLander(() => {
  2332. let nt = new nullTools();
  2333. try {
  2334. let _adv;
  2335. Object.defineProperty(win, 'adv', {
  2336. get: () => _adv,
  2337. set: (v) => {
  2338. console.log('Blocked advert on adhands.ru.');
  2339. nt.define(v, 'advert', '');
  2340. _adv = v;
  2341. }
  2342. });
  2343. } catch (ignore) {
  2344. if (!win.adv)
  2345. console.log('Unable to locate advert on adhands.ru.');
  2346. else {
  2347. console.log('Blocked advert on adhands.ru.');
  2348. nt.define(win.adv, 'advert', '');
  2349. }
  2350. }
  2351. }, nullTools);
  2352.  
  2353. scripts['all-episodes.tv'] = () => {
  2354. let nt = new nullTools();
  2355. nt.define(win, 'perX1', 2);
  2356. createStyle('#advtss, #ad3, a[href*="/ad.admitad.com/"] { display:none!important }');
  2357. };
  2358.  
  2359. scripts['allhentai.ru'] = () => {
  2360. selectiveEval();
  2361. preventPopups();
  2362. scriptLander(() => {
  2363. let _onerror = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'onerror');
  2364. if (!_onerror)
  2365. return;
  2366. _onerror.set = (...args) => console.log(args[0].toString());
  2367. Object.defineProperty(HTMLElement.prototype, 'onerror', _onerror);
  2368. });
  2369. };
  2370.  
  2371. scripts['allmovie.pro'] = {
  2372. other: ['rufilmtv.org'],
  2373. dom: function() {
  2374. // pretend to be Android to make site use different played for ads
  2375. if (isSafari)
  2376. return;
  2377. Object.defineProperty(navigator, 'userAgent', {
  2378. get: function(){
  2379. 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';
  2380. },
  2381. enumerable: true
  2382. });
  2383. }
  2384. };
  2385.  
  2386. scripts['anidub-online.ru'] = {
  2387. other: ['anime.anidub.com', 'online.anidub.com'],
  2388. dom: function() {
  2389. if (win.ogonekstart1)
  2390. win.ogonekstart1 = () => console.log("Fire in the hole!");
  2391. },
  2392. now: () => createStyle([
  2393. '.background {background: none!important;}',
  2394. '.background > script + div,'+
  2395. '.background > script ~ div:not([id]):not([class]) + div[id][class]'+
  2396. '{display:none!important}'
  2397. ])
  2398. };
  2399.  
  2400. scripts['drive2.ru'] = () => {
  2401. gardener('.c-block:not([data-metrika="recomm"]),.o-grid__item', />Реклама<\//i);
  2402. scriptLander(() => {
  2403. let _d2 = void 0;
  2404. Object.defineProperty(win, 'd2', {
  2405. get: () => _d2,
  2406. set: o => {
  2407. _d2 = new Proxy(o, {
  2408. set: (tgt, prop, val) => {
  2409. if (['brandingRender', 'dvReveal', '__dv'].includes(prop))
  2410. val = () => null;
  2411. tgt[prop] = val;
  2412. }
  2413. });
  2414. }
  2415. });
  2416. });
  2417. };
  2418.  
  2419. scripts['fishki.net'] = () => {
  2420. scriptLander(() => {
  2421. let nt = new nullTools();
  2422. let fishki = {};
  2423. nt.define(fishki, 'adv', nt.proxy({
  2424. afterAdblockCheck: nt.func(null),
  2425. refreshFloat: nt.func(null)
  2426. }));
  2427. nt.define(fishki, 'is_adblock', false);
  2428. nt.define(win, 'fishki', fishki);
  2429. }, nullTools);
  2430. gardener('.drag_list > .drag_element, .list-view > .paddingtop15, .post-wrap', /543769|Новости\sпартнеров|Полезная\sреклама/);
  2431. };
  2432.  
  2433. scripts['gidonline.club'] = () => createStyle('.tray > div[style] {display: none!important}');
  2434.  
  2435. scripts['hdgo.cc'] = {
  2436. other: ['46.30.43.38', 'couber.be'],
  2437. now: () => (new MutationObserver(
  2438. (ms) => {
  2439. let m, node;
  2440. for (m of ms) for (node of m.addedNodes)
  2441. if (node.tagName instanceof HTMLScriptElement && _getAttribute.call(node, 'onerror') !== null)
  2442. node.removeAttribute('onerror');
  2443. }
  2444. )).observe(_document.documentElement, { childList:true, subtree: true })
  2445. };
  2446.  
  2447. scripts['gismeteo.ru'] = {
  2448. other: ['gismeteo.ua'],
  2449. now: () => gardener('div > script', /AdvManager/i, { observe: true, parent: 'div' })
  2450. };
  2451.  
  2452. scripts['hdrezka.ag'] = () => {
  2453. Object.defineProperty(win, 'ab', { value: false, enumerable: true });
  2454. gardener('div[id][onclick][onmouseup][onmousedown]', /onmouseout/i);
  2455. };
  2456.  
  2457. scripts['hideip.me'] = {
  2458. now: () => scriptLander(() => {
  2459. let _innerHTML = Object.getOwnPropertyDescriptor(_Element.prototype, 'innerHTML');
  2460. let _set_innerHTML = _innerHTML.set;
  2461. let _innerText = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'innerText');
  2462. let _get_innerText = _innerText.get;
  2463. let div = _document.createElement('div');
  2464. _innerHTML.set = function(...args) {
  2465. _set_innerHTML.call(div, args[0].replace('i','a'));
  2466. if (args[0] && /[рp][еe]кл/.test(_get_innerText.call(div))||
  2467. /(\d\d\d?\.){3}\d\d\d?:\d/.test(_get_innerText.call(this)) ) {
  2468. console.log('Anti-Adblock killed.');
  2469. return true;
  2470. }
  2471. _set_innerHTML.apply(this, args);
  2472. };
  2473. Object.defineProperty(_Element.prototype, 'innerHTML', _innerHTML);
  2474. Object.defineProperty(win, 'adblock', {
  2475. get: () => false,
  2476. set: () => null,
  2477. enumerable: true
  2478. });
  2479. let _$ = {};
  2480. let _$_map = new WeakMap();
  2481. let _gOPD = Object.getOwnPropertyDescriptor(Object, 'getOwnPropertyDescriptor');
  2482. let _val_gOPD = _gOPD.value;
  2483. _gOPD.value = function(...args) {
  2484. let _res = _val_gOPD.apply(this, args);
  2485. if (args[0] instanceof Window && (args[1] === '$' || args[1] === 'jQuery')) {
  2486. delete _res.get;
  2487. delete _res.set;
  2488. _res.value = win[args[1]];
  2489. }
  2490. return _res;
  2491. };
  2492. Object.defineProperty(Object, 'getOwnPropertyDescriptor', _gOPD);
  2493. let getJQWrap = (n) => {
  2494. let name = n;
  2495. return {
  2496. enumerable: true,
  2497. get: () => _$[name],
  2498. set: x => {
  2499. if (_$_map.has(x)) {
  2500. _$[name] = _$_map.get(x);
  2501. return true;
  2502. }
  2503. if (x === _$.$ || x === _$.jQuery) {
  2504. _$[name] = x;
  2505. return true;
  2506. }
  2507. _$[name] = new Proxy(x, {
  2508. apply: (t, o, args) => {
  2509. let _res = t.apply(o, args);
  2510. if (_$_map.has(_res.is))
  2511. _res.is = _$_map.get(_res.is);
  2512. else {
  2513. let _is = _res.is;
  2514. _res.is = function(...args) {
  2515. if (args[0] === ':hidden')
  2516. return false;
  2517. return _is.apply(this, args);
  2518. };
  2519. _$_map.set(_is, _res.is);
  2520. }
  2521. return _res;
  2522. }
  2523. });
  2524. _$_map.set(x, _$[name]);
  2525. return true;
  2526. }
  2527. };
  2528. };
  2529. Object.defineProperty(win, '$', getJQWrap('$'));
  2530. Object.defineProperty(win, 'jQuery', getJQWrap('jQuery'));
  2531. let _dP = Object.defineProperty;
  2532. Object.defineProperty = function(...args) {
  2533. if (args[0] instanceof Window && (args[1] === '$' || args[1] === 'jQuery'))
  2534. return void 0;
  2535. return _dP.apply(this, args);
  2536. };
  2537. })
  2538. };
  2539.  
  2540. scripts['igra-prestoloff.cx'] = () => scriptLander(() => {
  2541. let nt = new nullTools();
  2542. /*jslint evil: true */ // yes, evil, I know
  2543. let _write = _document.write.bind(_document);
  2544. /*jslint evil: false */
  2545. nt.define(_document, 'write', t => {
  2546. let id = t.match(/jwplayer\("(\w+)"\)/i);
  2547. if (id && id[1])
  2548. return _write(`<div id="${id[1]}"></div>${t}`);
  2549. return _write('');
  2550. });
  2551. });
  2552.  
  2553. scripts['imageban.ru'] = {
  2554. now: () => {
  2555. Object.defineProperty(win, 'V7x1J', { get: () => null });
  2556. //preventPopunders();
  2557. }
  2558. };
  2559.  
  2560. scripts['kinopoisk.ru'] = {
  2561. now: () => {
  2562. // set no-branding body style
  2563. createStyle('body:not(#id) { background: #d5d5d5 url(/images/noBrandBg.jpg) 50% 0 no-repeat !important }');
  2564. },
  2565. dom: () => {
  2566. (style => style ? style.parentNode.removeChild(style) : console.log('Unable to locate branding style.')
  2567. )(_de.querySelector('#branding-style'));
  2568. }
  2569. };
  2570.  
  2571. scripts['korrespondent.net'] = {
  2572. now: () => scriptLander(() => {
  2573. let nt = new nullTools();
  2574. nt.define(win, 'holder', function(id) {
  2575. let div = _document.getElementById(id);
  2576. if (!div)
  2577. return;
  2578. if (div.parentNode.classList.contains('col__sidebar')) {
  2579. div.parentNode.appendChild(div);
  2580. div.style.height = '300px';
  2581. }
  2582. });
  2583. }, nullTools),
  2584. dom: () => {
  2585. for (let frame of _document.querySelectorAll('.unit-side-informer > iframe'))
  2586. frame.parentNode.style.width = '1px';
  2587. }
  2588. };
  2589.  
  2590. scripts['mail.ru'] = {
  2591. other: ['ok.ru'],
  2592. now: () => scriptLander(() => {
  2593. let nt = new nullTools();
  2594. // Trick to prevent mail.ru from removing 3rd-party styles
  2595. nt.define(Object.prototype, 'restoreVisibility', nt.func(null), false);
  2596. // Disable some of their counters
  2597. nt.define(win, 'rb_counter', nt.func(null, 'rb_counter'));
  2598. if (location.hostname === 'e.mail.ru')
  2599. nt.define(win, 'aRadar', nt.func(null, 'aRadar'));
  2600. else
  2601. nt.define(win, 'createRadar', nt.func(nt.func(null, 'aRadar'), 'createRadar'));
  2602.  
  2603. // Disable page scrambler on mail.ru to let extensions easily block ads there
  2604. function defineLocator(root) {
  2605. let _locator;
  2606. let fishnet = {
  2607. apply: (target, thisArg, args) => {
  2608. console.log(`locator.${target._name}(${JSON.stringify(args).slice(1,-1)})`);
  2609. return target.apply(thisArg, args);
  2610. }
  2611. };
  2612.  
  2613. function wrapLocator(locator) {
  2614. if ('setup' in locator) {
  2615. let _setup = locator.setup;
  2616. locator.setup = function(o) {
  2617. if ('enable' in o) {
  2618. o.enable = false;
  2619. console.log('Disable mimic mode.');
  2620. }
  2621. if ('links' in o) {
  2622. o.links = [];
  2623. console.log('Call with empty list of sheets.');
  2624. }
  2625. return _setup.call(this, o);
  2626. };
  2627. locator.insertSheet = () => console.log('Ignore insertSheet.');
  2628. locator.wrap = () => console.log('Ignore wrap.');
  2629. }
  2630. try {
  2631. let names = [];
  2632. for (let name in locator)
  2633. if (locator[name] instanceof Function) {
  2634. locator[name]._name = name;
  2635. locator[name] = new Proxy(locator[name], fishnet);
  2636. names.push(name);
  2637. }
  2638. console.log(`[locator] wrapped properties: ${names.join(', ')}`);
  2639. } catch(e) {
  2640. console.log(e);
  2641. }
  2642. _locator = locator;
  2643. }
  2644.  
  2645. if ('locator' in root && root.locator) {
  2646. console.log('Found existing "locator" object. :|');
  2647. _locator = root.locator;
  2648. wrapLocator(root.locator);
  2649. }
  2650.  
  2651. let loc_desc = Object.getOwnPropertyDescriptor(root, 'locator');
  2652. if (!loc_desc || loc_desc.set !== wrapLocator)
  2653. try {
  2654. Object.defineProperty(root, 'locator', {
  2655. set: wrapLocator,
  2656. get: () => _locator
  2657. });
  2658. } catch (err) {
  2659. console.log('Unable to redefine "locator" object!!!', err);
  2660. }
  2661. }
  2662.  
  2663. function defineDetector(mr) {
  2664. let __ = mr._ || {};
  2665.  
  2666. if ('HONEYPOT' in __) {
  2667. console.log('Disarming existing detector instance. :|', JSON.stringify(__));
  2668. nt.define(__, 'HONEYPOT', '.honeypot_fake_class_to_miss');
  2669. nt.define(__, 'STUCK_IN_POT', false);
  2670. }
  2671.  
  2672. __ = new Proxy(__, {
  2673. get: (t, p) => t[p],
  2674. set: (t, p, v) => {
  2675. console.log(`mr._.${p} =`, v);
  2676. if (['HONEYPOT', 'STUCK_IN_POT'].includes(p))
  2677. console.log('Not changed.');
  2678. t[p] = v; // setter in nt.define will prevent this when needed
  2679. return true;
  2680. }
  2681. });
  2682. Object.defineProperty(mr, '_', {
  2683. enumerable: true,
  2684. value: __
  2685. });
  2686. }
  2687.  
  2688. if (location.hostname === 'e.mail.ru')
  2689. defineLocator(win);
  2690. else
  2691. try {
  2692. let _mr;
  2693. Object.defineProperty(win, 'mr', {
  2694. enumerable: true,
  2695. get: () => _mr,
  2696. set: (v) => {
  2697. if (v === _mr)
  2698. return true;
  2699. console.log('Trapped new "mr" object.');
  2700. defineLocator(v.mimic ? v.mimic : v);
  2701. defineDetector(v);
  2702. _mr = v;
  2703. }
  2704. });
  2705. if (!('mr' in win))
  2706. throw 'Wat!?';
  2707. } catch (e) {
  2708. console.log('Found existing "mr" object.', e instanceof TypeError ? '' : e);
  2709. defineLocator(win.mr);
  2710. defineDetector(win.mr);
  2711. }
  2712. }, nullTools)
  2713. };
  2714.  
  2715. scripts['megogo.net'] = {
  2716. now: () => {
  2717. let nt = new nullTools();
  2718. nt.define(win, 'adBlock', false);
  2719. nt.define(win, 'showAdBlockMessage', nt.func(null));
  2720. }
  2721. };
  2722.  
  2723. scripts['naruto-base.su'] = () => gardener('div[id^="entryID"],.block', /href="http.*?target="_blank"/i);
  2724.  
  2725. scripts['overclockers.ru'] = {
  2726. now: () => scriptLander(() => {
  2727. let _innerHTML = Object.getOwnPropertyDescriptor(_Element.prototype, 'innerHTML');
  2728. let _set_innerHTML = _innerHTML.set;
  2729. _innerHTML.set = function() {
  2730. if (this === _document.body) {
  2731. console.log('Anti-Adblock killed.');
  2732. return true;
  2733. }
  2734. _set_innerHTML.apply(this, arguments);
  2735. };
  2736. Object.defineProperty(_Element.prototype, 'innerHTML', _innerHTML);
  2737. }),
  2738. dom: () => scriptLander(() => {
  2739. let killed = () => console.log('Anti-Adblock killed.');
  2740. if ('$' in win)
  2741. win.$ = new Proxy($, {
  2742. apply: (tgt, that, args) => {
  2743. let res = tgt.apply(that, args);
  2744. if (res[0] && res[0] === _document.body) {
  2745. res.html = () => killed;
  2746. res.empty = () => killed;
  2747. }
  2748. return res;
  2749. }
  2750. });
  2751. })
  2752. };
  2753. scripts['forums.overclockers.ru'] = {
  2754. now: () => {
  2755. createStyle('.needblock {position: fixed; left: -10000px}');
  2756. Object.defineProperty(win, 'adblck', {
  2757. get: () => 'no',
  2758. set: () => undefined,
  2759. enumerable: true
  2760. });
  2761. }
  2762. };
  2763.  
  2764. scripts['pb.wtf'] = {
  2765. other: ['piratbit.org', 'piratbit.ru'],
  2766. dom: () => {
  2767. // line above topic content and images in the slider in the header
  2768. let remove = node => (console.log('removed', node), node.parentNode.removeChild(node));
  2769. for (let el of _document.querySelectorAll('.release-navbar a, #page_content a')) {
  2770. if (location.hostname === el.hostname &&
  2771. /^\/(\w{3}|exit)\/[\w=/]{20,}$/.test(el.pathname)) {
  2772. remove(el.closest('div, tr'));
  2773. continue;
  2774. }
  2775. // ads in the topic header in case filter above wasn't enough
  2776. let parent = el.closest('tr');
  2777. if (parent && parent.querySelector('span') &&
  2778. parent.querySelector('span').textContent.startsWith('Реклам'))
  2779. remove(parent);
  2780. }
  2781. // casino ad button in random places
  2782. for (let el of _document.querySelectorAll('.btn-group')) {
  2783. el = el.parentNode.parentNode;
  2784. if (el.tagName === 'TH')
  2785. remove(el);
  2786. }
  2787. // ads in comments
  2788. let el = _document.querySelector('tbody[id^="post_"] + tbody:not([id])');
  2789. if (el && el.parentNode.children[2] == el)
  2790. remove(el);
  2791. }
  2792. };
  2793.  
  2794. scripts['pikabu.ru'] = () => gardener('.story', /story__author[^>]+>ads</i, {root: '.inner_wrap', observe: true});
  2795.  
  2796. scripts['peka2.tv'] = () => {
  2797. let bodyClass = 'body--branding';
  2798. let checkNode = node => {
  2799. for (let className of node.classList)
  2800. if (className.includes('banner') || className === bodyClass) {
  2801. _removeAttribute.call(node, 'style');
  2802. node.classList.remove(className);
  2803. for (let attr of Array.from(node.attributes))
  2804. if (attr.name.startsWith('advert'))
  2805. _removeAttribute.call(node, attr.name);
  2806. }
  2807. };
  2808. (new MutationObserver(ms => {
  2809. let m, node;
  2810. for (m of ms) for (node of m.addedNodes)
  2811. if (node instanceof HTMLElement)
  2812. checkNode(node);
  2813. })).observe(_de, {childList: true, subtree: true});
  2814. (new MutationObserver(ms => {
  2815. for (let m of ms)
  2816. checkNode(m.target);
  2817. })).observe(_de, {attributes: true, subtree: true, attributeFilter: ['class']});
  2818. };
  2819.  
  2820. scripts['qaru.site'] = () => {
  2821. let _src = Object.getOwnPropertyDescriptor(HTMLScriptElement.prototype, 'src');
  2822. let _src_set = _src.set;
  2823. _src.set = function(val) {
  2824. if (val.includes('fuckadblock') || val.includes('googlesyndication'))
  2825. return;
  2826. return _src_set.apply(this, arguments);
  2827. };
  2828. Object.defineProperty(HTMLScriptElement.prototype, 'src', _src);
  2829.  
  2830. let _addEventListener = EventTarget.prototype.addEventListener;
  2831. let _toString = Function.prototype.call.bind(Function.prototype.toString);
  2832. EventTarget.prototype.addEventListener = function addEventListener() {
  2833. if (arguments[0] === 'load' && _toString(arguments[1]).includes("_creatBait"))
  2834. return _addEventListener.call(
  2835. this, arguments[0], () => {
  2836. if ('fuckAdBlock' in win)
  2837. win.fuckAdBlock.emitEvent('notDetected');
  2838. }, arguments[2]
  2839. );
  2840. return _addEventListener.apply(this, arguments);
  2841. };
  2842. };
  2843.  
  2844. scripts['qrz.ru'] = {
  2845. now: () => {
  2846. let nt = new nullTools();
  2847. nt.define(win, 'ab', false);
  2848. nt.define(win, 'tryMessage', nt.func(null));
  2849. }
  2850. };
  2851.  
  2852. scripts['razlozhi.ru'] = {
  2853. now: () => {
  2854. for (let func of ['createShadowRoot', 'attachShadow'])
  2855. if (func in _Element.prototype)
  2856. _Element.prototype[func] = function(){
  2857. return this.cloneNode();
  2858. };
  2859. }
  2860. };
  2861.  
  2862. scripts['rbc.ru'] = {
  2863. dom: () => {
  2864. let _preventDefault = Event.prototype.preventDefault;
  2865. Event.prototype.preventDefault = function preventDefault() {
  2866. let t = this.target;
  2867. if (t instanceof HTMLAnchorElement || t.closest('A'))
  2868. throw new Error('an.yandex redirect prevention');
  2869. return _preventDefault.call(this);
  2870. };
  2871.  
  2872. function cleaner(nodes) {
  2873. for (let node of nodes) {
  2874. if (!node.classList || !node.classList.contains('js-yandex-counter'))
  2875. continue;
  2876. node.classList.remove('js-yandex-counter');
  2877. node.removeAttribute('data-yandex-name');
  2878. node.removeAttribute('data-yandex-params');
  2879. }
  2880. }
  2881. cleaner(_de.querySelectorAll('.js-yandex-counter'));
  2882.  
  2883. (new MutationObserver(
  2884. ms => {
  2885. for (let m of ms) cleaner(m.addedNodes);
  2886. }
  2887. )).observe(_de, {childList: true, subtree: true});
  2888. }
  2889. };
  2890.  
  2891. scripts['rp5.ru'] = {
  2892. other: ['rp5.by', 'rp5.kz', 'rp5.ua'],
  2893. now: () => gardener('div[id][class]', /\?AdvertMgmt=|adsbygoogle/, { root: '#content-wrapper', log: true })
  2894. };
  2895.  
  2896. scripts['rutube.ru'] = () => scriptLander(() => {
  2897. let _parse = JSON.parse;
  2898. let _skip_enabled = false;
  2899. JSON.parse = (...args) => {
  2900. let res = _parse(...args),
  2901. log = false;
  2902. if (!res)
  2903. return res;
  2904. // parse player configuration
  2905. if ('appearance' in res || 'video_balancer' in res) {
  2906. log = true;
  2907. if (res.appearance) {
  2908. if ('forbid_seek' in res.appearance && res.appearance.forbid_seek)
  2909. res.appearance.forbid_seek = false;
  2910. if ('forbid_timeline_preview' in res.appearance && res.appearance.forbid_timeline_preview)
  2911. res.appearance.forbid_timeline_preview = false;
  2912. }
  2913. _skip_enabled = !!res.remove_unseekable_blocks;
  2914. //res.advert = [];
  2915. delete res.advert;
  2916. //for (let limit of res.limits)
  2917. // limit.limit = 0;
  2918. delete res.limits;
  2919. //res.yast = null;
  2920. //res.yast_live_online = null;
  2921. delete res.yast;
  2922. delete res.yast_live_online;
  2923. Object.defineProperty(res, 'stat', {
  2924. get: () => [],
  2925. set: () => true,
  2926. enumerable: true
  2927. });
  2928. }
  2929.  
  2930. // parse video configuration
  2931. if ('video_url' in res) {
  2932. log = true;
  2933. if (res.cuepoints && !_skip_enabled)
  2934. for (let point of res.cuepoints) {
  2935. point.is_pause = false;
  2936. point.show_navigation = true;
  2937. point.forbid_seek = false;
  2938. }
  2939. }
  2940.  
  2941. if (log)
  2942. console.log('[rutube]', res);
  2943. return res;
  2944. };
  2945. });
  2946.  
  2947. scripts['simpsonsua.com.ua'] = () => scriptLander(() => {
  2948. let _addEventListener = Object.getPrototypeOf(HTMLDocument).prototype.addEventListener;
  2949. _document.addEventListener = function(event, callback) {
  2950. if (event === 'DOMContentLoaded' && callback.toString().includes('show_warning'))
  2951. return;
  2952. return _addEventListener.apply(this, arguments);
  2953. };
  2954. });
  2955.  
  2956. scripts['smotret-anime.ru'] = () => {
  2957. function setCookies() {
  2958. _document.cookie = `watchedVideoToday=1; expires=; path=/`;
  2959. _document.cookie = `watchedPromoVideo=${(new Date()).valueOf()}; expires=; path=/`;
  2960. }
  2961. setCookies();
  2962. setInterval(setCookies, 10000);
  2963. };
  2964.  
  2965. scripts['spaces.ru'] = () => {
  2966. gardener('div:not(.f-c_fll) > a[href*="spaces.ru/?Cl="]', /./, { parent: 'div' });
  2967. gardener('.js-banner_rotator', /./, { parent: '.widgets-group' });
  2968. };
  2969.  
  2970. scripts['spam-club.blogspot.co.uk'] = () => {
  2971. let _clientHeight = Object.getOwnPropertyDescriptor(_Element.prototype, 'clientHeight'),
  2972. _clientWidth = Object.getOwnPropertyDescriptor(_Element.prototype, 'clientWidth');
  2973. let wrapGetter = (getter) => {
  2974. let _getter = getter;
  2975. return function() {
  2976. let _size = _getter.apply(this, arguments);
  2977. return _size ? _size : 1;
  2978. };
  2979. };
  2980. _clientHeight.get = wrapGetter(_clientHeight.get);
  2981. _clientWidth.get = wrapGetter(_clientWidth.get);
  2982. Object.defineProperty(_Element.prototype, 'clientHeight', _clientHeight);
  2983. Object.defineProperty(_Element.prototype, 'clientWidth', _clientWidth);
  2984. let _onload = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'onload'),
  2985. _set_onload = _onload.set;
  2986. _onload.set = function() {
  2987. if (this instanceof HTMLImageElement)
  2988. return true;
  2989. _set_onload.apply(this, arguments);
  2990. };
  2991. Object.defineProperty(HTMLElement.prototype, 'onload', _onload);
  2992. };
  2993.  
  2994. scripts['sport-express.ru'] = () => gardener('.js-relap__item',/>Реклама\s+<\//, {root:'.container', observe: true});
  2995.  
  2996. scripts['sports.ru'] = {
  2997. now: () => {
  2998. gardener('.aside-news-list__item', /aside-news-list__advert/i, {root:'.columns-layout__left', observe: true});
  2999. gardener('.material-list__item', /Реклама/i, {root:'.columns-layout', observe: true});
  3000. // extra functionality: shows/hides panel at the top depending on scroll direction
  3001. createStyle([
  3002. '.user-panel__fixed { transition: top 0.2s ease-in-out!important; }',
  3003. '.user-panel-up { top: -40px!important }'
  3004. ], {id: 'userPanelSlide'}, false);
  3005. },
  3006. dom: () => {
  3007. (function lookForPanel() {
  3008. let panel = _document.querySelector('.user-panel__fixed');
  3009. if (!panel)
  3010. setTimeout(lookForPanel, 100);
  3011. else
  3012. window.addEventListener(
  3013. 'wheel', function(e) {
  3014. if (e.deltaY > 0 && !panel.classList.contains('user-panel-up'))
  3015. panel.classList.add('user-panel-up');
  3016. else if (e.deltaY < 0 && panel.classList.contains('user-panel-up'))
  3017. panel.classList.remove('user-panel-up');
  3018. }, false
  3019. );
  3020. })();
  3021. }
  3022. };
  3023.  
  3024. scripts['stealthz.ru'] = {
  3025. dom: () => {
  3026. // skip timeout
  3027. let $ = _document.querySelector.bind(_document);
  3028. let [timer_1, timer_2] = [$('#timer_1'), $('#timer_2')];
  3029. if (!timer_1 || !timer_2)
  3030. return;
  3031. timer_1.style.display = 'none';
  3032. timer_2.style.display = 'block';
  3033. }
  3034. };
  3035.  
  3036. scripts['yap.ru'] = {
  3037. other: ['yaplakal.com'],
  3038. now: () => {
  3039. gardener('form > table[id^="p_row_"]:nth-of-type(2)', /member1438|Administration/);
  3040. gardener('.icon-comments', /member1438|Administration|\/go\/\?http/, {parent:'tr', siblings:-2});
  3041. }
  3042. };
  3043.  
  3044. scripts['rambler.ru'] = {
  3045. other: ['championat.com', 'gazeta.ru', 'lenta.ru', 'media.eagleplatform.com', 'quto.ru', 'rns.online'],
  3046. now: () => scriptLander(() => {
  3047. // Prevent autoplay
  3048. if (!('EaglePlayer' in win)) {
  3049. let _EaglePlayer = void 0;
  3050. Object.defineProperty(win, 'EaglePlayer', {
  3051. enumerable: true,
  3052. get: () => _EaglePlayer,
  3053. set: x => {
  3054. if (x === _EaglePlayer)
  3055. return true;
  3056. _EaglePlayer = new Proxy(x, {
  3057. construct: (targ, args) => {
  3058. let player = new targ(...args);
  3059. if (!player.options) {
  3060. console.log('EaglePlayer: no options', EaglePlayer);
  3061. return player;
  3062. }
  3063. Object.defineProperty(player.options, 'autoplay', {
  3064. get: () => false,
  3065. set: () => true
  3066. });
  3067. Object.defineProperty(player.options, 'scroll', {
  3068. get: () => false,
  3069. set: () => true
  3070. });
  3071. return player;
  3072. }
  3073. });
  3074. }
  3075. });
  3076. let _setAttribute = _Element.prototype.setAttribute;
  3077. let isAutoplay = /^autoplay$/i;
  3078. _Element.prototype.setAttribute = function setAttribute(name) {
  3079. if (!this._stopped && isAutoplay.test(name)) {
  3080. console.log('Prevented assigning autoplay attribute.');
  3081. return null;
  3082. }
  3083. return _setAttribute.apply(this, arguments);
  3084. };
  3085. } else {
  3086. console.log('EaglePlayer function already exists.');
  3087. if (inIFrame) {
  3088. let _setAttribute = _Element.prototype.setAttribute;
  3089. let isAutoplay = /^autoplay$/i;
  3090. _Element.prototype.setAttribute = function setAttribute(name) {
  3091. if (!this._stopped && isAutoplay.test(name)) {
  3092. console.log('Prevented assigning autoplay attribute.');
  3093. this._stopped = true;
  3094. this.play = () => {
  3095. console.log('Prevented attempt to force-start playback.');
  3096. delete this.play;
  3097. };
  3098. return null;
  3099. }
  3100. return _setAttribute.apply(this, arguments);
  3101. };
  3102. }
  3103. }
  3104. if (location.hostname.endsWith('.media.eagleplatform.com'))
  3105. return;
  3106. // prevent ads from loading
  3107. let blockObfuscated = false;
  3108. let obfuscation = /\[[a-z]{4}\("0x\d+"\)\]/i;
  3109. let fts = Function.prototype.toString;
  3110. let CSSRuleProto = 'cssText' in CSSRule.prototype ? CSSRule.prototype : CSSStyleRule.prototype;
  3111. let _cssText = Object.getOwnPropertyDescriptor(CSSRuleProto, 'cssText');
  3112. let _cssText_get = _cssText.get;
  3113. _cssText.configurable = false;
  3114. _cssText.get = function() {
  3115. let cssText = _cssText_get.call(this);
  3116. if (cssText.includes('content:')) {
  3117. console.warn('Blocked access to suspicious cssText:', cssText.slice(0,60), '\u2026', cssText.length);
  3118. blockObfuscated = true;
  3119. return null;
  3120. }
  3121. return cssText;
  3122. };
  3123. Object.defineProperty(CSSRuleProto, 'cssText', _cssText);
  3124. let _setTimeout = win.setTimeout;
  3125. win.setTimeout = function(f) {
  3126. if (blockObfuscated && obfuscation.test(fts.call(f))) {
  3127. console.warn('Stopped setTimeout for:', fts.call(f).slice(0,100), '\u2026');
  3128. return null;
  3129. };
  3130. return _setTimeout.apply(this, arguments);
  3131. };
  3132. // fake global Adf object
  3133. let nt = new nullTools();
  3134. let Adf_banner = {};
  3135. [
  3136. 'reloadssp', 'sspScroll',
  3137. 'sspRich', 'ssp'
  3138. ].forEach(name => void(Adf_banner[name] = nt.proxy(() => new Promise(r => r({status: true})))));
  3139. nt.define(win, 'Adf', nt.proxy({
  3140. banner: nt.proxy(Adf_banner)
  3141. }));
  3142. // extra script to remove partner news on gazeta.ru
  3143. if (!location.hostname.includes('gazeta.ru'))
  3144. return;
  3145. (new MutationObserver(
  3146. (ms) => {
  3147. let m, node, header;
  3148. for (m of ms) for (node of m.addedNodes)
  3149. if (node instanceof HTMLDivElement && node.matches('.sausage')) {
  3150. header = node.querySelector('.sausage-header');
  3151. if (header && /новости\s+партн[её]ров/i.test(header.textContent))
  3152. node.style.display = 'none';
  3153. }
  3154. }
  3155. )).observe(_document.documentElement, { childList:true, subtree: true });
  3156. }, `let inIFrame = ${inIFrame}`, nullTools)
  3157. };
  3158.  
  3159. scripts['reactor.cc'] = {
  3160. other: ['joyreactor.cc', 'pornreactor.cc'],
  3161. now: () => {
  3162. selectiveEval();
  3163. scriptLander(() => {
  3164. let nt = new nullTools();
  3165. win.open = function(){
  3166. throw new Error('Redirect prevention.');
  3167. };
  3168. nt.define(win, 'Worker', function(){});
  3169. nt.define(win, 'JRCH', win.CoinHive);
  3170. }, nullTools);
  3171. },
  3172. click: function(e) {
  3173. let node = e.target;
  3174. if (node.nodeType === _Node.ELEMENT_NODE &&
  3175. node.style.position === 'absolute' &&
  3176. node.style.zIndex > 0)
  3177. node.parentNode.removeChild(node);
  3178. },
  3179. dom: function() {
  3180. let words = new RegExp(
  3181. 'блокировщик рекламы'
  3182. .split('')
  3183. .map(function(e){
  3184. return e+'[\u200b\u200c\u200d]*';
  3185. })
  3186. .join('')
  3187. .replace(' ', '\\s*')
  3188. .replace(/[аоре]/g, function(e){
  3189. return ['[аa]','[оo]','[рp]','[еe]']['аоре'.indexOf(e)];
  3190. }),
  3191. 'i'),
  3192. can;
  3193. function deeper(spider) {
  3194. for (let child of spider.childNodes)
  3195. if (words.test(child.innerText))
  3196. if (child.offsetHeight >= 750)
  3197. deeper(child);
  3198. else
  3199. can.push(child);
  3200. }
  3201. function probe() {
  3202. can = [];
  3203. deeper(_document.body);
  3204. for (let spider of can)
  3205. _setAttribute.call(spider, 'style', 'background:none!important');
  3206. }
  3207. (new MutationObserver(probe))
  3208. .observe(_document, { childList:true, subtree:true });
  3209. }
  3210. };
  3211.  
  3212. scripts['auto.ru'] = () => {
  3213. let words = /Реклама|Яндекс.Директ|yandex_ad_/;
  3214. let userAdsListAds = (
  3215. '.listing-list > .listing-item,'+
  3216. '.listing-item_type_fixed.listing-item'
  3217. );
  3218. let catalogAds = (
  3219. 'div[class*="layout_catalog-inline"],'+
  3220. 'div[class$="layout_horizontal"]'
  3221. );
  3222. let otherAds = (
  3223. '.advt_auto,'+
  3224. '.sidebar-block,'+
  3225. '.pager-listing + div[class],'+
  3226. '.card > div[class][style],'+
  3227. '.sidebar > div[class],'+
  3228. '.main-page__section + div[class],'+
  3229. '.listing > tbody'
  3230. );
  3231. gardener(userAdsListAds, words, {root:'.listing-wrap', observe:true});
  3232. gardener(catalogAds, words, {root:'.catalog__page,.content__wrapper', observe:true});
  3233. gardener(otherAds, words);
  3234. };
  3235.  
  3236. scripts['rsload.net'] = {
  3237. load: () => {
  3238. let dis = _document.querySelector('label[class*="cb-disable"]');
  3239. if (dis)
  3240. dis.click();
  3241. },
  3242. click: e => {
  3243. let t = e.target;
  3244. if (t && t.href && (/:\/\/\d+\.\d+\.\d+\.\d+\//.test(t.href)))
  3245. t.href = t.href.replace('://','://rsload.net:rsload.net@');
  3246. }
  3247. };
  3248.  
  3249. let domain;
  3250. // add alternative domain names if present and wrap functions into objects
  3251. for (let name in scripts) {
  3252. if (scripts[name] instanceof Function)
  3253. scripts[name] = { now: scripts[name] };
  3254. for (domain of (scripts[name].other||[])) {
  3255. if (domain in scripts)
  3256. console.log('Error in scripts list. Script for', name, 'replaced script for', domain);
  3257. scripts[domain] = scripts[name];
  3258. }
  3259. delete scripts[name].other;
  3260. }
  3261. // look for current domain in the list and run appropriate code
  3262. domain = _document.domain;
  3263. while (domain.indexOf('.') > -1) {
  3264. if (domain in scripts) for (let when in scripts[domain])
  3265. switch(when) {
  3266. case 'now':
  3267. scripts[domain][when]();
  3268. break;
  3269. case 'dom':
  3270. _document.addEventListener('DOMContentLoaded', scripts[domain][when], false);
  3271. break;
  3272. default:
  3273. _document.addEventListener (when, scripts[domain][when], false);
  3274. }
  3275. domain = domain.slice(domain.indexOf('.') + 1);
  3276. }
  3277.  
  3278. // Batch script lander
  3279. if (!skipLander)
  3280. landScript(batchLand, batchPrepend);
  3281.  
  3282. { // JS Fixes Tools Menu
  3283. let openOptions = function() {
  3284. let ovl = _createElement('div'),
  3285. inner = _createElement('div');
  3286. ovl.style = (
  3287. 'position: fixed;'+
  3288. 'top:0; left:0;'+
  3289. 'bottom: 0; right: 0;'+
  3290. 'background: rgba(0,0,0,0.85);'+
  3291. 'z-index: 2147483647;'+
  3292. 'padding: 5em'
  3293. );
  3294. inner.style = (
  3295. 'background: whitesmoke;'+
  3296. 'font-size: 10pt;'+
  3297. 'color: black;'+
  3298. 'padding: 1em'
  3299. );
  3300. inner.textContent = 'JS Fixes Tools';
  3301. inner.appendChild(_createElement('br'));
  3302. inner.appendChild(_createElement('br'));
  3303. ovl.addEventListener(
  3304. 'click', function(e) {
  3305. if (e.target === ovl) {
  3306. ovl.parentNode.removeChild(ovl);
  3307. e.preventDefault();
  3308. }
  3309. e.stopPropagation();
  3310. }, false
  3311. );
  3312.  
  3313. let sObjBtn = _createElement('button');
  3314. sObjBtn.onclick = getStrangeObjectsList;
  3315. sObjBtn.textContent = 'Print (in console) list of unusual window properties';
  3316. inner.appendChild(_createElement('br'));
  3317. inner.appendChild(sObjBtn);
  3318.  
  3319. _document.body.appendChild(ovl);
  3320. ovl.appendChild(inner);
  3321. };
  3322.  
  3323. // monitor keys pressed for Ctrl+Alt+Shift+J > s > f code
  3324. let opPos = 0, opKey = ['KeyJ','KeyS','KeyF'];
  3325. _document.addEventListener(
  3326. 'keydown', function(e) {
  3327. if ((e.code === opKey[opPos] || e.location) &&
  3328. (!!opPos || e.altKey && e.ctrlKey && e.shiftKey)) {
  3329. opPos += e.location ? 0 : 1;
  3330. e.stopPropagation();
  3331. e.preventDefault();
  3332. } else
  3333. opPos = 0;
  3334. if (opPos === opKey.length) {
  3335. opPos = 0;
  3336. openOptions();
  3337. }
  3338. }, false
  3339. );
  3340. }
  3341. })();