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