RU AdList JS Fixes

try to take over the world!

当前为 2018-07-31 提交的版本,查看 最新版本

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