RU AdList JS Fixes

try to take over the world!

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

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