Greasy Fork 还支持 简体中文。

RU AdList JS Fixes

try to take over the world!

目前為 2018-07-24 提交的版本,檢視 最新版本

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