RU AdList JS Fixes

try to take over the world!

当前为 2018-12-26 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name RU AdList JS Fixes
  3. // @namespace ruadlist_js_fixes
  4. // @version 20181226.0
  5. // @description try to take over the world!
  6. // @author lainverse & dimisa
  7. // @supportURL https://gf.qytechs.cn/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.prototype);
  29. let _Element = Object.getPrototypeOf(HTMLElement.prototype);
  30. // dTree 2.05 in some cases replaces Node object
  31. let _Node = Object.getPrototypeOf(_Element);
  32. let _console = {};
  33. for (let name in win.console) _console[name] = console[name];
  34.  
  35. // http://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser
  36. let isOpera = (!!window.opr && !!window.opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0,
  37. isChrome = !!window.chrome && !!window.chrome.webstore,
  38. isSafari =
  39. Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0 ||
  40. (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window.safari || window.safari.pushNotification);
  41. let isFirefox = 'InstallTrigger' in win;
  42. let inIFrame = (win.self !== win.top);
  43. let _getAttribute = Function.prototype.call.bind(_Element.getAttribute),
  44. _setAttribute = Function.prototype.call.bind(_Element.setAttribute),
  45. _removeAttribute = Function.prototype.call.bind(_Element.removeAttribute);
  46. let _document = win.document,
  47. _de = _document.documentElement,
  48. _appendChild = _Document.appendChild.bind(_de),
  49. _removeChild = _Document.removeChild.bind(_de),
  50. _createElement = _Document.createElement.bind(_document);
  51.  
  52. if (isFirefox && // Exit on image pages in Fx
  53. _document.constructor.prototype.toString() === '[object ImageDocumentPrototype]')
  54. return;
  55.  
  56. // NodeList and HTMLCollection iterator polyfill
  57. // required for old versions of Safari and Chrome 49 (last available for WinXP)
  58. // https://jakearchibald.com/2014/iterators-gonna-iterate/
  59. if (!NodeList.prototype[Symbol.iterator])
  60. NodeList.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
  61. if (!HTMLCollection.prototype[Symbol.iterator])
  62. HTMLCollection.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
  63.  
  64. // Wrapper to run scripts designed to override objects available to other scripts
  65. // Required in old versions of Firefox (<58) or when running with Greasemonkey
  66. let skipLander = true;
  67. try {
  68. skipLander = !(isFirefox && ('StopIteration' in win || GM.info.scriptHandler === 'Greasemonkey'));
  69. } catch(ignore){}
  70. let batchLand = [];
  71. let batchPrepend = [];
  72. let _APIString = 'let win = window, _console = {}; for (let name in win.console) _console[name] = console[name]; '+
  73. 'let _document = win.document, _Document = Object.getPrototypeOf(HTMLDocument.prototype),'+
  74. ' _Element = Object.getPrototypeOf(HTMLElement.prototype), _Node = Object.getPrototypeOf(_Element);';
  75. let landScript = (f, pre) => {
  76. let script = _createElement('script');
  77. script.textContent = `(()=>{${_APIString}${(
  78. (pre.length > 0 ? pre.join(';') : '')
  79. )};(${f.join(')();(')})();})();`;
  80. _appendChild(script);
  81. _removeChild(script);
  82. };
  83. let scriptLander = f => f();
  84. if (!skipLander) {
  85. scriptLander = (func, ...prepend) => {
  86. prepend.forEach(
  87. x => batchPrepend.includes(x) ? null : batchPrepend.push(x)
  88. );
  89. batchLand.push(func);
  90. };
  91. _document.addEventListener(
  92. 'DOMContentLoaded', () => void (scriptLander = (f, ...prep) => landScript([f], prep)), false
  93. );
  94. }
  95.  
  96. function nullTools(opts) {
  97. let nt = this;
  98. opts = opts || {};
  99. let log = (...args) => opts.log && _console.log(...args);
  100. let warn = (...args) => _console.warn(...args);
  101. let trace = (...args) => (opts.log || opts.trace) && warn(...args);
  102.  
  103. nt.destroy = function(o, destroy) {
  104. if (!opts.destroy && !destroy && o instanceof Object)
  105. return;
  106. log('cleaning', o);
  107. try {
  108. for (let item in o) {
  109. if (item instanceof Object)
  110. nt.destroy(item);
  111. delete o[item];
  112. }
  113. } catch (e) {
  114. log('Error in object destructor', e);
  115. }
  116. };
  117.  
  118. nt.define = function(obj, prop, val, enumerable = true) {
  119. try {
  120. Object.defineProperty(
  121. obj, prop, {
  122. get: () => val,
  123. set: v => {
  124. if (v !== val) {
  125. log(`set ${prop} of`, obj, 'to', v);
  126. nt.destroy(v);
  127. }
  128. },
  129. enumerable: enumerable
  130. }
  131. );
  132. } catch (err) {
  133. _console.log(`Unable to redefine "${prop}" in `, obj, err);
  134. }
  135. };
  136. nt.proxy = function(obj, missingFuncParentName, missingFuncValue) {
  137. return new Proxy(
  138. obj, {
  139. get: (t, p) => {
  140. if (p in t)
  141. return t[p];
  142. if (typeof p === 'symbol') {
  143. t[p] = void 0;
  144. _console.warn('Missing', p, missingFuncParentName ? `in ${missingFuncParentName}` : '', '>>', t[p]);
  145. return t[p];
  146. }
  147. if (missingFuncParentName) {
  148. t[p] = nt.func(missingFuncValue, `${missingFuncParentName}.${p}`);
  149. return t[p];
  150. }
  151. _console.warn(`Missing ${p} in`, t);
  152. },
  153. set: (t, p, v) => {
  154. if (v !== t[p]) {
  155. log(`set ${p} of`, t, 'to', v);
  156. nt.destroy(v);
  157. }
  158. return true;
  159. }
  160. }
  161. );
  162. };
  163. nt.func = (val, name = '', force_log = false) => nt.proxy((...args) => {
  164. (force_log ? warn : trace)(`call ${name}(`, ...args,`) return`, val);
  165. return val;
  166. });
  167. }
  168.  
  169. // Debug function, lists all unusual window properties
  170. function getStrangeObjectsList() {
  171. _console.warn('Strangers list start');
  172. let _toString = Function.prototype.call.bind(Function.prototype.toString);
  173. let _skip = 'frames/self/window/webkitStorageInfo'.split('/');
  174. for (let n in win) {
  175. let val = win[n];
  176. if (val && !_skip.includes(n) && (win !== window && val !== window[n] || win === window) &&
  177. (!(val instanceof Function) ||
  178. val instanceof Function &&
  179. !(new RegExp (`^function\\s(${n})?\\(\\)[\\s\\r\\n]*\\{[\\s\\r\\n]*\\[native\\scode\\][\\s\\r\\n]*\\}$`)).test(_toString(val))))
  180. _console.log(`${n} =`, val);
  181. }
  182. _console.warn('Strangers list end');
  183. }
  184.  
  185. // Creates and return protected style (unless protection is manually disabled).
  186. // Protected style will re-add itself on removal and remaind enabled on attempt to disable it.
  187. function createStyle(rules, props, skip_protect) {
  188. props = props || {};
  189. props.type = 'text/css';
  190.  
  191. function _protect(style) {
  192. if (skip_protect)
  193. return;
  194.  
  195. Object.defineProperty(style, 'sheet', {
  196. value: null,
  197. enumerable: true
  198. });
  199. Object.defineProperty(style, 'disabled', {
  200. get: () => true, //pretend to be disabled
  201. set: () => undefined,
  202. enumerable: true
  203. });
  204. (new MutationObserver(
  205. (ms) => _removeChild(ms[0].target)
  206. )).observe(style, { childList: true });
  207. }
  208.  
  209.  
  210. function _create() {
  211. let style = _appendChild(_createElement('style'));
  212. Object.assign(style, props);
  213.  
  214. function insertRules(rule) {
  215. if (rule.forEach)
  216. rule.forEach(insertRules);
  217. else try {
  218. style.sheet.insertRule(rule, 0);
  219. } catch (e) {
  220. _console.error(e);
  221. }
  222. }
  223.  
  224. insertRules(rules);
  225. _protect(style);
  226.  
  227. return style;
  228. }
  229.  
  230. let style = _create();
  231. if (skip_protect)
  232. return style;
  233.  
  234. (new MutationObserver(
  235. function(ms) {
  236. let m, node;
  237. let createStyleInANewThread = resolve => setTimeout(
  238. resolve => resolve(_create()),
  239. 0, resolve
  240. );
  241. let setStyle = st => void(style = st);
  242. for (m of ms) for (node of m.removedNodes)
  243. if (node === style)
  244. (new Promise(createStyleInANewThread))
  245. .then(setStyle);
  246. }
  247. )).observe(_de, { childList: true });
  248.  
  249. return style;
  250. }
  251.  
  252. // Fake objects of advertisement networks to break their workflow
  253. scriptLander(() => {
  254. let nt = new nullTools();
  255. // Popular adblock detector
  256. if (!('fuckAdBlock' in win)) {
  257. let FuckAdBlock = function(options) {
  258. let self = this;
  259. self._options = {
  260. checkOnLoad: false,
  261. resetOnEnd: false,
  262. checking: false
  263. };
  264. self.setOption = function(opt, val) {
  265. if (val)
  266. self._options[opt] = val;
  267. else
  268. Object.assign(self._options, opt);
  269. };
  270. if (options)
  271. self.setOption(options);
  272.  
  273. self._var = { event: {} };
  274. self.clearEvent = function() {
  275. self._var.event.detected = [];
  276. self._var.event.notDetected = [];
  277. };
  278. self.clearEvent();
  279.  
  280. self.on = function(detected, fun) {
  281. self._var.event[detected?'detected':'notDetected'].push(fun);
  282. return self;
  283. };
  284. self.onDetected = function(cb) {
  285. return self.on(true, cb);
  286. };
  287. self.onNotDetected = function(cb) {
  288. return self.on(false, cb);
  289. };
  290. self.emitEvent = function() {
  291. for (let fun of self._var.event.notDetected)
  292. fun();
  293. if (self._options.resetOnEnd)
  294. self.clearEvent();
  295. return self;
  296. };
  297. self._creatBait = () => null;
  298. self._destroyBait = () => null;
  299. self._checkBait = function() {
  300. setTimeout((() => self.emitEvent()), 1);
  301. };
  302. self.check = function() {
  303. self._checkBait();
  304. return true;
  305. };
  306.  
  307. let callback = function() {
  308. if (self._options.checkOnLoad)
  309. setTimeout(self.check, 1);
  310. };
  311. window.addEventListener('load', callback, false);
  312. };
  313. nt.define(win, 'FuckAdBlock', FuckAdBlock);
  314. nt.define(win, 'fuckAdBlock', new FuckAdBlock({
  315. checkOnLoad: true,
  316. resetOnEnd: true
  317. }));
  318. }
  319.  
  320. // CoinHive miner stub. Continuous 100% CPU load can easily kill some CPU with overheat.
  321. if (!('CoinHive' in win))
  322. if (location.hostname !== 'cnhv.co') {
  323. // CoinHive stub for cases when it doesn't affect site functionality
  324. let CoinHiveConstructor = function() {
  325. _console.warn('Fake CoinHive miner created.');
  326. this.setThrottle = nt.func(null);
  327. this.start = nt.func(null);
  328. this.on = nt.func(null);
  329. this.getHashesPerSecond = nt.func(Infinity);
  330. this.getTotalHashes = nt.func(Infinity);
  331. this.getAcceptedHashes = nt.func(Infinity);
  332. };
  333. let CoinHiveStub = nt.proxy({
  334. Anonymous: CoinHiveConstructor,
  335. User: CoinHiveConstructor,
  336. Token: CoinHiveConstructor,
  337. JobThread: nt.func(null),
  338. Res: nt.func(null),
  339. IF_EXCLUSIVE_TAB: false,
  340. CONFIG: nt.proxy({})
  341. });
  342. nt.define(win, 'CoinHive', CoinHiveStub);
  343. } else {
  344. // CoinHive wrapper to fool sites which expect it to actually work and return results
  345. let CoinHiveObject;
  346. Object.defineProperty(win, 'CoinHive', {
  347. set: function(obj) {
  348. if ('Token' in obj) {
  349. _console.log('[CoinHive] Token wrapper applied.');
  350. let _Token = obj.Token.bind(obj);
  351. obj.Token = function(siteKey, goal, params) {
  352. let _goal = goal;
  353. goal = goal > 256 ? 256 : goal;
  354. _console.log(`[CoinHive] Original goal: ${_goal}, new smaller goal ${goal}.`);
  355. _console.log(`With smaller goals server may return 'invalid_goal' error and stop working.`);
  356. let miner = _Token(siteKey, goal, params);
  357. miner.setThrottle(0.99);
  358. miner.setThrottle = () => null;
  359. let _start = miner.start.bind(miner);
  360. miner.start = function() {
  361. let res = _start(window.CoinHive.FORCE_EXCLUSIVE_TAB);
  362. return res;
  363. };
  364. let _getTotalHashes = miner.getTotalHashes;
  365. miner.getTotalHashes = function() {
  366. return Math.trunc(_getTotalHashes.call(this) / goal * _goal);
  367. };
  368. let __emit = miner._emit;
  369. miner._emit = function(state, props) {
  370. let _self = this;
  371. _console.log('[CoinHive] state:', state, props);
  372. if (state === 'job')
  373. setTimeout(() => {
  374. _self.stop();
  375. _self._emit('accepted', { hashes: goal });
  376. }, 1000);
  377. return __emit.apply(_self, arguments);
  378. };
  379. let _on = miner.on.bind(miner);
  380. miner.on = function(type, callback) {
  381. if (type === 'accepted') {
  382. _console.log('[CoinHive] "accepted" callback wrapper applied.');
  383. let _callback = callback;
  384. callback = function(params) {
  385. _console.log('[CoinHive] "accepted" callback is called, imitating original goal being reached.');
  386. params.hashes = _goal;
  387. return _callback.apply(this, arguments);
  388. };
  389. miner.stop();
  390. }
  391. return _on(type, callback);
  392. };
  393. return miner;
  394. };
  395. }
  396. CoinHiveObject = obj;
  397. },
  398. get: () => CoinHiveObject
  399. });
  400. }
  401.  
  402. // VideoJS player wrapper
  403. VideoJS: {
  404. let _videojs = win.videojs || void 0;
  405. Object.defineProperty(win, 'videojs', {
  406. get: () => _videojs,
  407. set: f => {
  408. if (f === _videojs)
  409. return true;
  410. _console.log('videojs =', f);
  411. _videojs = new Proxy(f, {
  412. apply: (tgt, ths, args) => {
  413. _console.log('videojs(', ...args, ')');
  414. let params = args[1];
  415. if (params) {
  416. if (params.hasAd)
  417. params.hasAd = false;
  418. if (params.autoplay)
  419. params.autoplay = false;
  420. if (params.plugins && params.plugins.vastClient)
  421. delete params.plugins.vastClient;
  422. }
  423. let res = tgt.apply(ths, args);
  424. if (res && res.seed)
  425. res.seed = () => null;
  426. _console.log('player = ', res);
  427. return res;
  428. }
  429. });
  430. }
  431. });
  432. }
  433.  
  434. // piguiqproxy-like script loaded from random RU domains
  435. /* potentially not required anymore
  436. let fab_application_define = nt.func(null, 'fab_application.define', true);
  437. fab_application_define.amd = nt.func(null, 'fab_application.define.amd');
  438. let fab_application = {
  439. requirejs: nt.func(null, 'fab_application.requirejs'),
  440. require: nt.func(null, 'fab_application.require'),
  441. define: nt.proxy(fab_application_define)
  442. };
  443. nt.define(win, 'fab_application', nt.proxy(fab_application));
  444. */
  445.  
  446. // Set a little trap for BodyClick ads
  447. Object.defineProperty(win, '__BC_domain', {
  448. set: () => { throw 'BodyClick trap' }
  449. });
  450.  
  451. // Yandex API (ADBTools, Metrika)
  452. let hostname = location.hostname;
  453. if (// Thank you, Greasemonkey, now I have to check for this. -_-
  454. location.protocol === 'about:' ||
  455. // Google likes to define odd global variables like Ya
  456. hostname.startsWith('google.') || hostname.includes('.google.') ||
  457. // Also, Yandex uses their Ya object for a lot of things on their pages and
  458. // wrapping it may cause problems. It's better to skip it in some cases.
  459. ((hostname.startsWith('yandex.') || hostname.includes('.yandex.')) &&
  460. /^\/((yand)?search|images)/i.test(location.pathname) && !hostname.startsWith('news.')) ||
  461. // Also skip on these following sites since they use
  462. // code minification which generated global Ya variable.
  463. hostname.endsWith('chatango.com') || hostname.endsWith('github.io') ||
  464. hostname.endsWith('grimtools.com') || hostname.endsWith('poeplanner.com'))
  465. return;
  466.  
  467. let YaProps = new Set();
  468. function setObfuscatedProperty(Ya, rootProp, name) {
  469. if (YaProps.has(rootProp))
  470. return;
  471. _console.warn(`Ya.${rootProp} = Ya.${name}`);
  472. nt.define(Ya, rootProp, Ya[name]);
  473. YaProps.add(rootProp);
  474. }
  475. function onObfuscatedProperty (Ya, rootProp, obj) {
  476. if ('AdvManager' in obj || 'isAllowedRepeatAds' in obj) {
  477. setObfuscatedProperty(Ya, rootProp, 'Context');
  478. return Ya.Context;
  479. }
  480. return new Proxy(obj, {
  481. set: (tgt, prop, val) => {
  482. if (prop === 'AdvManager' || prop === 'isAllowedRepeatAds') {
  483. setObfuscatedProperty(Ya, rootProp, 'Context');
  484. return true;
  485. }
  486. if ('create' in obj && 'createAdaptive' in obj || 'createScroll' in obj) {
  487. setObfuscatedProperty(Ya, rootProp, 'adfoxCode');
  488. return true;
  489. }
  490. tgt[prop] = val;
  491. return true;
  492. },
  493. get: (tgt, prop) => {
  494. if (prop === 'AdvManager' && !(prop in tgt)) {
  495. _console.warn(`Injected missing ${prop} in Ya.${rootProp}.`);
  496. tgt[prop] = Ya.Context[prop];
  497. }
  498. return tgt[prop];
  499. }
  500. });
  501. }
  502. let Rum = {};
  503. [
  504. '__timeMarks', '_timeMarks', '__deltaMarks', '_deltaMarks',
  505. '__defRes', '_defRes', '__defTimes', '_defTimes', '_vars',
  506. 'commonVars'
  507. ].forEach(name => void(Rum[name] = []));
  508. [
  509. 'getSettings', 'getVarsList'
  510. ].forEach(name => void(Rum[name] = nt.func([], `Ya.Rum.${name}`)));
  511. [
  512. ['ajaxStart', 0], ['ajaxComplete', 0],
  513. ['enabled', true], ['_tti', null],
  514. ['vsChanged', false], ['vsStart', 'visible']
  515. ].forEach(([prop, val]) => void(Rum[prop] = val));
  516. Rum = nt.proxy(Rum, 'Ya.Rum', null);
  517. let Ya = new Proxy({}, {
  518. set: function(tgt, prop, val) {
  519. if (val === tgt[prop])
  520. return true;
  521. if (prop === 'Rum') {
  522. nt.define(tgt, prop, Rum);
  523. YaProps.add(prop);
  524. Object.assign(val, Rum);
  525. }
  526. if (YaProps.has(prop)) {
  527. _console.log(`Ya.${prop} \u2260`, val);
  528. return true;
  529. }
  530. if (val instanceof Object && prop !== '__inline_params__')
  531. val = onObfuscatedProperty(Ya, prop, val);
  532. tgt[prop] = val;
  533. _console.log(`Ya.${prop} =`, val);
  534. return true;
  535. },
  536. get: (tgt, prop) => tgt[prop]
  537. });
  538. let callWithParams = function(f) {
  539. f.call(this, Ya.__inline_params__ || {});
  540. Ya.__inline_params__ = null;
  541. };
  542. nt.define(Ya, 'callWithParams', callWithParams);
  543. nt.define(Ya, 'PerfCounters', nt.proxy({
  544. __cacheEvents: []
  545. }, 'Ya.PerfCounters', null));
  546. nt.define(Ya, '__isSent', true);
  547. nt.define(Ya, 'confirmUrl', '');
  548. nt.define(Ya, 'Direct', nt.proxy({}, 'Ya.Direct', null));
  549. nt.define(Ya, 'mediaCode', nt.proxy({
  550. create: function() {
  551. if (inIFrame) {
  552. _console.log('Removed body of ad-frame.');
  553. _document.documentElement.removeChild(_document.body);
  554. }
  555. }
  556. }, 'Ya.mediaCode', null));
  557. let extra = nt.proxy({
  558. extra: nt.proxy({ match: 0, confirm: '', src: '' }),
  559. id: 0, percent: 100, threshold: 1
  560. });
  561. nt.define(Ya, '_exp', nt.proxy({
  562. id: 0, coin: 0,
  563. choose: nt.func(extra),
  564. get: (prop) => extra.hasOwnProperty(prop) ? extra[prop] : null,
  565. getId: nt.func(0),
  566. defaultVersion: extra,
  567. getExtra: nt.func(extra.extra),
  568. getDefaultExtra: nt.func(extra.extra),
  569. versions: [extra]
  570. }));
  571. nt.define(Ya, 'c', nt.func(null));
  572. nt.define(Ya, 'ADBTools', function(){
  573. this.getCurrentState = nt.func(true);
  574. return nt.proxy(this, 'Ya.ADBTools', null);
  575. });
  576. nt.define(Ya, 'AdDetector', nt.proxy({}, 'Ya.AdDetector', null));
  577. let adfoxCode = {
  578. forcedDirectLoadingExp: nt.proxy({ isLoadingTurnedOn: false, isExp: false }),
  579. isLoadingTurnedOn: false,
  580. xhrExperiment: nt.proxy({ isXhr: true, isControl: true }),
  581. pr: 0, _: []
  582. };
  583. [
  584. 'clearSession', 'create', 'createAdaptive', 'createScroll',
  585. 'destroy', 'moduleLoad', 'reload', 'setModule'
  586. ].forEach(name => void(adfoxCode[name] = nt.func(null, `Ya.adfoxCode.${name}`)));
  587. nt.define(Ya, 'adfoxCode', nt.proxy(adfoxCode, 'Ya.adfoxCode', null));
  588. let managerForAdfox = {
  589. loaderVersion: 1,
  590. isCurrrencyExp: true,
  591. isReady: nt.func(true, 'Ya.headerBidding.managerForAdfox.isReady'),
  592. getRequestTimeout: nt.func(300 + Math.floor(Math.random()*100), 'Ya.headerBidding.managerForAdfox.getRequestTimeout')
  593. };
  594. let headerBidding = nt.proxy({
  595. setSettings: opts => {
  596. if (!(opts && opts.adUnits))
  597. return null;
  598. let ids = [];
  599. for (let unit of opts.adUnits)
  600. ids.push(unit.code);
  601. createStyle(`#${ids.join(', #')} { display: none !important }`);
  602. },
  603. managerForAdfox: nt.proxy(managerForAdfox, 'Ya.headerBidding.managerForAdfox', null)
  604. });
  605. nt.define(Ya, 'headerBidding', headerBidding);
  606.  
  607. let AdvManager = function() {
  608. this.render = function(o) {
  609. if (!o.renderTo)
  610. return;
  611. let placeholder = _document.getElementById(o.renderTo);
  612. if (!placeholder)
  613. return _console.warn('Ya.AdvManager.render call w/o placeholder', o);
  614. let parent = placeholder.parentNode;
  615. placeholder.style = 'display:none!important';
  616. parent.style = (parent.getAttribute('style')||'') + 'height:auto!important';
  617. // fix for Yandex TV pages
  618. if (location.hostname.startsWith('tv.yandex.')) {
  619. let sibling = placeholder.previousSibling;
  620. if (sibling && sibling.classList && sibling.classList.contains('tv-spin'))
  621. sibling.style.display = 'none';
  622. }
  623. };
  624. this.constructor = Object;
  625. return nt.proxy(this, 'Ya.AdvManager', null);
  626. };
  627. nt.define(Ya, 'Context', nt.proxy({
  628. __longExperiment: null,
  629. _callbacks: nt.proxy([]),
  630. _asyncModeOn: true,
  631. _init: nt.func(null),
  632. isAllowedRepeatAds: nt.func(null),
  633. isNewLoader: nt.func(false),
  634. AdvManager: new AdvManager(),
  635. AdvManagerStatic: nt.func({})
  636. }));
  637. let Metrika = function Metrika(x) {
  638. this._ecommerce = '';
  639. if (x && 'id' in x)
  640. this.id = x.id;
  641. else
  642. this.id = 0;
  643. return nt.proxy(this, 'Ya.Metrika', null);
  644. };
  645. Metrika.counters = () => Ya._metrika.counters;
  646. nt.define(Ya, 'Metrika', Metrika);
  647. nt.define(Ya, 'Metrika2', Metrika);
  648. let counter = new Ya.Metrika();
  649. nt.define(Ya, '_metrika', nt.proxy({
  650. counter: counter,
  651. counters: [counter],
  652. hitParam: {},
  653. counterNum: 0,
  654. hitId: 0,
  655. v: 1,
  656. i: 0,
  657. _globalMetrikaHitId: 0,
  658. getCounters: null,
  659. dataLayer: null,
  660. f1: null
  661. }));
  662. nt.define(Ya, '_globalMetrikaHitId', 0);
  663. counter = {};
  664. [
  665. 'stringifyParams','_getVars',
  666. 'getUid','getUrl','getHash'
  667. ].forEach(name => void(counter[name] = nt.func('', `Ya.counter.${name}`)));
  668. nt.define(Ya, 'counter', nt.proxy(counter, 'Ya.counter', null));
  669. nt.define(Ya, 'jserrors', []);
  670. nt.define(Ya, 'onerror', nt.func(null, 'Ya.onerror'));
  671. if (win.Ya) {
  672. _console.log('Found existing Ya object:', win.Ya);
  673. for (let prop in win.Ya)
  674. Ya[prop] = win.Ya[prop];
  675. }
  676. for (let prop in Ya)
  677. if (prop !== '__inline_params__')
  678. YaProps.add(prop);
  679. nt.define(win, 'Ya', Ya);
  680. // Yandex.Metrika callbacks
  681. let yandex_metrika_callbacks = [];
  682. _document.addEventListener(
  683. 'DOMContentLoaded', () => {
  684. yandex_metrika_callbacks.forEach((f) => f && f.call(window));
  685. yandex_metrika_callbacks.length = 0;
  686. yandex_metrika_callbacks.push = (f) => setTimeout(f, 0);
  687. }, false
  688. );
  689. nt.define(win, 'yandex_metrika_callbacks', yandex_metrika_callbacks);
  690. }, nullTools, createStyle);
  691.  
  692. if (!isFirefox) {
  693. // scripts for non-Firefox browsers
  694. // https://gf.qytechs.cn/scripts/14720-it-s-not-important
  695. unimptt: {
  696. // BigInt were implemented in Chrome 67 which also support
  697. // proper user styles and doesn't need this fix anymore.
  698. if ((isChrome || isOpera) && 'BigInt' in win)
  699. break unimptt;
  700.  
  701. let imptt = /((display|(margin|padding)(-top|-bottom)?)\s*:[^;!]*)!\s*important/ig,
  702. ret_b = (a,b) => b,
  703. _toLowerCase = String.prototype.toLowerCase,
  704. protectedNodes = new WeakSet(),
  705. log = false;
  706.  
  707. let logger = function() {
  708. if (log)
  709. _console.log('Some page elements became a bit less important.');
  710. log = false;
  711. };
  712.  
  713. let unimportanter = function(node) {
  714. let style = (node.nodeType === _Node.ELEMENT_NODE) ?
  715. _getAttribute(node, 'style') : null;
  716.  
  717. if (!style || !imptt.test(style) || node.style.display === 'none' ||
  718. (node.src && node.src.startsWith('chrome-extension:'))) // Web of Trust IFRAME and similar
  719. return false; // get out if we have nothing to do here
  720.  
  721. protectedNodes.add(node);
  722. _setAttribute(node, 'style', style.replace(imptt, ret_b));
  723. log = true;
  724. };
  725.  
  726. (new MutationObserver(
  727. function(mutations) {
  728. setTimeout(
  729. function(ms) {
  730. let m, node;
  731. for (m of ms) for (node of m.addedNodes)
  732. unimportanter(node);
  733. logger();
  734. }, 0, mutations
  735. );
  736. }
  737. )).observe(_document, {
  738. childList : true,
  739. subtree : true
  740. });
  741.  
  742. _Element.setAttribute = function setAttribute(name, value) {
  743. '[native code]';
  744. let replaced = value;
  745. if (name && _toLowerCase.call(name) === 'style' && protectedNodes.has(this))
  746. replaced = value.replace(imptt, ret_b);
  747. log = (replaced !== value);
  748. logger();
  749. return _setAttribute(this, ...arguments);
  750. };
  751.  
  752. win.addEventListener (
  753. 'load', () => {
  754. for (let imp of _document.querySelectorAll('[style*="!"]'))
  755. unimportanter(imp);
  756. logger();
  757. }, false
  758. );
  759. }
  760.  
  761. // Naive ABP Style protector
  762. if ('ShadowRoot' in win) {
  763. let _querySelector = _Document.querySelector.bind(_document);
  764. let _removeChild = Function.prototype.call.bind(_Node.removeChild);
  765. let _appendChild = Function.prototype.call.bind(_Node.appendChild);
  766. let createShadow = () => _createElement('shadow');
  767. // Prevent adding fake content entry point
  768. _Node.appendChild = function appendChild(child) {
  769. if (this instanceof ShadowRoot &&
  770. child instanceof HTMLContentElement)
  771. return _appendChild(this, createShadow());
  772. return _appendChild(this, ...arguments);
  773. };
  774. {
  775. let _shadowSelector = Function.prototype.call.bind(ShadowRoot.prototype.querySelector);
  776. let _innerHTML = Object.getOwnPropertyDescriptor(ShadowRoot.prototype, 'innerHTML');
  777. let _parentNode = Object.getOwnPropertyDescriptor(_Node, 'parentNode');
  778. if (_innerHTML && _parentNode) {
  779. let _set = Function.prototype.call.bind(_innerHTML.set);
  780. let _getParent = Function.prototype.call.bind(_parentNode.get);
  781. _innerHTML.configurable = false;
  782. _innerHTML.set = function() {
  783. _set(this, ...arguments);
  784. let content = _shadowSelector(this, 'content');
  785. if (content) {
  786. let parent = _getParent(content);
  787. _removeChild(parent, content);
  788. _appendChild(parent, createShadow());
  789. }
  790. };
  791. }
  792. Object.defineProperty(ShadowRoot.prototype, 'innerHTML', _innerHTML);
  793. }
  794. // Locate and apply extra protection to a style on top of what ABP does
  795. let style;
  796. (new Promise(
  797. function(resolve, reject) {
  798. let getStyle = () => _querySelector('::shadow style');
  799. style = getStyle();
  800. if (style)
  801. return resolve(style);
  802. let intv = setInterval(
  803. function() {
  804. style = getStyle();
  805. if (!style)
  806. return;
  807. intv = clearInterval(intv);
  808. return resolve(style);
  809. }, 0
  810. );
  811. _document.addEventListener(
  812. 'DOMContentLoaded', () => {
  813. if (intv)
  814. clearInterval(intv);
  815. style = getStyle();
  816. return style ? resolve(style) : reject();
  817. }, false
  818. );
  819. }
  820. )).then(
  821. function(style) {
  822. let emptyArr = [],
  823. nullStr = {
  824. get: () => '',
  825. set: () => undefined
  826. };
  827. let shadow = style.parentNode;
  828. Object.defineProperties(shadow, {
  829. childElementCount: { value: 0 },
  830. styleSheets: { value: emptyArr },
  831. firstChild: { value: null },
  832. firstElementChild: { value: null },
  833. lastChild: { value: null },
  834. lastElementChild: { value: null },
  835. childNodes: { value: emptyArr },
  836. children: { value: emptyArr },
  837. innerHTML: { value: nullStr },
  838. });
  839. Object.defineProperties(style, {
  840. innerHTML: { value: nullStr },
  841. textContent: { value: nullStr },
  842. ownerDocument: { value: null },
  843. parentNode: {value: null },
  844. previousElementSibling: { value: null },
  845. previousSibling: { value: null },
  846. disabled: { get: () => true, set: () => null }
  847. });
  848. Object.defineProperties(style.sheet, {
  849. deleteRule: { value: () => null },
  850. disabled: { get: () => true, set: () => null },
  851. cssRules: { value: emptyArr },
  852. rules: { value: emptyArr }
  853. });
  854. }
  855. ).catch(()=>null);
  856. _Node.removeChild = function removeChild(child) {
  857. if (child === style)
  858. return;
  859. return _removeChild(this, ...arguments);
  860. };
  861. }
  862. }
  863.  
  864. if (/^https?:\/\/(mail\.yandex\.|music\.yandex\.|news\.yandex\.|(www\.)?yandex\.[^/]+\/(yand)?search[/?])/i.test(win.location.href) ||
  865. /^https?:\/\/tv\.yandex\./i.test(win.location.href)) {
  866. // https://gf.qytechs.cn/en/scripts/809-no-yandex-ads
  867. let yadWord = /Яндекс.Директ/i,
  868. adWords = /Реклама|Ad/i;
  869. let _querySelector = _document.querySelector.bind(_document),
  870. _querySelectorAll = _document.querySelectorAll.bind(_document),
  871. _getAttribute = Function.prototype.call.bind(_Element.getAttribute),
  872. _setAttribute = Function.prototype.call.bind(_Element.setAttribute);
  873. // Function to attach an observer to monitor dynamic changes on the page
  874. let pageUpdateObserver = (func, obj, params) => {
  875. if (obj)
  876. (new MutationObserver(func))
  877. .observe(obj, (params || { childList:true, subtree:true }));
  878. };
  879. // Short name for parentNode.removeChild and setAttribute style to display:none
  880. let remove = (node) => {
  881. if (!node || !node.parentNode)
  882. return false;
  883. _console.log('Removed node.');
  884. node.parentNode.removeChild(node);
  885. };
  886. let hide = (node) => {
  887. if (!node)
  888. return false;
  889. _console.log('Hid node.');
  890. _setAttribute(node, 'style', 'display:none!important');
  891. };
  892. // Yandex search ads in Google Chrome
  893. if ('attachShadow' in _Element) {
  894. let _attachShadow = _Element.attachShadow;
  895. _Element.attachShadow = function() {
  896. let node = this,
  897. root = _attachShadow.apply(node, arguments);
  898. pageUpdateObserver(
  899. (ms) => {
  900. for (let m of ms) if (m.addedNodes.length)
  901. if (adWords.test(root.textContent))
  902. remove(node.closest('.serp-item'));
  903. }, root
  904. );
  905. return root;
  906. };
  907. }
  908. // Yandex Mail ads
  909. if (location.hostname.startsWith('mail.')) {
  910. let nt = new nullTools();
  911. let wrap = vl => {
  912. if (!vl)
  913. return vl;
  914. _console.log('Daria =', vl);
  915. nt.define(vl, 'AdBlock', nt.proxy({
  916. detect: nt.func(new Promise(() => null), 'Daria.AdBlock.detect'),
  917. enabled: false
  918. }));
  919. nt.define(vl, 'AdvPresenter', nt.proxy({
  920. _config: nt.proxy({
  921. banner: false,
  922. done: false,
  923. line: true
  924. })
  925. }));
  926. if (vl.Config) {
  927. delete vl.Config.adBlockDetector;
  928. delete vl.Config['adv-url'];
  929. delete vl.Config.cryprox;
  930. if (vl.Config.features) {
  931. delete vl.Config.features.web_adloader_with_cookie_cache;
  932. delete vl.Config.features.web_ads;
  933. delete vl.Config.features.web_ads_mute;
  934. }
  935. vl.Config.mayHaveAdv = false;
  936. }
  937. return vl;
  938. };
  939. let _Daria = wrap(win.Daria);
  940. if (_Daria)
  941. _console.log('Wrapped already existing object "Daria".');
  942. Object.defineProperty(win, 'Daria', {
  943. get: () => _Daria,
  944. set: vl => {
  945. if (vl === _Daria)
  946. return;
  947. _Daria = wrap(vl);
  948. }
  949. });
  950. }
  951. // prevent/defuse adblock detector
  952. setInterval(() => {
  953. localStorage.ic = '';
  954. localStorage._mt__data = '';
  955. }, 100);
  956. let yp_keepCookieParts = /\.(sp|ygo|ygu)\./; // ygo = city id; ygu = detect city automatically
  957. let _doc_proto = ('cookie' in _Document) ? _Document : Object.getPrototypeOf(_document);
  958. let _cookie = Object.getOwnPropertyDescriptor(_doc_proto, 'cookie');
  959. if (_cookie) {
  960. let _set_cookie = Function.prototype.call.bind(_cookie.set);
  961. _cookie.set = function(value) {
  962. if (/^(mda=|yp=|ys=|yabs-|__|bltsr=)/.test(value))
  963. // remove value, set expired
  964. if (!value.startsWith('yp=')) {
  965. value = value.replace(/^([^=]+=)[^;]+/,'$1').replace(/(expires=)[\w\s\d,]+/,'$1Thu, 01 Jan 1970 00');
  966. _console.log('expire cookie', value.match(/^[^=]+/)[0]);
  967. } else {
  968. let parts = value.split(';');
  969. let values = parts[0].split('#').filter(part => yp_keepCookieParts.test(part));
  970. if (values.length)
  971. values[0] = values[0].replace(/^yp=/, '');
  972. let res = `yp=${values.join('#')}`;
  973. _console.log(`set cookie ${res}, dropped ${parts[0].replace(res,'')}`);
  974. parts[0] = res;
  975. value = parts.join(';');
  976. }
  977. return _set_cookie(this, value);
  978. };
  979. Object.defineProperty(_doc_proto, 'cookie', _cookie);
  980. }
  981. // other ads
  982. _document.addEventListener(
  983. 'DOMContentLoaded', () => {
  984. {
  985. // Generic ads removal and fixes
  986. let node = _querySelector('.serp-header');
  987. if (node)
  988. node.style.marginTop = '0';
  989. for (node of _querySelectorAll(
  990. '.serp-adv__head + .serp-item,'+
  991. '#adbanner,'+
  992. '.serp-adv,'+
  993. '.b-spec-adv,'+
  994. 'div[class*="serp-adv__"]:not(.serp-adv__found):not(.serp-adv__displayed)'
  995. )) remove(node);
  996. }
  997. // Search ads
  998. function removeSearchAds() {
  999. for (let node of _querySelectorAll('.serp-item'))
  1000. if (_getAttribute(node, 'role') === 'complementary' ||
  1001. adWords.test((node.querySelector('.label')||{}).textContent))
  1002. hide(node);
  1003. }
  1004. // News ads
  1005. function removeNewsAds() {
  1006. let node, block, items, mask, classes,
  1007. masks = [
  1008. { class: '.ads__wrapper', regex: /[^,]*?,[^,]*?\.ads__wrapper/ },
  1009. { class: '.ads__pool', regex: /[^,]*?,[^,]*?\.ads__pool/ }
  1010. ];
  1011. for (node of _querySelectorAll('style[nonce]')) {
  1012. classes = node.innerText.replace(/\{[^}]+\}+/ig, '|').split('|');
  1013. for (block of classes) for (mask of masks)
  1014. if (block.includes(mask.class)) {
  1015. block = block.match(mask.regex)[0];
  1016. items = _querySelectorAll(block);
  1017. for (item of items)
  1018. remove(items[0]);
  1019. }
  1020. }
  1021. }
  1022. // Music ads
  1023. function removeMusicAds() {
  1024. for (let node of _querySelectorAll('.ads-block'))
  1025. remove(node);
  1026. }
  1027. // News fixes
  1028. function removePageAdsClass() {
  1029. if (_document.body.classList.contains("b-page_ads_yes")) {
  1030. _document.body.classList.remove("b-page_ads_yes");
  1031. _console.log('Page ads class removed.');
  1032. }
  1033. }
  1034. // TV fixes
  1035. function removeTVAds() {
  1036. for (let node of _querySelectorAll('div[class^="_"][data-reactid] > div'))
  1037. if (yadWord.test(node.textContent) || node.querySelector('iframe:not([src])')) {
  1038. if (node.offsetWidth) {
  1039. let pad = _document.createElement('div');
  1040. _setAttribute(pad, 'style', `width:${node.offsetWidth}px`);
  1041. node.parentNode.appendChild(pad);
  1042. }
  1043. remove(node);
  1044. }
  1045. }
  1046.  
  1047. if (location.hostname.startsWith('music.')) {
  1048. pageUpdateObserver(removeMusicAds, _querySelector('.sidebar'));
  1049. removeMusicAds();
  1050. } else if (location.hostname.startsWith('news.')) {
  1051. pageUpdateObserver(removeNewsAds, _document.body);
  1052. pageUpdateObserver(removePageAdsClass, _document.body, { attributes:true, attributesFilter:['class'] });
  1053. removeNewsAds();
  1054. removePageAdsClass();
  1055. } else if (location.hostname.startsWith('tv.')) {
  1056. pageUpdateObserver(removeTVAds, _document.body);
  1057. removeTVAds();
  1058. } else if (!location.hostname.startsWith('mail.')) {
  1059. pageUpdateObserver(removeSearchAds, _querySelector('.main__content'));
  1060. removeSearchAds();
  1061. }
  1062. }
  1063. );
  1064. }
  1065.  
  1066. // Generic Yandex Scripts
  1067. if (/^https?:\/\/([^.]+\.)*yandex\.[^/]+/i.test(win.location.href)) {
  1068. // remove banner on the start page
  1069. scriptLander(() => {
  1070. let nt = new nullTools({log: false, trace: true});
  1071. let AwapsJsonAPI_Json = function(...args) {
  1072. _console.log('>> new AwapsJsonAPI.Json(', ...args, ')');
  1073. };
  1074. [
  1075. 'setID', 'addImageContent',
  1076. 'sendCounts', 'expand', 'refreshAd'
  1077. ].forEach(name => void(AwapsJsonAPI_Json.prototype[name] = nt.func(null, `AwapsJsonAPI.Json.${name}`)));
  1078. AwapsJsonAPI_Json.prototype.checkBannerVisibility = nt.func(true, 'AwapsJsonAPI.Json.checkBannerVisibility');
  1079. AwapsJsonAPI_Json.prototype.addIframeContent = nt.proxy(function(...args) {
  1080. try {
  1081. let frame = args[1][0].parentNode;
  1082. frame.parentNode.removeChild(frame);
  1083. _console.log(`Removed banner placeholder.`);
  1084. } catch(ignore) {
  1085. _console.log(`Can't locate frame object to remove.`);
  1086. }
  1087. });
  1088. AwapsJsonAPI_Json.prototype.getHTML = nt.func('', 'AwapsJsonAPI.Json.getHTML');
  1089. AwapsJsonAPI_Json.prototype = nt.proxy(AwapsJsonAPI_Json.prototype);
  1090. AwapsJsonAPI_Json = nt.proxy(AwapsJsonAPI_Json);
  1091. if ('AwapsJsonAPI' in win) {
  1092. _console.log('Oops! AwapsJsonAPI already defined.');
  1093. let f = win.AwapsJsonAPI.Json;
  1094. win.AwapsJsonAPI.Json = AwapsJsonAPI_Json;
  1095. if (f && f.prototype)
  1096. f.prototype = AwapsJsonAPI_Json.prototype;
  1097. } else
  1098. nt.define(win, 'AwapsJsonAPI', nt.proxy({
  1099. Json: AwapsJsonAPI_Json
  1100. }));
  1101.  
  1102. let parseExport = x => {
  1103. if (!x)
  1104. return x;
  1105. // remove banner placeholder
  1106. if (x.banner && x.banner.cls) {
  1107. let _parent = `.${x.banner.cls.banner__parent}`;
  1108. _document.addEventListener('DOMContentLoaded', () => {
  1109. for (let banner of _document.querySelectorAll(_parent)) {
  1110. _setAttribute(banner, 'style', 'display:none!important');
  1111. _console.log('Hid banner placeholder.');
  1112. }
  1113. }, false);
  1114. }
  1115.  
  1116. // remove banner data and some other stuff
  1117. delete x.banner;
  1118. delete x.consistency;
  1119. delete x['i-bannerid'];
  1120. delete x['i-counter'];
  1121. delete x['promo-curtain'];
  1122.  
  1123. // remove parts of ga-counter (complete removal break "ТВ Онлайн")
  1124. if (x['ga-counter'] && x['ga-counter'].data) {
  1125. x['ga-counter'].data.id = 0;
  1126. delete x['ga-counter'].data.ether;
  1127. delete x['ga-counter'].data.iframeSrc;
  1128. delete x['ga-counter'].data.iframeSrcEx;
  1129. }
  1130.  
  1131. return x;
  1132. };
  1133. // Yandex banner on main page and some other things
  1134. let _home = win.home,
  1135. _home_set = !!_home;
  1136. Object.defineProperty(win, 'home', {
  1137. get: () => _home,
  1138. set: vl => {
  1139. if (!_home_set && vl === _home)
  1140. return;
  1141. _home_set = false;
  1142. _console.log('home =', vl);
  1143. let _home_export = parseExport(vl.export);
  1144. Object.defineProperty(vl, 'export', {
  1145. get: () => _home_export,
  1146. set: vl => {
  1147. _home_export = parseExport(vl);
  1148. }
  1149. });
  1150. _home = vl;
  1151. }
  1152. });
  1153. // adblock circumvention on some Yandex domains (weather in particular)
  1154. nt.define(win, 'Raven', nt.proxy({
  1155. captureMessage: nt.func(null, 'Raven.captureMessage'),
  1156. config: nt.func({
  1157. install: nt.func(null, 'Raven.config().install')
  1158. }, 'Raven.config')
  1159. }));
  1160. }, nullTools, 'let _setAttribute = Function.prototype.call.bind(_Element.setAttribute)');
  1161.  
  1162. if ('attachShadow' in _Element) {
  1163. let fakeRoot = () => ({
  1164. firstChild: null,
  1165. appendChild: () => null,
  1166. querySelector: () => null,
  1167. querySelectorAll: () => null
  1168. });
  1169. _Element.createShadowRoot = fakeRoot;
  1170. let shadows = new WeakMap();
  1171. let _attachShadow = Object.getOwnPropertyDescriptor(_Element, 'attachShadow');
  1172. _attachShadow.value = function() {
  1173. return shadows.set(this, fakeRoot()).get(this);
  1174. };
  1175. Object.defineProperty(_Element, 'attachShadow', _attachShadow);
  1176. let _shadowRoot = Object.getOwnPropertyDescriptor(_Element, 'shadowRoot');
  1177. _shadowRoot.set = () => null;
  1178. _shadowRoot.get = function() {
  1179. return shadows.has(this) ? shadows.get(this) : void 0;
  1180. };
  1181. Object.defineProperty(_Element, 'shadowRoot', _shadowRoot);
  1182. }
  1183.  
  1184. // Disable banner styleSheet (on main page)
  1185. document.addEventListener('DOMContentLoaded', () => {
  1186. for (let sheet of document.styleSheets)
  1187. try {
  1188. for (let rule of sheet.cssRules)
  1189. if (rule.cssText.includes(' 728px 90px')) {
  1190. rule.parentStyleSheet.disabled = true;
  1191. _console.log('Disabled banner styleSheet:', rule.parentStyleSheet);
  1192. }
  1193. } catch(ignore) {}
  1194. }, false);
  1195.  
  1196. // Partially based on https://gf.qytechs.cn/en/scripts/22737-remove-yandex-redirect
  1197. let selectors = (
  1198. 'A[onmousedown*="/jsredir"],'+
  1199. 'A[data-vdir-href],'+
  1200. 'A[data-counter]'
  1201. );
  1202. let removeTrackingAttributes = function(link) {
  1203. link.removeAttribute('onmousedown');
  1204. if (link.hasAttribute('data-vdir-href')) {
  1205. link.removeAttribute('data-vdir-href');
  1206. link.removeAttribute('data-orig-href');
  1207. }
  1208. if (link.hasAttribute('data-counter')) {
  1209. link.removeAttribute('data-counter');
  1210. link.removeAttribute('data-bem');
  1211. }
  1212. };
  1213. let removeTracking = function(scope) {
  1214. if (scope instanceof Element)
  1215. for (let link of scope.querySelectorAll(selectors))
  1216. removeTrackingAttributes(link);
  1217. };
  1218. _document.addEventListener('DOMContentLoaded', (e) => removeTracking(e.target));
  1219. (new MutationObserver(
  1220. function(ms) {
  1221. let m, node;
  1222. for (m of ms) for (node of m.addedNodes)
  1223. if (node instanceof HTMLAnchorElement && node.matches(selectors))
  1224. removeTrackingAttributes(node);
  1225. else
  1226. removeTracking(node);
  1227. }
  1228. )).observe(_de, { childList: true, subtree: true });
  1229. }
  1230.  
  1231. // https://gf.qytechs.cn/en/scripts/21937-moonwalk-hdgo-kodik-fix v0.8 (adapted)
  1232. _document.addEventListener(
  1233. 'DOMContentLoaded', function() {
  1234. let log = name => _console.log(`Player FIX: Detected ${name} player in ${location.href}`);
  1235. function removeVast (data) {
  1236. if (data && (data.vast || data.reserve_vast || data.vast_button)) {
  1237. _console.log('Removed:\ndata.vast', data.vast, '\ndata.reserve_vast', data.reserve_vast, '\ndata.vast_button', data.vast_button);
  1238. delete data.vast;
  1239. delete data.reserve_vast;
  1240. delete data.vast_button;
  1241. if (data.chain) {
  1242. let need = [],
  1243. drop = [],
  1244. links = data.chain.split('.');
  1245. for (let link of links)
  1246. if (!/^vast_|_vast_|_vast$/.test(link))
  1247. need.push(link);
  1248. else
  1249. drop.push(link);
  1250. _console.log('Dropped from the chain:', ...drop);
  1251. data.chain = need.join('.');
  1252. }
  1253. }
  1254. return data;
  1255. }
  1256. if (win.video_balancer !== void 0 && win.event_callback !== void 0) {
  1257. log('Moonwalk');
  1258. if (video_balancer.adv_loader)
  1259. removeVast(video_balancer.adv_loader.options);
  1260. if ('_mw_adb' in win)
  1261. Object.defineProperty(win, '_mw_adb', {
  1262. get: () => false,
  1263. set: () => true
  1264. });
  1265. /*} else if (win.stat_url !== undefined && win.is_html5 !== undefined && win.is_wp8 !== undefined) {
  1266. log('HDGo');
  1267. _document.body.onclick = null;
  1268. let tmp = _document.querySelector('#swtf');
  1269. if (tmp)
  1270. tmp.style.display = 'none';
  1271. if (win.banner_second !== void 0)
  1272. win.banner_second = 0;
  1273. if (win.$banner_ads !== void 0)
  1274. win.$banner_ads = false;
  1275. if (win.$new_ads !== void 0)
  1276. win.$new_ads = false;
  1277. if (win.createCookie !== void 0)
  1278. win.createCookie('popup', 'true', '999');
  1279. if (win.canRunAds !== void 0 && win.canRunAds !== true)
  1280. win.canRunAds = true;*/
  1281. } else if (win.startKodikPlayer !== void 0) {
  1282. log('Kodik');
  1283. // skip attempt to block access to HD resolutions
  1284. let chainCall = new Proxy({}, { get: () => () => chainCall });
  1285. if ($ && $.prototype && $.prototype.addClass) {
  1286. let $addClass = $.prototype.addClass;
  1287. $.prototype.addClass = function (className) {
  1288. if (className === 'blocked')
  1289. return chainCall;
  1290. return $addClass.apply(this, arguments);
  1291. };
  1292. }
  1293. // remove ad links from the metadata
  1294. let _ajax = win.$.ajax;
  1295. win.$.ajax = (params, ...args) => {
  1296. if (params.success) {
  1297. let _s = params.success;
  1298. params.success = (data, ...args) => _s(removeVast(data), ...args);
  1299. }
  1300. return _ajax(params, ...args);
  1301. }
  1302. } else if (win.getnextepisode && win.uppodEvent) {
  1303. log('Share-Serials.net');
  1304. scriptLander(
  1305. function() {
  1306. let _setInterval = win.setInterval,
  1307. _setTimeout = win.setTimeout,
  1308. _toString = Function.prototype.call.bind(Function.prototype.toString);
  1309. win.setInterval = function(func) {
  1310. if (func instanceof Function && _toString(func).includes('_delay')) {
  1311. let intv = _setInterval.call(
  1312. this, function() {
  1313. _setTimeout.call(
  1314. this, function(intv) {
  1315. clearInterval(intv);
  1316. let timer = _document.querySelector('#timer');
  1317. if (timer)
  1318. timer.click();
  1319. }, 100, intv);
  1320. func.call(this);
  1321. }, 5
  1322. );
  1323.  
  1324. return intv;
  1325. }
  1326. return _setInterval.apply(this, arguments);
  1327. };
  1328. win.setTimeout = function(func) {
  1329. if (func instanceof Function && _toString(func).includes('adv_showed'))
  1330. return _setTimeout.call(this, func, 0);
  1331. return _setTimeout.apply(this, arguments);
  1332. };
  1333. }
  1334. );
  1335. } else if ('ADC' in win) {
  1336. log('vjs-creatives plugin in');
  1337. let replacer = (obj) => {
  1338. for (let name in obj)
  1339. if (obj[name] instanceof Function)
  1340. obj[name] = () => null;
  1341. };
  1342. replacer(win.ADC);
  1343. replacer(win.currentAdSlot);
  1344. }
  1345. UberVK: {
  1346. if (!inIFrame)
  1347. break UberVK;
  1348. let oddNames = 'HD' in win &&
  1349. !Object.getOwnPropertyNames(win).every(n => !n.startsWith('_0x'));
  1350. if (!oddNames)
  1351. break UberVK;
  1352. log('UberVK');
  1353. XMLHttpRequest.prototype.open = () => {
  1354. throw 404;
  1355. };
  1356. }
  1357. }, false
  1358. );
  1359.  
  1360. // Applies wrapper function on the current page and all newly created same-origin iframes
  1361. // This is used to prevent trick which allows to get fresh page API through newly created same-origin iframes
  1362. function deepWrapAPI(wrapper) {
  1363. let wrapped = new WeakSet(),
  1364. _get_contentWindow = () => null,
  1365. log = (...args) => false && _console.log(...args);
  1366. let wrapAPI = root => {
  1367. if (!root || wrapped.has(root))
  1368. return;
  1369. wrapped.add(root);
  1370. try {
  1371. wrapper(root instanceof HTMLIFrameElement ? _get_contentWindow(root) : root);
  1372. log('Wrapped API in', (root === win) ? "main window." : root);
  1373. } catch(e) {
  1374. log('Failed to wrap API in', (root === win) ? "main window." : root, '\n', e);
  1375. }
  1376. };
  1377.  
  1378. // wrap API on contentWindow access
  1379. let _apply = Function.prototype.apply;
  1380. let _contentWindow = Object.getOwnPropertyDescriptor(HTMLIFrameElement.prototype, 'contentWindow');
  1381. _get_contentWindow = _apply.bind(_contentWindow.get);
  1382. _contentWindow.get = function() {
  1383. wrapAPI(this);
  1384. return _get_contentWindow(this);;
  1385. };
  1386. Object.defineProperty(HTMLIFrameElement.prototype, 'contentWindow', _contentWindow);
  1387.  
  1388. // wrap API on contentDocument access
  1389. let _contentDocument = Object.getOwnPropertyDescriptor(HTMLIFrameElement.prototype, 'contentDocument');
  1390. let _get_contentDocument = _apply.bind(_contentDocument.get);
  1391. _contentDocument.get = function() {
  1392. wrapAPI(this);
  1393. return _get_contentDocument(this);
  1394. };
  1395. Object.defineProperty(HTMLIFrameElement.prototype, 'contentDocument', _contentDocument);
  1396.  
  1397. // manual children objects traverser to avoid issues
  1398. // with calling querySelectorAll on wrong types of objects
  1399. let _nodeType = _apply.bind(Object.getOwnPropertyDescriptor(_Node, 'nodeType').get);
  1400. let _childNodes = _apply.bind(Object.getOwnPropertyDescriptor(_Node, 'childNodes').get);
  1401. let _ELEMENT_NODE = _Node.ELEMENT_NODE;
  1402. let _DOCUMENT_FRAGMENT_NODE = _Node.DOCUMENT_FRAGMENT_NODE
  1403. let wrapFrames = root => {
  1404. if (_nodeType(root) !== _ELEMENT_NODE && _nodeType(root) !== _DOCUMENT_FRAGMENT_NODE)
  1405. return; // only process nodes which may contain an IFRAME or be one
  1406. if (root instanceof HTMLIFrameElement) {
  1407. wrapAPI(root);
  1408. return;
  1409. }
  1410. for (let child of _childNodes(root))
  1411. wrapFrames(child);
  1412. };
  1413.  
  1414. // wrap API in a newly appended iframe objects
  1415. let _appendChild = _apply.bind(Node.prototype.appendChild);
  1416. Node.prototype.appendChild = function appendChild() {
  1417. '[native code]';
  1418. let res = _appendChild(this, arguments);
  1419. wrapFrames(arguments[0]);
  1420. return res;
  1421. };
  1422.  
  1423. // wrap API in iframe objects created with innerHTML of element on page
  1424. let _innerHTML = Object.getOwnPropertyDescriptor(_Element, 'innerHTML');
  1425. let _set_innerHTML = _apply.bind(_innerHTML.set);
  1426. _innerHTML.set = function() {
  1427. _set_innerHTML(this, arguments);
  1428. if (_document.contains(this))
  1429. wrapFrames(this);
  1430. };
  1431. Object.defineProperty(_Element, 'innerHTML', _innerHTML);
  1432.  
  1433. wrapAPI(win);
  1434. }
  1435.  
  1436. // piguiqproxy.com / zmctrack.net circumvention and onerror callback prevention
  1437. scriptLander(
  1438. () => {
  1439. // onerror callback blacklist
  1440. let masks = [],
  1441. blockAll = /(^|\.)(((a-dot-)?kinozal-tv|rutracker-org)\.appspot\.com)$/,
  1442. isBlocked = url => masks.some(mask => mask.test(url)) || blockAll.test(location.hostname);
  1443. for (let filter of [// blacklist
  1444. '/fuckadblock/', '/fuckadblock.',
  1445. '||185.87.50.147^',
  1446. '||10root25.website^', '||24video.xxx^',
  1447. '||adlabs.ru^', '||adspayformymortgage.win^', '||amgload.net^', '||aviabay.ru^',
  1448. '||bgrndi.com^', '||brokeloy.com^',
  1449. '||cdnjs-aws.ru^','||cnamerutor.ru^',
  1450. '||directadvert.ru^', '||dsn-fishki.ru^', '||docfilms.info^', '||dreadfula.ru^',
  1451. '||et-code.ru^', '||etcodes.com^',
  1452. '||franecki.net^', '||film-doma.ru^',
  1453. '||free-torrent.org^', '||free-torrent.pw^',
  1454. '||free-torrents.org^', '||free-torrents.pw^',
  1455. '||game-torrent.info^', '||gocdn.ru^',
  1456. '||hdkinoshka.com^', '||hghit.com^', '||hindcine.net^',
  1457. '||kiev.ua^', '||kinotochka.net^', '||kinott.com^', '||kinott.ru^',
  1458. '||klcheck.com^', '||kuveres.com^',
  1459. '||lepubs.com^', '||luxadv.com^', '||luxup.ru^', '||luxupcdna.com^',
  1460. '||marketgid.com^', '||mebablo.com^', '||mixadvert.com^', '||mxtads.com^',
  1461. '||nickhel.com^',
  1462. '||oconner.biz^', '||oconner.link^', '||octoclick.net^', '||octozoon.org^',
  1463. '||piguiqproxy.com^', '||pkpojhc.com^',
  1464. '||psma01.com^', '||psma02.com^', '||psma03.com^',
  1465. '||rcdn.pro^', '||recreativ.ru^', '||redtram.com^', '||regpole.com^',
  1466. '||rootmedia.ws^', '||ruttwind.com^', '||rutvind.com^',
  1467. '||skidl.ru^', '||smi2.net^', '||smcheck.org^',
  1468. '||torvind.com^', '||traffic-media.co^', '||trafmag.com^', '||trustjs.net^', '||ttarget.ru^',
  1469. '||utarget.ru^',
  1470. '||webadvert-gid.ru^', '||webadvertgid.ru^',
  1471. '||xxuhter.ru^',
  1472. '||yuiout.online^',
  1473. '||zmctrack.net^', '||zoom-film.ru^'])
  1474. masks.push(new RegExp(
  1475. filter.replace(/([\\/[\].+?(){}$])/g, '\\$1')
  1476. .replace(/\*/g, '.*?')
  1477. .replace(/\^(?!$)/g,'\\.?[^\\w%._-]')
  1478. .replace(/\^$/,'\\.?([^\\w%._-]|$)')
  1479. .replace(/^\|\|/,'^(ws|http)s?:\\/+([^/.]+\\.)*?'),
  1480. 'i'));
  1481. // main script
  1482. deepWrapAPI(root => {
  1483. let _call = root.Function.prototype.call,
  1484. _defineProperty = root.Object.defineProperty,
  1485. _getOwnPropertyDescriptor = root.Object.getOwnPropertyDescriptor;
  1486. onerror: {
  1487. // 'onerror' handler for scripts from blacklisted sources
  1488. let scriptMap = new WeakMap();
  1489. let _Reflect_apply = root.Reflect.apply,
  1490. _HTMLScriptElement = root.HTMLScriptElement,
  1491. _HTMLImageElement = root.HTMLImageElement;
  1492. let _get_tagName = _call.bind(_getOwnPropertyDescriptor(root.Element.prototype, 'tagName').get),
  1493. _get_scr_src = _call.bind(_getOwnPropertyDescriptor(_HTMLScriptElement.prototype, 'src').get),
  1494. _get_img_src = _call.bind(_getOwnPropertyDescriptor(_HTMLImageElement.prototype, 'src').get);
  1495. let _get_src = node => {
  1496. if (node instanceof _HTMLScriptElement)
  1497. return _get_scr_src(node);
  1498. if (node instanceof _HTMLImageElement)
  1499. return _get_img_src(node);
  1500. return void 0
  1501. };
  1502. let _onerror = _getOwnPropertyDescriptor(root.HTMLElement.prototype, 'onerror'),
  1503. _set_onerror = _call.bind(_onerror.set);
  1504. _onerror.get = function() {
  1505. return scriptMap.get(this) || null;
  1506. };
  1507. _onerror.set = function(callback) {
  1508. if (typeof callback !== 'function') {
  1509. scriptMap.delete(this);
  1510. _set_onerror(this, callback);
  1511. return;
  1512. }
  1513. scriptMap.set(this, callback);
  1514. _set_onerror(this, function() {
  1515. let src = _get_src(this);
  1516. if (isBlocked(src)) {
  1517. _console.warn(`Blocked "onerror" callback from ${_get_tagName(this)}: ${src}`);
  1518. return;
  1519. }
  1520. _Reflect_apply(scriptMap.get(this), this, arguments);
  1521. });
  1522. };
  1523. _defineProperty(root.HTMLElement.prototype, 'onerror', _onerror);
  1524. }
  1525. // Simplistic WebSocket wrapper for Maxthon and Firefox before v58
  1526. WSWrap: { // once again seems required in Google Chrome and similar browsers due to zmctrack.net -_-
  1527. if (true /*/Maxthon/.test(navigator.appVersion) ||
  1528. 'InstallTrigger' in win && 'StopIteration' in win*/) {
  1529. let _ws = _getOwnPropertyDescriptor(root, 'WebSocket');
  1530. if (!_ws)
  1531. break WSWrap;
  1532. _ws.value = new Proxy(_ws.value, {
  1533. construct: (ws, args) => {
  1534. if (isBlocked(args[0])) {
  1535. _console.log('Blocked WS connection:', args[0]);
  1536. return {};
  1537. }
  1538. return new ws(...args);
  1539. }
  1540. });
  1541. _defineProperty(root, 'WebSocket', _ws);
  1542. }
  1543. }
  1544. untrustedClick: {
  1545. // Block popular method to open a new window in Google Chrome by dispatching a custom click
  1546. // event on a newly created anchor with _blank target. Untrusted events must not open new windows.
  1547. let _dispatchEvent = _call.bind(root.EventTarget.prototype.dispatchEvent);
  1548. root.EventTarget.prototype.dispatchEvent = function dispatchEvent(e) {
  1549. if (!e.isTrusted && e.type === 'click' && e.constructor.name === 'MouseEvent' &&
  1550. !this.parentNode && this.tagName === 'A' && this.target[0] === '_') {
  1551. _console.log('Blocked dispatching a click event on a parentless anchor:', this);
  1552. return;
  1553. }
  1554. return _dispatchEvent(this, ...arguments);
  1555. };
  1556. }
  1557. // XHR Wrapper
  1558. let _proto = void 0;
  1559. try {
  1560. _proto = root.XMLHttpRequest.prototype;
  1561. } catch(ignore) {
  1562. return;
  1563. };
  1564. // blacklist of domains where all third-party requests are ignored
  1565. let ondomains = /(^|[/.@])oane\.ws($|[:/])/i;
  1566. // highly suspicious URLs
  1567. let suspicious = /^https?:\/\/(csp-)?([a-z0-9]{6}){1,2}\.ru\//i;
  1568. let on_get_ban = /^https?:\/\/(csp-)?([a-z0-9]{6}){1,2}\.ru\/([a-z0-9/]{40,}|[a-z0-9]{8,}|ad\/banner\/.+)$/i;
  1569. let on_post_ban = /^https?:\/\/(csp-)?([a-z0-9]{6}){1,2}\.ru\/([a-z0-9]{6,})$/i;
  1570. let yandex_direct = /^https?:\/\/(yandex(\.[a-z]{2,3}){1,2}\/((images|weather)\/[a-z0-9/_-]{40,}|j?clck\/.*)|[^.]+\.yandex\.net\/static\/main\.js(\?.*)?)$/i;
  1571. let whitelist = /^https?:\/\/yandex\.ru\/yobject$/;
  1572.  
  1573. function checkRequest(fname, method, url) {
  1574. if ((isBlocked(url) ||
  1575. ondomains.test(location.hostname) && !ondomains.test(url) ||
  1576. method === 'GET' && on_get_ban.test(url) ||
  1577. method === 'POST' && on_post_ban.test(url) ||
  1578. yandex_direct.test(url)) && !whitelist.test(url)) {
  1579. _console.log(`Blocked ${fname} ${method} request:`, url);
  1580. return true;
  1581. }
  1582. if (suspicious.test(url))
  1583. _console.warn(`Suspicious ${fname} ${method} request:`, url);
  1584. return false;
  1585. }
  1586.  
  1587. let xhrStopList = new WeakSet();
  1588. let _open = root.Function.prototype.apply.bind(_proto.open);
  1589. _proto.open = function open() {
  1590. '[native code]';
  1591. if (checkRequest('xhr', ...arguments)) {
  1592. xhrStopList.add(this);
  1593. return;
  1594. }
  1595. return _open(this, arguments);
  1596. };
  1597. ['send', 'setRequestHeader', 'getAllResponseHeaders'].forEach(
  1598. name => {
  1599. let func = _proto[name];
  1600. _proto[name] = function(...args) {
  1601. return xhrStopList.has(this) ? null : func.apply(this, args);
  1602. };
  1603. }
  1604. );
  1605. // simulate readyState === 1 for blocked requests
  1606. let _readyState = Object.getOwnPropertyDescriptor(_proto, 'readyState');
  1607. let _get_readyState = root.Function.prototype.apply.bind(_readyState.get);
  1608. _readyState.get = function() {
  1609. return xhrStopList.has(this) ? 1 : _get_readyState(this, arguments);
  1610. }
  1611. Object.defineProperty(_proto, 'readyState', _readyState);
  1612.  
  1613. let _fetch = root.Function.prototype.apply.bind(root.fetch);
  1614. root.fetch = function fetch() {
  1615. '[native code]';
  1616. let url = arguments[0];
  1617. let method = arguments[1] ? arguments[1].method : void 0;
  1618. if (arguments[0] instanceof Request) {
  1619. method = url.method;
  1620. url = url.url;
  1621. }
  1622. if (checkRequest('fetch', method, url))
  1623. return new Promise(() => null);
  1624. return _fetch(root, arguments);
  1625. };
  1626. });
  1627.  
  1628. win.stop = () => {
  1629. _console.warn('window.stop() ...y tho?');
  1630. for (let sheet of _document.styleSheets)
  1631. if (sheet.disabled) {
  1632. sheet.disabled = false;
  1633. _console.log('Re-enabled:', sheet);
  1634. }
  1635. }
  1636. }, deepWrapAPI
  1637. );
  1638.  
  1639. // === Helper functions ===
  1640.  
  1641. // function to search and remove nodes by content
  1642. // selector - standard CSS selector to define set of nodes to check
  1643. // words - regular expression to check content of the suspicious nodes
  1644. // params - object with multiple extra parameters:
  1645. // .log - display log in the console
  1646. // .hide - set display to none instead of removing from the page
  1647. // .parent - parent node to remove if content is found in the child node
  1648. // .siblings - number of simling nodes to remove (excluding text nodes)
  1649. let scRemove = (node) => node.parentNode.removeChild(node);
  1650. let scHide = function(node) {
  1651. let style = _getAttribute(node, 'style') || '',
  1652. hide = ';display:none!important;';
  1653. if (style.indexOf(hide) < 0)
  1654. _setAttribute(node, 'style', style + hide);
  1655. };
  1656.  
  1657. function scissors (selector, words, scope, params) {
  1658. let logger = (...args) => { if (params.log) _console.log(...args) };
  1659. if (!scope.contains(_document.body))
  1660. logger('[s] scope', scope);
  1661. let remFunc = (params.hide ? scHide : scRemove),
  1662. iterFunc = (params.siblings > 0 ? 'nextElementSibling' : 'previousElementSibling'),
  1663. toRemove = [],
  1664. siblings;
  1665. for (let node of scope.querySelectorAll(selector)) {
  1666. // drill up to a parent node if specified, break if not found
  1667. if (params.parent) {
  1668. let old = node;
  1669. node = node.closest(params.parent);
  1670. if (node === null || node.contains(scope)) {
  1671. logger('[s] went out of scope with', old);
  1672. continue;
  1673. }
  1674. }
  1675. logger('[s] processing', node);
  1676. if (toRemove.includes(node))
  1677. continue;
  1678. if (words.test(node.innerHTML)) {
  1679. // skip node if already marked for removal
  1680. logger('[s] marked for removal');
  1681. toRemove.push(node);
  1682. // add multiple nodes if defined more than one sibling
  1683. siblings = Math.abs(params.siblings) || 0;
  1684. while (siblings) {
  1685. node = node[iterFunc];
  1686. if (!node) break; // can't go any further - exit
  1687. logger('[s] adding sibling node', node);
  1688. toRemove.push(node);
  1689. siblings -= 1;
  1690. }
  1691. }
  1692. }
  1693. let toSkip = [];
  1694. for (let node of toRemove)
  1695. if (!toRemove.every(other => other === node || !node.contains(other)))
  1696. toSkip.push(node);
  1697. if (toRemove.length)
  1698. logger(`[s] proceeding with ${params.hide?'hide':'removal'} of`, toRemove, `skip`, toSkip);
  1699. for (let node of toRemove) if (!toSkip.includes(node))
  1700. remFunc(node);
  1701. }
  1702.  
  1703. // function to perform multiple checks if ads inserted with a delay
  1704. // by default does 30 checks withing a 3 seconds unless nonstop mode specified
  1705. // also does 1 extra check when a page completely loads
  1706. // selector and words - passed dow to scissors
  1707. // params - object with multiple extra parameters:
  1708. // .log - display log in the console
  1709. // .root - selector to narrow down scope to scan;
  1710. // .observe - if true then check will be performed continuously;
  1711. // Other parameters passed down to scissors.
  1712. function gardener(selector, words, params) {
  1713. let logger = (...args) => { if (params.log) _console.log(...args) };
  1714. params = params || {};
  1715. logger(`[gardener] selector: '${selector}' detector: ${words} options: ${JSON.stringify(params)}`);
  1716. let scope;
  1717. let globalScope = [_de];
  1718. let domLoaded = false;
  1719. let getScope = root => root ? _de.querySelectorAll(root) : globalScope;
  1720. let onevent = e => {
  1721. logger(`[gardener] cleanup on ${Object.getPrototypeOf(e)} "${e.type}"`);
  1722. for (let node of scope)
  1723. scissors(selector, words, node, params);
  1724. };
  1725. let repeater = n => {
  1726. if (!domLoaded && n) {
  1727. setTimeout(repeater, 500, n - 1);
  1728. scope = getScope(params.root);
  1729. if (!scope) // exit if the root element is not present on the page
  1730. return 0;
  1731. onevent({type: 'Repeater'});
  1732. }
  1733. };
  1734. repeater(20);
  1735. _document.addEventListener(
  1736. 'DOMContentLoaded', (e) => {
  1737. domLoaded = true;
  1738. // narrow down scope to a specific element
  1739. scope = getScope(params.root);
  1740. if (!scope) // exit if the root element is not present on the page
  1741. return 0;
  1742. logger('[g] scope', scope);
  1743. // add observe mode if required
  1744. if (params.observe) {
  1745. let params = { childList:true, subtree: true };
  1746. let observer = new MutationObserver(
  1747. function(ms) {
  1748. for (let m of ms)
  1749. if (m.addedNodes.length)
  1750. onevent(m);
  1751. }
  1752. );
  1753. for (let node of scope)
  1754. observer.observe(node, params);
  1755. logger('[g] observer enabled');
  1756. }
  1757. onevent(e);
  1758. }, false);
  1759. // wait for a full page load to do one extra cut
  1760. win.addEventListener('load', onevent, false);
  1761. }
  1762.  
  1763. // wrap popular methods to open a new tab to catch specific behaviours
  1764. function createWindowOpenWrapper(openFunc) {
  1765. let _createElement = _Document.createElement,
  1766. _appendChild = _Element.appendChild,
  1767. fakeNative = (f) => (f.toString = () => `function ${f.name}() { [native code] }`);
  1768.  
  1769. let nt = new nullTools();
  1770. fakeNative(openFunc);
  1771.  
  1772. let parser = _createElement.call(_document, 'a');
  1773. let openWhitelist = (url, parent) => {
  1774. parser.href = url;
  1775. return parser.hostname === 'www.imdb.com' || parser.hostname === 'www.kinopoisk.ru' ||
  1776. parent.hostname === 'radikal.ru' && url === void 0;
  1777. };
  1778.  
  1779. let redefineOpen = (root) => {
  1780. if ('open' in root) {
  1781. let _open = root.open.bind(root);
  1782. nt.define(root, 'open', (...args) => {
  1783. if (openWhitelist(args[0], location)) {
  1784. _console.log('Whitelisted popup:', ...args);
  1785. return _open(...args);
  1786. }
  1787. return openFunc(...args);
  1788. });
  1789. }
  1790. };
  1791. redefineOpen(win);
  1792.  
  1793. function createElement() {
  1794. '[native code]';
  1795. let el = _createElement.apply(this, arguments);
  1796. // redefine window.open in first-party frames
  1797. if (el instanceof HTMLIFrameElement || el instanceof HTMLObjectElement)
  1798. el.addEventListener('load', (e) => {
  1799. try {
  1800. redefineOpen(e.target.contentWindow);
  1801. } catch(ignore) {}
  1802. }, false);
  1803. return el;
  1804. }
  1805. fakeNative(createElement);
  1806.  
  1807. let redefineCreateElement = (obj) => {
  1808. for (let root of [obj.document, _Document]) if ('createElement' in root)
  1809. nt.define(root, 'createElement', createElement);
  1810. };
  1811. redefineCreateElement(win);
  1812.  
  1813. // wrap window.open in newly added first-party frames
  1814. _Element.appendChild = function appendChild() {
  1815. '[native code]';
  1816. let el = _appendChild.apply(this, arguments);
  1817. if (el instanceof HTMLIFrameElement)
  1818. try {
  1819. redefineOpen(el.contentWindow);
  1820. redefineCreateElement(el.contentWindow);
  1821. } catch(ignore) {}
  1822. return el;
  1823. };
  1824. fakeNative(_Element.appendChild);
  1825. }
  1826.  
  1827. // Function to catch and block various methods to open a new window with 3rd-party content.
  1828. // Some advertisement networks went way past simple window.open call to circumvent default popup protection.
  1829. // This funciton blocks window.open, ability to restore original window.open from an IFRAME object,
  1830. // ability to perform an untrusted (not initiated by user) click on a link, click on a link without a parent
  1831. // node or simply a link with piece of javascript code in the HREF attribute.
  1832. function preventPopups() {
  1833. // call sandbox-me if in iframe and not whitelisted
  1834. if (inIFrame) {
  1835. win.top.postMessage({ name: 'sandbox-me', href: win.location.href }, '*');
  1836. return;
  1837. }
  1838.  
  1839. scriptLander(() => {
  1840. let nt = new nullTools({log:true});
  1841. let open = (...args) => {
  1842. '[native code]';
  1843. _console.warn('Site attempted to open a new window', ...args);
  1844. return {
  1845. document: nt.proxy({
  1846. write: nt.func({}, 'write'),
  1847. writeln: nt.func({}, 'writeln')
  1848. }),
  1849. location: nt.proxy({})
  1850. };
  1851. };
  1852.  
  1853. createWindowOpenWrapper(open);
  1854.  
  1855. _console.log('Popup prevention enabled.');
  1856. }, nullTools, createWindowOpenWrapper);
  1857. }
  1858.  
  1859. // Helper function to close background tab if site opens itself in a new tab and then
  1860. // loads a 3rd-party page in the background one (thus performing background redirect).
  1861. function preventPopunders() {
  1862. // create "close_me" event to call high-level window.close()
  1863. let eventName = `close_me_${Math.random().toString(36).substr(2)}`;
  1864. let callClose = () => {
  1865. _console.log('close call');
  1866. window.close();
  1867. };
  1868. window.addEventListener(eventName, callClose, true);
  1869.  
  1870. scriptLander(() => {
  1871. // get host of a provided URL with help of an anchor object
  1872. // unfortunately new URL(url, window.location) generates wrong URL in some cases
  1873. let parseURL = _document.createElement('A');
  1874. let getHost = url => {
  1875. parseURL.href = url;
  1876. return parseURL.hostname
  1877. };
  1878. // site went to a new tab and attempts to unload
  1879. // call for high-level close through event
  1880. let closeWindow = () => window.dispatchEvent(new CustomEvent(eventName, {}));
  1881. // check is URL local or goes to different site
  1882. let isLocal = (url) => {
  1883. if (url === location.pathname || url === location.href)
  1884. return true; // URL points to current pathname or full address
  1885. let host = getHost(url);
  1886. let site = location.hostname;
  1887. return host !== '' && // URLs with unusual protocol may have empty 'host'
  1888. (site === host || site.endsWith(`.${host}`) || host.endsWith(`.${site}`));
  1889. };
  1890.  
  1891. let _open = window.open.bind(window);
  1892. let open = (...args) => {
  1893. '[native code]';
  1894. let url = args[0];
  1895. if (url && isLocal(url))
  1896. window.addEventListener('beforeunload', closeWindow, true);
  1897. return _open(...args);
  1898. };
  1899.  
  1900. createWindowOpenWrapper(open);
  1901.  
  1902. _console.log("Background redirect prevention enabled.");
  1903. }, `let eventName="${eventName}"`, nullTools, createWindowOpenWrapper);
  1904. }
  1905.  
  1906. // Mix between check for popups and popunders
  1907. // Significantly more agressive than both and can't be used as universal solution
  1908. function preventPopMix() {
  1909. if (inIFrame) {
  1910. win.top.postMessage({ name: 'sandbox-me', href: win.location.href }, '*');
  1911. return;
  1912. }
  1913.  
  1914. // create "close_me" event to call high-level window.close()
  1915. let eventName = `close_me_${Math.random().toString(36).substr(2)}`;
  1916. let callClose = () => {
  1917. _console.log('close call');
  1918. window.close();
  1919. };
  1920. window.addEventListener(eventName, callClose, true);
  1921.  
  1922. scriptLander(() => {
  1923. let _open = window.open,
  1924. parseURL = _document.createElement('A');
  1925. // get host of a provided URL with help of an anchor object
  1926. // unfortunately new URL(url, window.location) generates wrong URL in some cases
  1927. let getHost = (url) => {
  1928. parseURL.href = url;
  1929. return parseURL.host;
  1930. };
  1931. // site went to a new tab and attempts to unload
  1932. // call for high-level close through event
  1933. let closeWindow = () => {
  1934. _open(window.location,'_self');
  1935. window.dispatchEvent(new CustomEvent(eventName, {}));
  1936. };
  1937. // check is URL local or goes to different site
  1938. function isLocal(url) {
  1939. let loc = window.location;
  1940. if (url === loc.pathname || url === loc.href)
  1941. return true; // URL points to current pathname or full address
  1942. let host = getHost(url),
  1943. site = loc.host;
  1944. if (host === '')
  1945. return false; // URLs with unusual protocol may have empty 'host'
  1946. if (host.length > site.length)
  1947. [site, host] = [host, site];
  1948. return site.includes(host, site.length - host.length);
  1949. }
  1950.  
  1951. // add check for redirect for 5 seconds, then disable it
  1952. function checkRedirect() {
  1953. window.addEventListener('beforeunload', closeWindow, true);
  1954. setTimeout(closeWindow=>window.removeEventListener('beforeunload', closeWindow, true), 5000, closeWindow);
  1955. }
  1956.  
  1957. function open(url, name) {
  1958. '[native code]';
  1959. if (url && isLocal(url) && (!name || name === '_blank')) {
  1960. _console.warn('Suspicious local new window', arguments);
  1961. checkRedirect();
  1962. return _open.apply(this, arguments);
  1963. }
  1964. _console.warn('Blocked attempt to open a new window', arguments);
  1965. return {
  1966. document: {
  1967. write: () => {},
  1968. writeln: () => {}
  1969. }
  1970. };
  1971. }
  1972.  
  1973. function clickHandler(e) {
  1974. let link = e.target,
  1975. url = link.href||'';
  1976. if (e.targetParentNode && e.isTrusted || link.target !== '_blank') {
  1977. _console.log('Link', link, 'were created dinamically, but looks fine.');
  1978. return true;
  1979. }
  1980. if (isLocal(url) && link.target === '_blank') {
  1981. _console.log('Suspicious local link', link);
  1982. checkRedirect();
  1983. return;
  1984. }
  1985. _console.log('Blocked suspicious click on a link', link);
  1986. e.stopPropagation();
  1987. e.preventDefault();
  1988. }
  1989.  
  1990. createWindowOpenWrapper(open, clickHandler);
  1991.  
  1992. _console.log("Mixed popups prevention enabled.");
  1993. }, `let eventName="${eventName}"`, createWindowOpenWrapper);
  1994. }
  1995. // External listener for case when site known to open popups were loaded in iframe
  1996. // It will sandbox any iframe which will send message 'forbid.popups' (preventPopups sends it)
  1997. // Some sites replace frame's window.location with data-url to run in clean context
  1998. if (!inIFrame) window.addEventListener(
  1999. 'message', function(e) {
  2000. if (!e.data || e.data.name !== 'sandbox-me' || !e.data.href)
  2001. return;
  2002. let src = e.data.href;
  2003. for (let frame of _document.querySelectorAll('iframe'))
  2004. if (frame.contentWindow === e.source) {
  2005. if (frame.hasAttribute('sandbox')) {
  2006. if (!frame.sandbox.contains('allow-popups'))
  2007. return; // exit frame since it's already sandboxed and popups are blocked
  2008. // remove allow-popups if frame already sandboxed
  2009. frame.sandbox.remove('allow-popups');
  2010. } else
  2011. // set sandbox mode for troublesome frame and allow scripts, forms and a few other actions
  2012. // technically allowing both scripts and same-origin allows removal of the sandbox attribute,
  2013. // but to apply content must be reloaded and this script will re-apply it in the result
  2014. frame.setAttribute('sandbox','allow-forms allow-scripts allow-presentation allow-top-navigation allow-same-origin');
  2015. _console.log('Disallowed popups from iframe', frame);
  2016.  
  2017. // reload frame content to apply restrictions
  2018. if (!src) {
  2019. src = frame.src;
  2020. _console.log('Unable to get current iframe location, reloading from src', src);
  2021. } else
  2022. _console.log('Reloading iframe with URL', src);
  2023. frame.src = 'about:blank';
  2024. frame.src = src;
  2025. }
  2026. }, false
  2027. );
  2028.  
  2029. function selectiveEval(extra, useGeneric = true) {
  2030. scriptLander(() => {
  2031. let _eval_def = Object.getOwnPropertyDescriptor(win, 'eval');
  2032. if (!_eval_def || !_eval_def.value) {
  2033. _console.warn('Unable to wrap window.eval.', _eval_def);
  2034. return;
  2035. }
  2036. let genericPatterns = /_0x|location\s*?=|location.href\s*?=|location.assign\(|open\(/i;
  2037. let _eval_val = _eval_def.value;
  2038. _eval_def.value = function(...args) {
  2039. if (useGeneric && genericPatterns.test(args[0]) || extra && extra.test(args[0])) {
  2040. _console.warn(`Skipped eval of ${args[0].slice(0, 512)}\u2026`);
  2041. return null;
  2042. }
  2043. return _eval_val.apply(this, args);
  2044. };
  2045. Object.defineProperty(win, 'eval', _eval_def);
  2046. }, `let extra = ${extra}`);
  2047. }
  2048.  
  2049. // hides cookies by pattern and attempts to remove them if they already set
  2050. // also prevents setting new versions of such cookies
  2051. function selectiveCookies(scPattern, scPaths = []) {
  2052. scriptLander(() => {
  2053. let ga = '_g(at?|id)|__utm[a-z]'; // Google Analytics Cookies
  2054. scPattern = new RegExp(`(^|;\\s?)(${scPattern}|${ga})($|=)`);
  2055. if (isFirefox && scPaths.length)
  2056. scPaths.forEach((path, id) => scPaths[id] = `${path}/`);
  2057. scPaths.push('/');
  2058. let _doc_proto = ('cookie' in _Document) ? _Document : Object.getPrototypeOf(_document);
  2059. let _cookie = Object.getOwnPropertyDescriptor(_doc_proto, 'cookie');
  2060. if (_cookie) {
  2061. let _set_cookie = Function.prototype.call.bind(_cookie.set);
  2062. let _get_cookie = Function.prototype.call.bind(_cookie.get);
  2063. let expireDate = 'Thu, 01 Jan 1970 00:00:01 UTC';
  2064. let expireAge = '-99999999';
  2065. let expireBase = `=;expires=${expireDate};Max-Age=${expireAge}`;
  2066. let expireAttempted = {};
  2067. // expire is called from cookie getter and doesn't know exact parameters used to set cookies present there
  2068. // so, it will use path=/ by default if scPaths wasn't set and attempt to set cookies on all parent domains
  2069. let expire = (cookie, that) => {
  2070. let domain = that.location.hostname.split('.'),
  2071. name = cookie.replace(/=.*/,'');
  2072. scPaths.forEach(path =>_set_cookie(that, `${name}${expireBase};path=${path}`));
  2073. while (domain.length > 1) {
  2074. try {
  2075. scPaths.forEach(
  2076. path => _set_cookie(that, `${name}${expireBase};domain=${domain.join('.')};path=${path}`)
  2077. );
  2078. } catch(e) { _console.warn(e); }
  2079. domain.shift();
  2080. }
  2081. expireAttempted[name] = true;
  2082. _console.log('Removing existing cookie:', cookie);
  2083. };
  2084. // skip setting unwanted cookies
  2085. _cookie.set = function(value) {
  2086. if (scPattern.test(value)) {
  2087. _console.warn('Ignored cookie:', value);
  2088. // try to remove same cookie if it already exists using exact values from the set string
  2089. if (scPattern.test(_get_cookie(this))) {
  2090. let parts = value.split(/;\s?/),
  2091. name = parts[0].replace(/=.*/,''),
  2092. newParts = [`${name}=`, `expires=${expireDate}`, `Max-Age=${expireAge}`],
  2093. skip = [name, 'expires', 'Max-Age'];
  2094. for (let part of parts)
  2095. if (!skip.includes(part.replace(/=.*/,'')))
  2096. newParts.push(part);
  2097. try {
  2098. _set_cookie(this, newParts.join(';'));
  2099. } catch(e) { _console.warn(e); }
  2100. _console.log('Removing existing cookie:', name);
  2101. }
  2102. return;
  2103. }
  2104. return _set_cookie(this, value);
  2105. };
  2106. // hide unwanted cookies from site
  2107. _cookie.get = function() {
  2108. let res = _get_cookie(this);
  2109. if (scPattern.test(res)) {
  2110. let stack = [];
  2111. for (let cookie of res.split(/;\s?/))
  2112. if (!scPattern.test(cookie))
  2113. stack.push(cookie);
  2114. else {
  2115. let name = cookie.replace(/=.*/,'');
  2116. if (expireAttempted[name]) {
  2117. _console.log('Unable to expire:', cookie);
  2118. expireAttempted[name] = false;
  2119. }
  2120. if (!(name in expireAttempted))
  2121. expire(cookie, this);
  2122. }
  2123. res = stack.join('; ');
  2124. }
  2125. return res;
  2126. };
  2127. Object.defineProperty(_doc_proto, 'cookie', _cookie);
  2128. }
  2129. _console.log('Active cookies:', document.cookie);
  2130. }, `let scPattern = "${scPattern}", scPaths = ${scPaths}, isFirefox = ${isFirefox};`);
  2131. }
  2132.  
  2133. /*{ // simple toString wrapper, might be useful to prevent detection
  2134. '[native code]';
  2135. let _toString = Function.prototype.apply.bind(Function.prototype.toString);
  2136. let baseText = Function.prototype.toString.toString();
  2137. let protect = new WeakSet();
  2138. protect.add(_Document.createElement);
  2139. protect.add(_Node.appendChild);
  2140. protect.add(_Node.removeChild);
  2141. win.Function.prototype.toString = function() {
  2142. if (protect.has(this))
  2143. return baseText.replace('toString', this.name);
  2144. return _toString(this);
  2145. };
  2146. protect.add(Function.prototype.toString);
  2147. }*/
  2148.  
  2149. // Locates a node with specific text in Russian
  2150. // Uses table of substitutions for similar letters
  2151. let selectNodeByTextContent = (()=> {
  2152. let subs = {
  2153. // english & greek
  2154. 'А': 'AΑ', 'В': 'BΒ', 'Г':'Γ',
  2155. 'Е': 'EΕ', 'З': '3', 'К':'KΚ',
  2156. 'М': 'MΜ', 'Н': 'HΗ', 'О':'OΟ',
  2157. 'П': 'Π', 'Р': 'PΡ', 'С':'C',
  2158. 'Т': 'T', 'Ф': 'Φ', 'Х':'XΧ'
  2159. }
  2160. let regExpBuilder = text => new RegExp(
  2161. text.toUpperCase()
  2162. .split('')
  2163. .map(function(e){
  2164. return `${e in subs ? `[${e}${subs[e]}]` : (e === ' ' ? '\\s+' : e)}[\u200b\u200c\u200d]*`;
  2165. })
  2166. .join(''),
  2167. 'i');
  2168. let reMap = {};
  2169. return (re, opts = { root: _document.body }) => {
  2170. if (!re.test) {
  2171. if (!reMap[re])
  2172. reMap[re] = regExpBuilder(re);
  2173. re = reMap[re];
  2174. }
  2175.  
  2176. for (let child of opts.root.children)
  2177. if (re.test(child.textContent)) {
  2178. if (opts.shallow)
  2179. return child;
  2180. opts.root = child;
  2181. return selectNodeByTextContent(re, opts) || child;
  2182. }
  2183. }
  2184. })();
  2185.  
  2186. // Set alternative name for Ya object
  2187. function setYa(name) {
  2188. Object.defineProperty(win, name, {
  2189. get: () => win.Ya,
  2190. set: () => true
  2191. });
  2192. }
  2193.  
  2194. // === Scripts for specific domains ===
  2195.  
  2196. let scripts = {};
  2197. // prevent popups and redirects block
  2198. // Popups
  2199. scripts.preventPopups = {
  2200. other: [
  2201. 'biqle.ru',
  2202. 'chaturbate.com',
  2203. 'dfiles.ru',
  2204. 'eporner.eu',
  2205. 'hentaiz.org',
  2206. 'mirrorcreator.com',
  2207. 'online-multy.ru',
  2208. 'radikal.ru', 'rumedia.ws',
  2209. 'tapehub.tech', 'thepiratebay.org',
  2210. 'unionpeer.com',
  2211. 'zippyshare.com'
  2212. ],
  2213. now: preventPopups
  2214. };
  2215. // Popunders (background redirect)
  2216. scripts.preventPopunders = {
  2217. other: [
  2218. 'lostfilm-online.ru',
  2219. 'mediafire.com', 'megapeer.org', 'megapeer.ru',
  2220. 'perfectgirls.net'
  2221. ],
  2222. now: preventPopunders
  2223. };
  2224. // PopMix (both types of popups encountered on site)
  2225. scripts['openload.co'] = {
  2226. other: ['oload.tv', 'oload.info'],
  2227. now: () => {
  2228. let nt = new nullTools();
  2229. nt.define(win, 'CNight', win.CoinHive);
  2230. if (location.pathname.startsWith('/embed/')) {
  2231. nt.define(win, 'BetterJsPop', {
  2232. add: ((a, b) => _console.warn('BetterJsPop.add', a, b)),
  2233. config: ((o) => _console.warn('BetterJsPop.config', o)),
  2234. Browser: { isChrome: true }
  2235. });
  2236. nt.define(win, 'isSandboxed', nt.func(null));
  2237. nt.define(win, 'adblock', false);
  2238. nt.define(win, 'adblock2', false);
  2239. } else preventPopMix();
  2240. }
  2241. };
  2242. scripts['turbobit.net'] = preventPopMix;
  2243.  
  2244. scripts['tapochek.net'] = () => {
  2245. // workaround for moradu.com/apu.php load error handler script, not sure which ad network is this
  2246. let _appendChild = Object.getOwnPropertyDescriptor(_Node, 'appendChild');
  2247. let _appendChild_value = _appendChild.value;
  2248. _appendChild.value = function appendChild(node) {
  2249. if (this === _document.body)
  2250. if ((node instanceof HTMLScriptElement || node instanceof HTMLStyleElement) &&
  2251. /^https?:\/\/[0-9a-f]{15}\.com\/\d+(\/|\.css)$/.test(node.src) ||
  2252. node instanceof HTMLDivElement && node.style.zIndex > 900000 &&
  2253. node.style.backgroundImage.includes('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'))
  2254. throw '...eenope!';
  2255. return _appendChild_value.apply(this, arguments);
  2256. };
  2257. Object.defineProperty(_Node, 'appendChild', _appendChild);
  2258.  
  2259. // disable window focus tricks and changing location
  2260. let focusHandlerName = /\WfocusAchieved\(/
  2261. let _toString = Function.prototype.call.bind(Function.prototype.toString);
  2262. let _setInterval = win.setInterval;
  2263. win.setInterval = (...args) => {
  2264. if (args.length && focusHandlerName.test(_toString(args[0]))) {
  2265. _console.log('skip setInterval for', ...args);
  2266. return -1;
  2267. }
  2268. return _setInterval(...args);
  2269. };
  2270. let _addEventListener = win.addEventListener;
  2271. win.addEventListener = function(...args) {
  2272. if (args.length && args[0] === 'focus' && focusHandlerName.test(_toString(args[1]))) {
  2273. _console.log('skip addEventListener for', ...args);
  2274. return void 0;
  2275. }
  2276. return _addEventListener.apply(this, args);
  2277. };
  2278.  
  2279. // generic popup prevention
  2280. preventPopups();
  2281. };
  2282.  
  2283. scripts['rustorka.com'] = {
  2284. other: ['rustorka.club', 'rustorka.lib', 'rustorka.net'],
  2285. now: () => {
  2286. selectiveEval(/antiadblock/);
  2287. selectiveCookies('adblock|u_count|gophp|st2|st3', ['/forum']);
  2288. scriptLander(() => {
  2289. // wrap window.open to catch a popup if it triggers
  2290. win.open = (...args) => {
  2291. _console.warn(`Site attempted to open "${args[0]}" in a new window.`);
  2292. location.replace(location.href);
  2293. return null;
  2294. };
  2295. window.addEventListener('DOMContentLoaded', () => {
  2296. let link = void 0;
  2297. _document.body.addEventListener('mousedown', e => {
  2298. link = e.target.closest('a, select, #fancybox-title-wrap');
  2299. }, false);
  2300. let _open = window.open.bind(window);
  2301. let _getAttribute = Function.prototype.call.bind(_Element.getAttribute);
  2302. win.open = (...args) => {
  2303. let url = args[0];
  2304. if (link instanceof HTMLAnchorElement) {
  2305. // third-party post links
  2306. let href = _getAttribute(link, 'href');
  2307. if (link.classList.contains('postLink') &&
  2308. !link.matches(`a[href*="${location.hostname}"]`) &&
  2309. (href === url || link.href === url))
  2310. return _open(...args);
  2311. // onclick # links
  2312. if (href === '#' && /window\.open/.test(_getAttribute(link, 'onclick')))
  2313. return _open(...args);
  2314. // force local links to load in the current window
  2315. if (href[0] === '/' || href.startsWith('./') || href.includes(`//${location.hostname}/`))
  2316. location.assign(href);
  2317. }
  2318. // list of image hostings under upload picture button (new comment)
  2319. if (link instanceof HTMLSelectElement &&
  2320. !url.includes(location.hostname) &&
  2321. link.value === url)
  2322. return _open(...args);
  2323. // open screenshot in a new window
  2324. if (link instanceof HTMLSpanElement &&
  2325. link.id === 'fancybox-title-wrap')
  2326. return _open(...args);
  2327. // looks like tabunder
  2328. if (link === null && url === location.href)
  2329. location.replace(url); // reload current page
  2330. // other cases
  2331. _console.warn(`Site attempted to open "${url}" in a new window. Source: `, link);
  2332. return {};
  2333. };
  2334. }, true);
  2335. }, nullTools)
  2336. }
  2337. };
  2338.  
  2339. // = other ======================================================================================
  2340. scripts['1tv.ru'] = {
  2341. other: ['mediavitrina.ru'],
  2342. now: () => scriptLander(() => {
  2343. let nt = new nullTools();
  2344. nt.define(win, 'EUMPAntiblockConfig', nt.proxy({url: '//www.1tv.ru/favicon.ico'}));
  2345. let disablePlugins = {
  2346. 'antiblock': false,
  2347. 'stat1tv': false
  2348. };
  2349. let _EUMPConfig = void 0;
  2350. let _EUMPConfig_set = x => {
  2351. if (x.plugins) {
  2352. x.plugins = x.plugins.filter(plugin => (plugin in disablePlugins) ? !(disablePlugins[plugin] = true) : true);
  2353. _console.warn(`Player plugins: active [${x.plugins}], disabled [${Object.keys(disablePlugins).filter(x => disablePlugins[x])}]`);
  2354. }
  2355. _EUMPConfig = x;
  2356. };
  2357. if ('EUMPConfig' in win)
  2358. _EUMPConfig_set(win.EUMPConfig);
  2359. Object.defineProperty(win, 'EUMPConfig', {
  2360. enumerable: true,
  2361. get: () => _EUMPConfig,
  2362. set: _EUMPConfig_set
  2363. });
  2364. }, nullTools)
  2365. };
  2366.  
  2367. scripts['2picsun.ru'] = {
  2368. other: [
  2369. 'pics2sun.ru', '3pics-img.ru'
  2370. ],
  2371. now: () => {
  2372. Object.defineProperty(navigator, 'userAgent', {value: 'googlebot'});
  2373. }
  2374. };
  2375.  
  2376. scripts['4pda.ru'] = {
  2377. now: () => {
  2378. // https://gf.qytechs.cn/en/scripts/14470-4pda-unbrender
  2379. let isForum = location.pathname.startsWith('/forum/'),
  2380. remove = node => (node && node.parentNode.removeChild(node)),
  2381. hide = node => (node && (node.style.display = 'none'));
  2382.  
  2383. // clean a page
  2384. window.addEventListener(
  2385. 'DOMContentLoaded', function() {
  2386. let width = () => window.innerWidth || _de.clientWidth || _document.body.clientWidth || 0;
  2387. let height = () => window.innerHeight || _de.clientHeight || _document.body.clientHeight || 0;
  2388.  
  2389. HeaderAds: {
  2390. // hide ads above HEADER
  2391. let header = _document.querySelector('.drop-search');
  2392. if (!header) {
  2393. _console.warn('Unable to locate header element');
  2394. break HeaderAds;
  2395. }
  2396. header = header.parentNode.parentNode;
  2397. for (let itm of header.parentNode.children)
  2398. if (itm !== header)
  2399. hide(itm);
  2400. else break;
  2401. }
  2402.  
  2403. if (isForum) {
  2404. let itm = _document.querySelector('#logostrip');
  2405. if (itm)
  2406. remove(itm.parentNode.nextSibling);
  2407. // clear background in the download frame
  2408. if (location.pathname.startsWith('/forum/dl/')) {
  2409. let setBackground = node => _setAttribute(
  2410. node,
  2411. 'style', (_getAttribute(node, 'style') || '') +
  2412. ';background-color:#4ebaf6!important'
  2413. );
  2414. setBackground(_document.body);
  2415. for (let itm of _document.querySelectorAll('body > div'))
  2416. if (!itm.querySelector('.dw-fdwlink, .content') && !itm.classList.contains('footer'))
  2417. remove(itm);
  2418. else
  2419. setBackground(itm);
  2420. }
  2421. // exist from DOMContentLoaded since the rest is not for forum
  2422. return;
  2423. }
  2424.  
  2425. FixNavMenu: {
  2426. // restore DevDB link in the navigation
  2427. let itm = _document.querySelector('#nav li a[href$="/devdb/"]')
  2428. if (!itm) {
  2429. _console.warn('Unable to locate navigation menu');
  2430. break FixNavMenu;
  2431. }
  2432. itm.closest('li').style.display = 'block';
  2433. // hide ad link from the navigation
  2434. hide(_document.querySelector('#nav li a[data-dotrack]'));
  2435. }
  2436. SidebarAds: {
  2437. // remove ads from sidebar
  2438. let aside = _document.querySelectorAll('[class]:not([id]) > [id]:not([class]) > :first-child + :last-child');
  2439. if (!aside.length) {
  2440. _console.warn('Unable to locate sidebar');
  2441. break SidebarAds;
  2442. }
  2443. let post;
  2444. for (let side of aside) {
  2445. _console.log('Processing potential sidebar:', side);
  2446. for (let itm of Array.from(side.children)) {
  2447. post = itm.classList.contains('post');
  2448. if (itm.querySelector('iframe') && !post)
  2449. remove(itm);
  2450. if (itm.querySelector('script, a[target="_blank"] > img') && !post || !itm.children.length)
  2451. hide(itm);
  2452. }
  2453. }
  2454. }
  2455.  
  2456. _document.body.setAttribute('style', (_document.body.getAttribute('style')||'')+';background-color:#E6E7E9!important');
  2457.  
  2458. let extra = 'background-image:none!important;background-color:transparent!important',
  2459. fakeStyles = new WeakMap(),
  2460. styleProxy = {
  2461. get: (target, prop) => fakeStyles.get(target)[prop] || target[prop],
  2462. set: function(target, prop, value) {
  2463. let fakeStyle = fakeStyles.get(target);
  2464. ((prop in fakeStyle) ? fakeStyle : target)[prop] = value;
  2465. return true;
  2466. }
  2467. };
  2468. for (let itm of _document.querySelectorAll('[id]:not(A), A')) {
  2469. if (!(itm.offsetWidth > 0.95 * width() &&
  2470. itm.offsetHeight > 0.85 * height()))
  2471. continue;
  2472. if (itm.tagName !== 'A') {
  2473. fakeStyles.set(itm.style, {
  2474. 'backgroundImage': itm.style.backgroundImage,
  2475. 'backgroundColor': itm.style.backgroundColor
  2476. });
  2477.  
  2478. try {
  2479. Object.defineProperty(itm, 'style', {
  2480. value: new Proxy(itm.style, styleProxy),
  2481. enumerable: true
  2482. });
  2483. } catch (e) {
  2484. _console.log('Unable to protect style property.', e);
  2485. }
  2486.  
  2487. _setAttribute(itm, 'style', `${(_getAttribute(itm, 'style') || '')};${extra}`);
  2488. }
  2489. if (itm.tagName === 'A')
  2490. _setAttribute(itm, 'style', 'display:none!important');
  2491. }
  2492. }
  2493. );
  2494. }
  2495. };
  2496.  
  2497. scripts['adhands.ru'] = () => scriptLander(() => {
  2498. let nt = new nullTools();
  2499. try {
  2500. let _adv;
  2501. Object.defineProperty(win, 'adv', {
  2502. get: () => _adv,
  2503. set: (v) => {
  2504. _console.log('Blocked advert on adhands.ru.');
  2505. nt.define(v, 'advert', '');
  2506. _adv = v;
  2507. }
  2508. });
  2509. } catch (ignore) {
  2510. if (!win.adv)
  2511. _console.log('Unable to locate advert on adhands.ru.');
  2512. else {
  2513. _console.log('Blocked advert on adhands.ru.');
  2514. nt.define(win.adv, 'advert', '');
  2515. }
  2516. }
  2517. }, nullTools);
  2518.  
  2519. scripts['all-episodes.tv'] = () => {
  2520. let nt = new nullTools();
  2521. nt.define(win, 'perX1', 2);
  2522. createStyle('#advtss, #ad3, a[href*="/ad.admitad.com/"] { display:none!important }');
  2523. };
  2524.  
  2525. scripts['allhentai.ru'] = () => {
  2526. selectiveEval();
  2527. preventPopups();
  2528. scriptLander(() => {
  2529. let _onerror = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'onerror');
  2530. if (!_onerror)
  2531. return;
  2532. _onerror.set = (...args) => _console.log(args[0].toString());
  2533. Object.defineProperty(HTMLElement.prototype, 'onerror', _onerror);
  2534. });
  2535. };
  2536.  
  2537. scripts['allmovie.pro'] = {
  2538. other: ['rufilmtv.org'],
  2539. dom: function() {
  2540. // pretend to be Android to make site use different played for ads
  2541. if (isSafari)
  2542. return;
  2543. Object.defineProperty(navigator, 'userAgent', {
  2544. get: function(){
  2545. 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';
  2546. },
  2547. enumerable: true
  2548. });
  2549. }
  2550. };
  2551.  
  2552. scripts['anidub-online.ru'] = {
  2553. other: ['anime.anidub.com', 'online.anidub.com'],
  2554. dom: function() {
  2555. if (win.ogonekstart1)
  2556. win.ogonekstart1 = () => _console.log("Fire in the hole!");
  2557. },
  2558. now: () => createStyle([
  2559. '.background {background: none!important;}',
  2560. '.background > script + div,'+
  2561. '.background > script ~ div:not([id]):not([class]) + div[id][class]'+
  2562. '{display:none!important}'
  2563. ])
  2564. };
  2565.  
  2566. scripts['audioportal.su'] = {
  2567. now: () => createStyle('#blink2 { display: none !important }'),
  2568. dom: () => {
  2569. let links = _document.querySelectorAll('a[onclick*="clickme("]');
  2570. if (!links) return;
  2571. for (let link of links)
  2572. clickme(link);
  2573. }
  2574. };
  2575.  
  2576. scripts['avito.ru'] = () => selectiveCookies('abp|bltsr|cmtchd|crookie|is_adblock');
  2577.  
  2578. scripts['di.fm'] = () => scriptLander(() => {
  2579. let log = false;
  2580. // wrap global app object to catch registration of specific modules
  2581. let _di = void 0;
  2582. Object.defineProperty(win, 'di', {
  2583. get: () => _di,
  2584. set: vl => {
  2585. if (vl === _di)
  2586. return;
  2587. log && _console.log('di =', vl);
  2588. _di = new Proxy(vl, {
  2589. set: (di, name, vl) => {
  2590. if (vl === di[name])
  2591. return true;
  2592. if (name === 'app') {
  2593. log && _console.log('di.app =', vl);
  2594. if ('module' in vl)
  2595. vl.module = new Proxy(vl.module, {
  2596. apply: (module, that, args) => {
  2597. if (/Wall|Banner|Detect|WebplayerApp\.Ads/.test(args[0])) {
  2598. let name = args[0];
  2599. log && _console.warn('wrap', name, 'module');
  2600. if (typeof args[1] === 'function')
  2601. args[1] = new Proxy(args[1], {
  2602. apply: (fun, that, args) => {
  2603. if (args[0]) // module object
  2604. args[0].start = () => _console.log('Skipped start of', name);
  2605. return Reflect.apply(fun, that, args);
  2606. }
  2607. });
  2608. }// else log && _console.log('loading module', args[0]);
  2609. if (args[0] === 'Modals') {
  2610. log && _console.warn('wrap', name, 'module');
  2611. if (typeof args[1] === 'function')
  2612. args[1] = new Proxy(args[1], {
  2613. apply: (fun, that, args) => {
  2614. if ('commands' in args[1] && 'setHandlers' in args[1].commands &&
  2615. !Object.hasOwnProperty.call(args[1].commands, 'setHandlers')) {
  2616. let _commands = args[1].commands;
  2617. _commands.setHandlers = new Proxy(_commands.setHandlers, {
  2618. apply: (fun, that, args) => {
  2619. for (let name in args[0])
  2620. if (name === 'modal:streaminterrupt' ||
  2621. name === 'modal:midroll')
  2622. args[0][name] = () => _console.log('Skipped', name, 'window');
  2623. delete _commands.setHandlers;
  2624. return Reflect.apply(fun, that, args);
  2625. }
  2626. });
  2627. }
  2628. return Reflect.apply(fun, that, args);
  2629. }
  2630. });
  2631. }
  2632. return Reflect.apply(module, that, args);
  2633. }
  2634. });
  2635. }
  2636. di[name] = vl;
  2637. return true;
  2638. }
  2639. });
  2640. }
  2641. });
  2642. // don't send errorception logs
  2643. Object.defineProperty(win, 'onerror', {
  2644. set: vl => log && _console.warn('Skipped global onerror callback', vl)
  2645. });
  2646. });
  2647.  
  2648. scripts['drive2.ru'] = () => {
  2649. gardener('.c-block:not([data-metrika="recomm"]),.o-grid__item', />Реклама<\//i);
  2650. scriptLander(() => {
  2651. let _d2 = void 0;
  2652. Object.defineProperty(win, 'd2', {
  2653. get: () => _d2,
  2654. set: o => {
  2655. if (o === _d2)
  2656. return true;
  2657. _d2 = new Proxy(o, {
  2658. set: (tgt, prop, val) => {
  2659. if (['brandingRender', 'dvReveal', '__dv'].includes(prop))
  2660. val = () => null;
  2661. tgt[prop] = val;
  2662. return true;
  2663. }
  2664. });
  2665. }
  2666. });
  2667. });
  2668. };
  2669.  
  2670. scripts['fastpic.ru'] = () => {
  2671. let nt = new nullTools();
  2672. // Had to obfuscate property name to avoid triggering anti-obfuscation on gf.qytechs.cn -_- (Exception 403012)
  2673. nt.define(win, `_0x${'4955'}`, []);
  2674. };
  2675.  
  2676. scripts['fishki.net'] = () => {
  2677. scriptLander(() => {
  2678. let nt = new nullTools();
  2679. let fishki = {};
  2680. nt.define(fishki, 'adv', nt.proxy({
  2681. afterAdblockCheck: nt.func(null),
  2682. refreshFloat: nt.func(null)
  2683. }));
  2684. nt.define(fishki, 'is_adblock', false);
  2685. nt.define(win, 'fishki', fishki);
  2686. }, nullTools);
  2687. gardener('.drag_list > .drag_element, .list-view > .paddingtop15, .post-wrap', /543769|Новости\sпартнеров|Полезная\sреклама/);
  2688. };
  2689.  
  2690. scripts['friends.in.ua'] = () => scriptLander(() => {
  2691. Object.defineProperty(win, 'need_warning', {
  2692. get: () => 0, set: () => null
  2693. });
  2694. });
  2695.  
  2696. scripts['gidonline.club'] = () => createStyle('.tray > div[style] {display: none!important}');
  2697.  
  2698. scripts['hdgo.cc'] = {
  2699. other: ['46.30.43.38', 'couber.be'],
  2700. now: () => (new MutationObserver(
  2701. (ms) => {
  2702. let m, node;
  2703. for (m of ms) for (node of m.addedNodes)
  2704. if (node.tagName instanceof HTMLScriptElement && _getAttribute(node, 'onerror') !== null)
  2705. node.removeAttribute('onerror');
  2706. }
  2707. )).observe(_document.documentElement, { childList:true, subtree: true })
  2708. };
  2709.  
  2710. scripts['gismeteo.ru'] = {
  2711. other: ['gismeteo.by', 'gismeteo.kz', 'gismeteo.ua'],
  2712. now: () => {
  2713. selectiveCookies('ab_[^=]*|bltsr|redirect|_gab');
  2714. gardener('div > script', /AdvManager/i, { observe: true, parent: 'div' })
  2715. }
  2716. };
  2717.  
  2718. scripts['hdrezka.ag'] = () => {
  2719. Object.defineProperty(win, 'ab', { value: false, enumerable: true });
  2720. gardener('div[id][onclick][onmouseup][onmousedown]', /onmouseout/i);
  2721. };
  2722.  
  2723. scripts['hqq.tv'] = () => scriptLander(() => {
  2724. // disable anti-debugging in hqq.tv player
  2725. let isObfuscated = text => /[^a-z0-9]([a-z0-9]{1,2}\.[a-z0-9]{1,2}\(|[a-z0-9]{4}\.[a-z]\(\d+\)|[a-z0-9]\[[a-z0-9]{1,2}\]\[[a-z0-9]{1,2}\])/i.test(text);
  2726. deepWrapAPI(root => {
  2727. // skip obfuscated stuff and a few other calls
  2728. let _setInterval = root.setInterval,
  2729. _setTimeout = root.setTimeout,
  2730. _toString = root.Function.prototype.call.bind(root.Function.prototype.toString);
  2731. root.setInterval = (...args) => {
  2732. let fun = args[0];
  2733. if (fun instanceof Function) {
  2734. let text = _toString(fun),
  2735. skip = text.includes('check();') || isObfuscated(text);
  2736. _console.warn('setInterval', text, 'skip', skip);
  2737. if (skip) return -1;
  2738. }
  2739. return _setInterval.apply(this, args);
  2740. };
  2741. let wrappedST = new WeakSet();
  2742. root.setTimeout = (...args) => {
  2743. let fun = args[0];
  2744. if (fun instanceof Function) {
  2745. let text = _toString(fun),
  2746. skip = fun.name === 'check' || isObfuscated(text);
  2747. if (!wrappedST.has(fun)) {
  2748. _console.warn('setTimeout', text, 'skip', skip);
  2749. wrappedST.add(fun);
  2750. }
  2751. if (skip) return;
  2752. }
  2753. return _setTimeout.apply(this, args);
  2754. };
  2755. // skip 'debugger' call
  2756. let _eval = root.eval;
  2757. root.eval = text => {
  2758. if (typeof text === 'string' && text.includes('debugger;')) {
  2759. _console.warn('skip eval', text);
  2760. return;
  2761. }
  2762. _eval(text);
  2763. };
  2764. // Prevent RegExpt + toString trick
  2765. let _proto = void 0;
  2766. try {
  2767. _proto = root.RegExp.prototype;
  2768. } catch(ignore) {
  2769. return;
  2770. }
  2771. let _RE_tS = Object.getOwnPropertyDescriptor(_proto, 'toString');
  2772. let _RE_tSV = _RE_tS.value || _RE_tS.get();
  2773. Object.defineProperty(_proto, 'toString', {
  2774. enumerable: _RE_tS.enumerable,
  2775. configurable: _RE_tS.configurable,
  2776. get: () => _RE_tSV,
  2777. set: val => _console.warn('Attempt to change toString for', this, 'with', _toString(val))
  2778. });
  2779. });
  2780. }, deepWrapAPI);
  2781.  
  2782. scripts['hideip.me'] = {
  2783. now: () => scriptLander(() => {
  2784. let _innerHTML = Object.getOwnPropertyDescriptor(_Element, 'innerHTML');
  2785. let _set_innerHTML = _innerHTML.set;
  2786. let _innerText = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'innerText');
  2787. let _get_innerText = _innerText.get;
  2788. let div = _document.createElement('div');
  2789. _innerHTML.set = function(...args) {
  2790. _set_innerHTML.call(div, args[0].replace('i','a'));
  2791. if (args[0] && /[рp][еe]кл/.test(_get_innerText.call(div))||
  2792. /(\d\d\d?\.){3}\d\d\d?:\d/.test(_get_innerText.call(this)) ) {
  2793. _console.log('Anti-Adblock killed.');
  2794. return true;
  2795. }
  2796. _set_innerHTML.apply(this, args);
  2797. };
  2798. Object.defineProperty(_Element, 'innerHTML', _innerHTML);
  2799. Object.defineProperty(win, 'adblock', {
  2800. get: () => false,
  2801. set: () => null,
  2802. enumerable: true
  2803. });
  2804. let _$ = {};
  2805. let _$_map = new WeakMap();
  2806. let _gOPD = Object.getOwnPropertyDescriptor(Object, 'getOwnPropertyDescriptor');
  2807. let _val_gOPD = _gOPD.value;
  2808. _gOPD.value = function(...args) {
  2809. let _res = _val_gOPD.apply(this, args);
  2810. if (args[0] instanceof Window && (args[1] === '$' || args[1] === 'jQuery')) {
  2811. delete _res.get;
  2812. delete _res.set;
  2813. _res.value = win[args[1]];
  2814. }
  2815. return _res;
  2816. };
  2817. Object.defineProperty(Object, 'getOwnPropertyDescriptor', _gOPD);
  2818. let getJQWrap = (n) => {
  2819. let name = n;
  2820. return {
  2821. enumerable: true,
  2822. get: () => _$[name],
  2823. set: x => {
  2824. if (_$_map.has(x)) {
  2825. _$[name] = _$_map.get(x);
  2826. return true;
  2827. }
  2828. if (x === _$.$ || x === _$.jQuery) {
  2829. _$[name] = x;
  2830. return true;
  2831. }
  2832. _$[name] = new Proxy(x, {
  2833. apply: (t, o, args) => {
  2834. let _res = t.apply(o, args);
  2835. if (_$_map.has(_res.is))
  2836. _res.is = _$_map.get(_res.is);
  2837. else {
  2838. let _is = _res.is;
  2839. _res.is = function(...args) {
  2840. if (args[0] === ':hidden')
  2841. return false;
  2842. return _is.apply(this, args);
  2843. };
  2844. _$_map.set(_is, _res.is);
  2845. }
  2846. return _res;
  2847. }
  2848. });
  2849. _$_map.set(x, _$[name]);
  2850. return true;
  2851. }
  2852. };
  2853. };
  2854. Object.defineProperty(win, '$', getJQWrap('$'));
  2855. Object.defineProperty(win, 'jQuery', getJQWrap('jQuery'));
  2856. let _dP = Object.defineProperty;
  2857. Object.defineProperty = function(...args) {
  2858. if (args[0] instanceof Window && (args[1] === '$' || args[1] === 'jQuery'))
  2859. return void 0;
  2860. return _dP.apply(this, args);
  2861. };
  2862. })
  2863. };
  2864.  
  2865. scripts['igra-prestoloff.cx'] = () => scriptLander(() => {
  2866. let nt = new nullTools();
  2867. /*jslint evil: true */ // yes, evil, I know
  2868. let _write = _document.write.bind(_document);
  2869. /*jslint evil: false */
  2870. nt.define(_document, 'write', t => {
  2871. let id = t.match(/jwplayer\("(\w+)"\)/i);
  2872. if (id && id[1])
  2873. return _write(`<div id="${id[1]}"></div>${t}`);
  2874. return _write('');
  2875. });
  2876. });
  2877.  
  2878. scripts['imageban.ru'] = () => { Object.defineProperty(win, 'V7x1J', { get: () => null }); };
  2879.  
  2880. scripts['ivi.ru'] = () => {
  2881. let _xhr_open = win.XMLHttpRequest.prototype.open;
  2882. win.XMLHttpRequest.prototype.open = function(method, url, ...args) {
  2883. if (typeof url === 'string')
  2884. if (url.endsWith('/track'))
  2885. return;
  2886. return _xhr_open.call(this, method, url, ...args);
  2887. };
  2888. let _responseText = Object.getOwnPropertyDescriptor(XMLHttpRequest.prototype, 'responseText');
  2889. let _responseText_get = _responseText.get;
  2890. _responseText.get = function() {
  2891. if (this.__responseText__)
  2892. return this.__responseText__;
  2893. let res = _responseText_get.apply(this, arguments);
  2894. let o;
  2895. try {
  2896. if (res)
  2897. o = JSON.parse(res);
  2898. } catch(ignore) {};
  2899. let changed = false;
  2900. if (o && o.result) {
  2901. if (o.result instanceof Array &&
  2902. 'adv_network_logo_url' in o.result[0]) {
  2903. o.result = [];
  2904. changed = true;
  2905. }
  2906. if (o.result.show_adv) {
  2907. o.result.show_adv = false;
  2908. changed = true;
  2909. }
  2910. }
  2911. if (changed) {
  2912. _console.log('changed response >>', o);
  2913. res = JSON.stringify(o);
  2914. }
  2915. this.__responseText__ = res;
  2916. return res;
  2917. };
  2918. Object.defineProperty(XMLHttpRequest.prototype, 'responseText', _responseText);
  2919. };
  2920.  
  2921. scripts['kinopoisk.ru'] = () => {
  2922. selectiveCookies('bltsr|cmtchd|crookie|kpunk');
  2923. // set no-branding body style and adjust other blocks on the page
  2924. let style = [
  2925. '.app__header.app__header_margin-bottom_brand, #top { margin-bottom: 20px !important }',
  2926. '.app__branding { display: none !important}'
  2927. ];
  2928. if (location.hostname === 'www.kinopoisk.ru' && !location.pathname.startsWith('/games/'))
  2929. style.push('html:not(#id), body:not(#id), .app-container { background: #d5d5d5 url(/images/noBrandBg.jpg) 50% 0 no-repeat !important }');
  2930. createStyle(style);
  2931. // catch branding and other things
  2932. let _KP = void 0;
  2933. Object.defineProperty(win, 'KP', {
  2934. get: () => _KP,
  2935. set: val => {
  2936. if (_KP === val)
  2937. return true;
  2938. _KP = new Proxy(val, {
  2939. set: (kp, name, val) => {
  2940. if (name === 'branding') {
  2941. kp[name] = new Proxy({ weborama: {} }, {
  2942. get: (kp, name) => name in kp ? kp[name] : '',
  2943. set: () => true
  2944. });
  2945. return true;
  2946. }
  2947. if (name === 'config')
  2948. val = new Proxy(val, {
  2949. set: (cfg, name, val) => {
  2950. if (name === 'anContextUrl')
  2951. return true;
  2952. if (name === 'adfoxEnabled' || name === 'hasBranding')
  2953. val = false;
  2954. if (name === 'adfoxVideoAdUrls')
  2955. val = {flash:{}, html:{}};
  2956. cfg[name] = val;
  2957. return true;
  2958. }
  2959. });
  2960. kp[name] = val;
  2961. return true;
  2962. }
  2963. });
  2964. _console.log('KP =', val);
  2965. }
  2966. });
  2967. // skip branding and some other junk
  2968. Object.defineProperty(win, 'advBlock', {
  2969. get: () => () => null,
  2970. set: () => true
  2971. });
  2972. // skip timeout check for blocked requests
  2973. let _setTimeout = Function.prototype.apply.bind(win.setTimeout);
  2974. let _toString = Function.prototype.apply.bind(Function.prototype.toString);
  2975. win.setTimeout = function(...args) {
  2976. if (args[1] === 100) {
  2977. let str = _toString(args[0]);
  2978. if (str.endsWith('{a()}') || str.endsWith('{n()}'))
  2979. return;
  2980. }
  2981. return _setTimeout(this, args);
  2982. };
  2983. };
  2984.  
  2985. scripts['kinozal-tv.appspot.com'] = {
  2986. other: ['a-dot-kinozal-tv.appspot.com'],
  2987. now: () => {
  2988. // They check if 'startsWith' in String.prototype
  2989. // and skip parts of ABP detector if it's not there
  2990. delete String.prototype.startsWith;
  2991. }
  2992. };
  2993.  
  2994. scripts['korrespondent.net'] = {
  2995. now: () => scriptLander(() => {
  2996. let nt = new nullTools();
  2997. nt.define(win, 'holder', function(id) {
  2998. let div = _document.getElementById(id);
  2999. if (!div)
  3000. return;
  3001. if (div.parentNode.classList.contains('col__sidebar')) {
  3002. div.parentNode.appendChild(div);
  3003. div.style.height = '300px';
  3004. }
  3005. });
  3006. }, nullTools),
  3007. dom: () => {
  3008. for (let frame of _document.querySelectorAll('.unit-side-informer > iframe'))
  3009. frame.parentNode.style.width = '1px';
  3010. }
  3011. };
  3012.  
  3013. scripts['liveinternet.ru'] = () => {
  3014. setYa('gXwM');
  3015. };
  3016.  
  3017. scripts['mail.ru'] = {
  3018. other: ['ok.ru'],
  3019. now: () => {
  3020. selectiveCookies('act|s|t|p|testcookie');
  3021. scriptLander(() => {
  3022. let nt = new nullTools();
  3023. // Trick to prevent mail.ru from removing 3rd-party styles
  3024. nt.define(Object.prototype, 'restoreVisibility', nt.func(null), false);
  3025. // Disable some of their counters
  3026. nt.define(win, 'rb_counter', nt.func(null, 'rb_counter'));
  3027. if (location.hostname === 'e.mail.ru')
  3028. nt.define(win, 'aRadar', nt.func(null, 'aRadar'));
  3029. else
  3030. nt.define(win, 'createRadar', nt.func(nt.func(null, 'aRadar'), 'createRadar'));
  3031.  
  3032. {
  3033. let missingCheck = {
  3034. get: (obj, name) => {
  3035. if (!(name in obj))
  3036. _console.warn(obj, 'missing:', name);
  3037. return obj[name];
  3038. }
  3039. };
  3040. let skipLog = (name, ret) => (...args) => (_console.log(`Skip ${name}(`, ...args, ')'), ret);
  3041. let createSkipLogObject = (baseName, list) => list.reduce(
  3042. (acc, cur) => (acc[cur] = skipLog(`${baseName}.${cur}`), acc),
  3043. {}
  3044. );
  3045. let redefiner = {
  3046. apply: (target, thisArg, args) => {
  3047. let res = void 0;
  3048. if (target._name === 'mrg-smokescreen/Welter')
  3049. res = {
  3050. isWelter: () => true,
  3051. wrap: skipLog(`${target._name}.wrap`)
  3052. };
  3053. if (target._name === 'mrg-smokescreen/StyleSheets')
  3054. res = createSkipLogObject(target._name, ['update', 'remove', 'insert', 'setup']);
  3055. if (target._name === 'mrg-honeypot/main')
  3056. res = { check: skipLog(`${target._name}.check`, false) };
  3057. if (target._name.startsWith('advert/rb/slot')) {
  3058. res = createSkipLogObject(target._name, ['get', 'getHTML', 'createBlock', 'onRedirect']);
  3059. res.slot = '0';
  3060. }
  3061. if (target._name.startsWith('OK/banners/'))
  3062. res = createSkipLogObject(target._name, ['activate', 'deactivate']);
  3063. if (target._name === 'mimic') {
  3064. res = createSkipLogObject(target._name, ['insertDirect', 'setup']);
  3065. res.version = "%PACKAGE_VERSION%";
  3066. }
  3067. if (target._name === 'advert/adman/adman')
  3068. res = createSkipLogObject(target._name, ['refresh', 'getBlock', 'init']);
  3069. if (res)
  3070. res = new Proxy(res, missingCheck);
  3071. else
  3072. res = target.apply(thisArg, args);
  3073. if (target._name === 'mrg-smokescreen/Utils')
  3074. res.extend = function(...args) {
  3075. let res = {
  3076. enable: false,
  3077. match: [],
  3078. links: []
  3079. };
  3080. _console.log(`${target._name}.extend(`, ...args, ') >>', res );
  3081. return res;
  3082. };
  3083. if (target._name === 'advert/RB') {
  3084. res.getSlots = () => [];
  3085. res.load._name = target._name + '.load';
  3086. res.load = new Proxy(res.load, redefiner);
  3087. }
  3088. _console.log(target._name, '(',...args,') >>', res);
  3089. return res;
  3090. }
  3091. };
  3092.  
  3093. let wrapAdFuncs = {
  3094. apply: (target, thisArg, args) => {
  3095. let module = args[0];
  3096. if (typeof module === 'string')
  3097. if (module.startsWith('mrg-smoke') ||
  3098. module.startsWith('mrg-context') ||
  3099. module.startsWith('mrg-honeypot') ||
  3100. module.startsWith('advert') ||
  3101. module.startsWith('mimic') ||
  3102. module.startsWith('OK/banner') ||
  3103. module === 'OK/Smokescreen') {
  3104. let fun = args[args.length-1];
  3105. fun._name = module;
  3106. args[args.length-1] = new Proxy(fun, redefiner);
  3107. }// else
  3108. // _console.log('Define:', args[0]);
  3109. return target.apply(thisArg, args);
  3110. }
  3111. };
  3112. let wrapDefine = def => {
  3113. if (!def)
  3114. return;
  3115. _console.log('define =', def);
  3116. def = new Proxy(def, wrapAdFuncs);
  3117. def._name = 'define';
  3118. return def;
  3119. };
  3120. let _define = wrapDefine(win.define);
  3121. Object.defineProperty(win, 'define', {
  3122. get: () => _define,
  3123. set: x => {
  3124. if (_define === x)
  3125. return true;
  3126. _define = wrapDefine(x);
  3127. return true;
  3128. }
  3129. });
  3130. }
  3131.  
  3132. // Disable page scrambler on mail.ru to let extensions easily block ads there
  3133. let logger = {
  3134. apply: (target, thisArg, args) => {
  3135. let res = target.apply(thisArg, args);
  3136. _console.log(`${target._name}(`, ...args, `) >>`, res);
  3137. return res;
  3138. }
  3139. };
  3140.  
  3141. let _locator;
  3142. function wrapLocator(locator) {
  3143. if ('setup' in locator) {
  3144. let _setup = locator.setup;
  3145. locator.setup = function(o) {
  3146. if ('enable' in o) {
  3147. o.enable = false;
  3148. _console.log('Disable mimic mode.');
  3149. }
  3150. if ('links' in o) {
  3151. o.links = [];
  3152. _console.log('Call with empty list of sheets.');
  3153. }
  3154. return _setup.call(this, o);
  3155. };
  3156. locator.insertSheet = () => false;
  3157. locator.wrap = () => false;
  3158. }
  3159. try {
  3160. let names = [];
  3161. for (let name in locator)
  3162. if (locator[name] instanceof Function && name !== 'transform') {
  3163. locator[name]._name = "locator." + name;
  3164. locator[name] = new Proxy(locator[name], logger);
  3165. names.push(name);
  3166. }
  3167. _console.log(`[locator] wrapped properties: ${names.length ? names.join(', ') : '[empty]'}`);
  3168. } catch(e) {
  3169. _console.log(e);
  3170. }
  3171. _locator = locator;
  3172. }
  3173.  
  3174. function defineLocator(root) {
  3175. let loc_desc = Object.getOwnPropertyDescriptor(root, 'locator');
  3176. if (!loc_desc || loc_desc.set !== wrapLocator)
  3177. try {
  3178. Object.defineProperty(root, 'locator', {
  3179. set: wrapLocator,
  3180. get: () => _locator
  3181. });
  3182. } catch (err) {
  3183. _console.log('Unable to redefine "locator" object!!!', err);
  3184. }
  3185. }
  3186.  
  3187. let _honeyPot;
  3188. function defineDetector(mr) {
  3189. let __ = mr._ || {};
  3190. let setHoneyPot = o => {
  3191. if (!o || o === _honeyPot) return;
  3192. _console.log('[honeyPot]', o);
  3193. _honeyPot = function() {
  3194. this.check = new Proxy(() => {
  3195. __.STUCK_IN_POT = false;
  3196. return false;
  3197. }, logger);
  3198. this.check._name = 'honeyPot.check';
  3199. this.destroy = () => null;
  3200. };
  3201. };
  3202. if ('honeyPot' in mr)
  3203. setHoneyPot(mr.honeyPot);
  3204. else
  3205. Object.defineProperty(mr, 'honeyPot', {
  3206. get: () => _honeyPot,
  3207. set: setHoneyPot
  3208. });
  3209.  
  3210. __ = new Proxy(__, {
  3211. get: (t, p) => t[p],
  3212. set: (t, p, v) => {
  3213. _console.log(`mr._.${p} =`, v);
  3214. t[p] = v;
  3215. return true;
  3216. }
  3217. });
  3218. mr._ = __;
  3219. }
  3220.  
  3221. function defineAdd(mr) {
  3222. let _add;
  3223. let addWrapper = {
  3224. apply: (tgt, that, args) => {
  3225. let module = args[0];
  3226. if (typeof module === 'string' && module.startsWith('ad')) {
  3227. _console.log('Skip module:', module);
  3228. return;
  3229. }
  3230. if (typeof module === 'object' && module.name.startsWith('ad'))
  3231. _console.log('Loaded module:', module);
  3232. return logger.apply(tgt, that, args);
  3233. }
  3234. };
  3235. let setMrAdd = v => {
  3236. if (!v) return;
  3237. v._name = 'mr.add';
  3238. v = new Proxy(v, addWrapper);
  3239. _add = v;
  3240. };
  3241. if ('add' in mr)
  3242. setMrAdd(mr.add);
  3243. Object.defineProperty(mr, 'add', {
  3244. get: () => _add,
  3245. set: setMrAdd
  3246. });
  3247.  
  3248. }
  3249.  
  3250. let _mr_wrapper = vl => {
  3251. defineLocator(vl.mimic ? vl.mimic : vl);
  3252. defineDetector(vl);
  3253. defineAdd(vl);
  3254. return vl;
  3255. };
  3256. if ('mr' in win) {
  3257. _console.log('Found existing "mr" object.');
  3258. win.mr = _mr_wrapper(win.mr);
  3259. } else {
  3260. let _mr = void 0;
  3261. Object.defineProperty(win, 'mr', {
  3262. get: () => _mr,
  3263. set: vl => { _mr = _mr_wrapper(vl) },
  3264. configurable: true
  3265. });
  3266. let _defineProperty = Function.prototype.apply.bind(Object.defineProperty);
  3267. Object.defineProperty = function defineProperty(o, name, conf) {
  3268. if (name === 'mr' && o instanceof Window) {
  3269. _console.warn('Object.defineProperty(', ...arguments, ')');
  3270. conf.set(_mr_wrapper(conf.get()));
  3271. }
  3272. if ((name === 'honeyPot' || name === 'add') && _mr === o && conf.set)
  3273. return;
  3274. return _defineProperty(this, arguments);
  3275. };
  3276. }
  3277.  
  3278. // smokyTools wrapper for news.mail.ru
  3279. nt.define(win, 'smokyTools', nt.proxy({
  3280. getDict: nt.func(nt.proxy({}, 'smokyTools.getDict', null), 'smokyTools.getDict'),
  3281. CSS: nt.func(nt.proxy({}, 'smokyTools.CSS', null), 'smokyTools.CSS')
  3282. }, 'smokyTools', null));
  3283. nt.define(win, 'smoky', nt.func(null, 'smoky'));
  3284. nt.define(win, 'smokySingleElement', nt.func(null, 'smokySingleElement'));
  3285. nt.define(win, 'smokyByClass', nt.func(null, 'smokyByClass'));
  3286. }, nullTools);
  3287. }
  3288. };
  3289.  
  3290. scripts['oms.matchat.online'] = () => scriptLander(() => {
  3291. let _rmpGlobals = void 0;
  3292. Object.defineProperty(win, 'rmpGlobals', {
  3293. get: () => _rmpGlobals,
  3294. set: x => {
  3295. if (x === _rmpGlobals)
  3296. return true;
  3297. _rmpGlobals = new Proxy(x, {
  3298. get: (obj, name) => {
  3299. if (name === 'adBlockerDetected')
  3300. return false;
  3301. return obj[name];
  3302. },
  3303. set: (obj, name, val) => {
  3304. if (name === 'adBlockerDetected')
  3305. _console.warn('rmpGlobals.adBlockerDetected =', val)
  3306. else
  3307. obj[name] = val;
  3308. return true;
  3309. }
  3310. });
  3311. }
  3312. });
  3313. });
  3314.  
  3315. scripts['megogo.net'] = {
  3316. now: () => {
  3317. let nt = new nullTools();
  3318. nt.define(win, 'adBlock', false);
  3319. nt.define(win, 'showAdBlockMessage', nt.func(null));
  3320. }
  3321. };
  3322.  
  3323. scripts['naruto-base.su'] = () => gardener('div[id^="entryID"],.block', /href="http.*?target="_blank"/i);
  3324.  
  3325. scripts['newdeaf-online.net'] = {
  3326. dom: () => {
  3327. let adNodes = _document.querySelectorAll('.ads');
  3328. if (!adNodes)
  3329. return;
  3330. let getter = x => {
  3331. let val = x;
  3332. return () => (_console.warn('read .ads', name, val), val);
  3333. };
  3334. let setter = x => _console.warn('skip write .ads', name, x);
  3335. for (let adNode of adNodes)
  3336. for (let name of ['innerHTML'])
  3337. Object.defineProperty(adNode, name, {
  3338. get: getter(ads[name]),
  3339. set: setter
  3340. });
  3341. }
  3342. };
  3343.  
  3344. scripts['overclockers.ru'] = {
  3345. dom: () => scriptLander(() => {
  3346. let killed = () => _console.warn('Anti-Adblock killed.');
  3347. if ('$' in win)
  3348. win.$ = new Proxy($, {
  3349. apply: (tgt, that, args) => {
  3350. let res = tgt.apply(that, args);
  3351. if (res[0] && res[0] === _document.body) {
  3352. res.html = killed;
  3353. res.empty = killed;
  3354. }
  3355. return res;
  3356. }
  3357. });
  3358. })
  3359. };
  3360. scripts['forums.overclockers.ru'] = {
  3361. now: () => {
  3362. createStyle('.needblock {position: fixed; left: -10000px}');
  3363. Object.defineProperty(win, 'adblck', {
  3364. get: () => 'no',
  3365. set: () => undefined,
  3366. enumerable: true
  3367. });
  3368. }
  3369. };
  3370.  
  3371. scripts['pb.wtf'] = {
  3372. other: ['piratbit.org', 'piratbit.ru'],
  3373. dom: () => {
  3374. // line above topic content and images in the slider in the header
  3375. let remove = node => (_console.log('removed', node), node.parentNode.removeChild(node));
  3376. for (let el of _document.querySelectorAll('.release-block-img a, #page_content a')) {
  3377. if (location.hostname === el.hostname &&
  3378. /^\/(\w{3}|exit)\/[\w=/]{20,}$/.test(el.pathname)) {
  3379. remove(el.closest('div, tr'));
  3380. continue;
  3381. }
  3382. // ads in the topic header in case filter above wasn't enough
  3383. let parent = el.closest('tr');
  3384. if (parent) {
  3385. let span = (parent.querySelector('span') || {}).textContent;
  3386. span && span.startsWith('YO!') && remove(parent);
  3387. }
  3388. }
  3389. // casino ad button in random places
  3390. for (let el of _document.querySelectorAll('.btn-group')) {
  3391. el = el.parentNode;
  3392. if (el.tagName === 'CENTER')
  3393. remove(el.parentNode);
  3394. }
  3395. // ads in comments
  3396. let el = _document.querySelector('thead + tbody[id^="post_"] + tbody[class*=" "]');
  3397. if (el && el.parentNode.children[2] == el)
  3398. remove(el);
  3399. }
  3400. };
  3401.  
  3402. scripts['pikabu.ru'] = () => gardener('.story', /story__author[^>]+>ads</i, {root: '.inner_wrap', observe: true});
  3403.  
  3404. scripts['peka2.tv'] = () => {
  3405. let bodyClass = 'body--branding';
  3406. let checkNode = node => {
  3407. for (let className of node.classList)
  3408. if (className.includes('banner') || className === bodyClass) {
  3409. _removeAttribute(node, 'style');
  3410. node.classList.remove(className);
  3411. for (let attr of Array.from(node.attributes))
  3412. if (attr.name.startsWith('advert'))
  3413. _removeAttribute(node, attr.name);
  3414. }
  3415. };
  3416. (new MutationObserver(ms => {
  3417. let m, node;
  3418. for (m of ms) for (node of m.addedNodes)
  3419. if (node instanceof HTMLElement)
  3420. checkNode(node);
  3421. })).observe(_de, {childList: true, subtree: true});
  3422. (new MutationObserver(ms => {
  3423. for (let m of ms)
  3424. checkNode(m.target);
  3425. })).observe(_de, {attributes: true, subtree: true, attributeFilter: ['class']});
  3426. };
  3427.  
  3428. scripts['qrz.ru'] = {
  3429. now: () => {
  3430. let nt = new nullTools();
  3431. nt.define(win, 'ab', false);
  3432. nt.define(win, 'tryMessage', nt.func(null));
  3433. }
  3434. };
  3435.  
  3436. scripts['razlozhi.ru'] = {
  3437. now: () => {
  3438. setYa('vpsU');
  3439. for (let func of ['createShadowRoot', 'attachShadow'])
  3440. if (func in _Element)
  3441. _Element[func] = function(){
  3442. return this.cloneNode();
  3443. };
  3444. }
  3445. };
  3446.  
  3447. scripts['rbc.ru'] = {
  3448. other: ['autonews.ru', 'rbcplus.ru', 'sportrbc.ru'],
  3449. now: () => {
  3450. selectiveCookies('adb_on');
  3451. let _RA = void 0;
  3452. let setArgs = {
  3453. 'showBanners': true,
  3454. 'showAds': true,
  3455. 'banners.staticPath': '',
  3456. 'paywall.staticPath': '',
  3457. 'banners.dfp.config': [],
  3458. 'banners.dfp.pageTargeting': () => null,
  3459. };
  3460. Object.defineProperty(win, 'RA', {
  3461. get: () => _RA,
  3462. set: vl => {
  3463. _console.log('RA =', vl);
  3464. if ('repo' in vl) {
  3465. _console.log('RA.repo =', vl.repo);
  3466. vl.repo = new Proxy(vl.repo, {
  3467. set: (o, name, val) => {
  3468. if (name === 'banner') {
  3469. _console.log(`RA.repo.${name} =`, val);
  3470. val = new Proxy(val, {
  3471. get: (o, name) => {
  3472. let res = o[name];
  3473. if (typeof o[name] === 'function') {
  3474. res = () => null;
  3475. res.toString = o[name].toString.bind(o[name]);
  3476. }
  3477. if (name === 'isInited')
  3478. res = true;
  3479. _console.warn(`get RA.repo.banner.${name}`, res);
  3480. return res;
  3481. }
  3482. });
  3483. }
  3484. o[name] = val;
  3485. return true;
  3486. }
  3487. });
  3488. } else
  3489. _console.log('Unable to locate RA.repo');
  3490. _RA = new Proxy(vl, {
  3491. set: (o, name, val) => {
  3492. if (name === 'config') {
  3493. _console.log('RA.config =', val);
  3494. if ('set' in val) {
  3495. val.set = new Proxy(val.set, {
  3496. apply: (set, that, args) => {
  3497. let name = args[0];
  3498. if (name in setArgs)
  3499. args[1] = setArgs[name];
  3500. if (name in setArgs || name === 'checkad')
  3501. _console.log('RA.config.set(', ...args, ')');
  3502. return Reflect.apply(set, that, args);
  3503. }
  3504. });
  3505. val.set('showAds', true); // pretend ads already were shown
  3506. }
  3507. }
  3508. o[name] = val;
  3509. return true;
  3510. }
  3511. });
  3512. }
  3513. });
  3514. Object.defineProperty(win, 'bannersConfig', {
  3515. get: () => [], set: () => null
  3516. });
  3517. // pretend there is a paywall landing on screen already
  3518. let pwl = _document.createElement('div');
  3519. pwl.style.display = 'none';
  3520. pwl.className = 'js-paywall-landing';
  3521. _document.documentElement.appendChild(pwl);
  3522. // detect and skip execution of one of the ABP detectors
  3523. let _setTimeout = Function.prototype.apply.bind(win.setTimeout);
  3524. let _toString = Function.prototype.call.bind(Function.prototype.toString);
  3525. win.setTimeout = function setTimeout() {
  3526. if (typeof arguments[0] === 'function') {
  3527. let fts = _toString(arguments[0]);
  3528. if (/\.length\s*>\s*0\s*&&/.test(fts) && /:hidden/.test(fts)) {
  3529. _console.log('Skipped setTimout(', fts, arguments[1], ')');
  3530. return;
  3531. }
  3532. }
  3533. return _setTimeout(this, arguments);
  3534. };
  3535. // hide banner placeholders
  3536. createStyle('[data-banner-id], .banner__container, .banners__yandex__article { display: none !important }');
  3537. },
  3538. dom: () => {
  3539. // hide sticky banner place at the top of the page
  3540. for (let itm of _document.querySelectorAll('.l-sticky'))
  3541. if (itm.querySelector('.banner__container__link'))
  3542. itm.style.display = 'none';
  3543. }
  3544. };
  3545.  
  3546. scripts['rp5.ru'] = {
  3547. other: ['rp5.by', 'rp5.kz', 'rp5.ua'],
  3548. now: () => {
  3549. Object.defineProperty(win, 'sContentBottom', {
  3550. get: () => '',
  3551. set: () => true
  3552. });
  3553. },
  3554. dom: () => {
  3555. let node = selectNodeByTextContent('Разместить текстовое объявление', { root: _de.querySelector('#content-wrapper'), shallow: true });
  3556. if (node)
  3557. node.style.display = 'none';
  3558. }
  3559. };
  3560.  
  3561. scripts['rutube.ru'] = () => scriptLander(() => {
  3562. let _parse = JSON.parse;
  3563. let _skip_enabled = false;
  3564. JSON.parse = (...args) => {
  3565. let res = _parse(...args),
  3566. log = false;
  3567. if (!res)
  3568. return res;
  3569. // parse player configuration
  3570. if ('appearance' in res || 'video_balancer' in res) {
  3571. log = true;
  3572. if (res.appearance) {
  3573. if ('forbid_seek' in res.appearance && res.appearance.forbid_seek)
  3574. res.appearance.forbid_seek = false;
  3575. if ('forbid_timeline_preview' in res.appearance && res.appearance.forbid_timeline_preview)
  3576. res.appearance.forbid_timeline_preview = false;
  3577. }
  3578. _skip_enabled = !!res.remove_unseekable_blocks;
  3579. //res.advert = [];
  3580. delete res.advert;
  3581. //for (let limit of res.limits)
  3582. // limit.limit = 0;
  3583. delete res.limits;
  3584. //res.yast = null;
  3585. //res.yast_live_online = null;
  3586. delete res.yast;
  3587. delete res.yast_live_online;
  3588. Object.defineProperty(res, 'stat', {
  3589. get: () => [],
  3590. set: () => true,
  3591. enumerable: true
  3592. });
  3593. }
  3594.  
  3595. // parse video configuration
  3596. if ('video_url' in res) {
  3597. log = true;
  3598. if (res.cuepoints && !_skip_enabled)
  3599. for (let point of res.cuepoints) {
  3600. point.is_pause = false;
  3601. point.show_navigation = true;
  3602. point.forbid_seek = false;
  3603. }
  3604. }
  3605.  
  3606. if (log)
  3607. _console.log('[rutube]', res);
  3608. return res;
  3609. };
  3610. });
  3611.  
  3612. scripts['simpsonsua.com.ua'] = () => scriptLander(() => {
  3613. let _addEventListener = _Document.addEventListener;
  3614. _document.addEventListener = function(event, callback) {
  3615. if (event === 'DOMContentLoaded' && callback.toString().includes('show_warning'))
  3616. return;
  3617. return _addEventListener.apply(this, arguments);
  3618. };
  3619. });
  3620.  
  3621. scripts['smotret-anime.ru'] = () => scriptLander(() => {
  3622. deepWrapAPI(root => {
  3623. let _pause = root.Function.prototype.call.bind(root.Audio.prototype.pause);
  3624. let _addEventListener = root.Function.prototype.call.bind(root.Element.prototype.addEventListener);
  3625. let stopper = e => _pause(e.target);
  3626. root.Audio = new Proxy(root.Audio, {
  3627. construct: (audio, args) => {
  3628. let res = new audio(...args);
  3629. _addEventListener(res, 'play', stopper, true);
  3630. return res;
  3631. }
  3632. });
  3633. _createElement = root.Document.prototype.createElement;
  3634. root.Document.prototype.createElement = function createElement() {
  3635. let res = _createElement.apply(this, arguments);
  3636. if (res instanceof HTMLAudioElement)
  3637. _addEventListener(res, 'play', stopper, true);
  3638. return res;
  3639. };
  3640. });
  3641. }, deepWrapAPI);
  3642.  
  3643. scripts['spaces.ru'] = () => {
  3644. gardener('div:not(.f-c_fll) > a[href*="spaces.ru/?Cl="]', /./, { parent: 'div' });
  3645. gardener('.js-banner_rotator', /./, { parent: '.widgets-group' });
  3646. };
  3647.  
  3648. scripts['spam-club.blogspot.co.uk'] = () => {
  3649. let _clientHeight = Object.getOwnPropertyDescriptor(_Element, 'clientHeight'),
  3650. _clientWidth = Object.getOwnPropertyDescriptor(_Element, 'clientWidth');
  3651. let wrapGetter = (getter) => {
  3652. let _getter = getter;
  3653. return function() {
  3654. let _size = _getter.apply(this, arguments);
  3655. return _size ? _size : 1;
  3656. };
  3657. };
  3658. _clientHeight.get = wrapGetter(_clientHeight.get);
  3659. _clientWidth.get = wrapGetter(_clientWidth.get);
  3660. Object.defineProperty(_Element, 'clientHeight', _clientHeight);
  3661. Object.defineProperty(_Element, 'clientWidth', _clientWidth);
  3662. let _onload = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'onload'),
  3663. _set_onload = _onload.set;
  3664. _onload.set = function() {
  3665. if (this instanceof HTMLImageElement)
  3666. return true;
  3667. _set_onload.apply(this, arguments);
  3668. };
  3669. Object.defineProperty(HTMLElement.prototype, 'onload', _onload);
  3670. };
  3671.  
  3672. scripts['sport-express.ru'] = () => gardener('.js-relap__item',/>Реклама\s+<\//, {root:'.container', observe: true});
  3673.  
  3674. scripts['sports.ru'] = {
  3675. now: () => {
  3676. gardener('.aside-news-list__item', /aside-news-list__advert/i, {root:'.columns-layout__left', observe: true});
  3677. gardener('.material-list__item', /Реклама/i, {root:'.columns-layout', observe: true});
  3678. // extra functionality: shows/hides panel at the top depending on scroll direction
  3679. createStyle([
  3680. '.user-panel__fixed { transition: top 0.2s ease-in-out!important; }',
  3681. '.user-panel-up { top: -40px!important }'
  3682. ], {id: 'userPanelSlide'}, false);
  3683. },
  3684. dom: () => {
  3685. (function lookForPanel() {
  3686. let panel = _document.querySelector('.user-panel__fixed');
  3687. if (!panel)
  3688. setTimeout(lookForPanel, 100);
  3689. else
  3690. window.addEventListener(
  3691. 'wheel', function(e) {
  3692. if (e.deltaY > 0 && !panel.classList.contains('user-panel-up'))
  3693. panel.classList.add('user-panel-up');
  3694. else if (e.deltaY < 0 && panel.classList.contains('user-panel-up'))
  3695. panel.classList.remove('user-panel-up');
  3696. }, false
  3697. );
  3698. })();
  3699. }
  3700. };
  3701.  
  3702. scripts['stealthz.ru'] = {
  3703. dom: () => {
  3704. // skip timeout
  3705. let $ = _document.querySelector.bind(_document);
  3706. let [timer_1, timer_2] = [$('#timer_1'), $('#timer_2')];
  3707. if (!timer_1 || !timer_2)
  3708. return;
  3709. timer_1.style.display = 'none';
  3710. timer_2.style.display = 'block';
  3711. }
  3712. };
  3713.  
  3714. scripts['xittv.net'] = () => scriptLander(() => {
  3715. let logNames = ['setup', 'trigger', 'on', 'off', 'onReady', 'onError', 'getConfig', 'addPlugin', 'getAdBlock'];
  3716. let skipEvents = ['adComplete', 'adSkipped', 'adBlock', 'adRequest', 'adMeta', 'adImpression', 'adError', 'adTime', 'adStarted', 'adClick'];
  3717. let _jwplayer = void 0;
  3718. Object.defineProperty(win, 'jwplayer', {
  3719. get: () => _jwplayer,
  3720. set: x => {
  3721. _jwplayer = new Proxy(x, {
  3722. apply: (fun, that, args) => {
  3723. let res = fun.apply(that, args);
  3724. res = new Proxy(res, {
  3725. get: (obj, name) => {
  3726. if (logNames.includes(name) && obj[name] instanceof Function)
  3727. return new Proxy(obj[name], {
  3728. apply: (fun, that, args) => {
  3729. if (name === 'setup') {
  3730. let o = args[0];
  3731. if (o)
  3732. delete o.advertising;
  3733. }
  3734. if (name === 'on' || name === 'trigger') {
  3735. let events = typeof args[0] === 'string' ? args[0].split(" ") : null;
  3736. if (events.length === 1 && skipEvents.includes(events[0]))
  3737. return res;
  3738. if (events.length > 1) {
  3739. let names = [];
  3740. for (let event of events)
  3741. if (!skipEvents.includes(event))
  3742. names.push(event);
  3743. if (names.length > 0)
  3744. args[0] = names.join(" ");
  3745. else
  3746. return res;
  3747. }
  3748. }
  3749. let subres = fun.apply(that, args);
  3750. _console.warn(`jwplayer().${name}(`, ...args, `) >>`, res);
  3751. return subres;
  3752. }
  3753. });
  3754. return obj[name];
  3755. }
  3756. });
  3757. return res;
  3758. }
  3759. });
  3760. _console.log('jwplayer =', x);
  3761. }
  3762. });
  3763. });
  3764.  
  3765. scripts['yap.ru'] = {
  3766. other: ['yaplakal.com'],
  3767. now: () => {
  3768. gardener('form > table[id^="p_row_"]:nth-of-type(2)', /member1438|Administration/);
  3769. gardener('.icon-comments', /member1438|Administration|\/go\/\?http/, {parent:'tr', siblings:-2});
  3770. }
  3771. };
  3772.  
  3773. scripts['rambler.ru'] = {
  3774. other: ['championat.com', 'gazeta.ru', 'lenta.ru', 'media.eagleplatform.com', 'quto.ru', 'rns.online'],
  3775. now: () => {
  3776. selectiveCookies('detect_count');
  3777. scriptLander(() => {
  3778. // Prevent autoplay
  3779. if (!('EaglePlayer' in win)) {
  3780. let _EaglePlayer = void 0;
  3781. Object.defineProperty(win, 'EaglePlayer', {
  3782. enumerable: true,
  3783. get: () => _EaglePlayer,
  3784. set: x => {
  3785. if (x === _EaglePlayer)
  3786. return true;
  3787. _EaglePlayer = new Proxy(x, {
  3788. construct: (targ, args) => {
  3789. let player = new targ(...args);
  3790. if (!player.options) {
  3791. _console.log('EaglePlayer: no options', EaglePlayer);
  3792. return player;
  3793. }
  3794. Object.defineProperty(player.options, 'autoplay', {
  3795. get: () => false,
  3796. set: () => true
  3797. });
  3798. Object.defineProperty(player.options, 'scroll', {
  3799. get: () => false,
  3800. set: () => true
  3801. });
  3802. return player;
  3803. }
  3804. });
  3805. }
  3806. });
  3807. let _setAttribute = Function.prototype.apply.bind(_Element.setAttribute);
  3808. let isAutoplay = /^autoplay$/i;
  3809. _Element.setAttribute = function setAttribute(name) {
  3810. if (!this._stopped && isAutoplay.test(name)) {
  3811. _console.log('Prevented assigning autoplay attribute.');
  3812. return null;
  3813. }
  3814. return _setAttribute(this, arguments);
  3815. };
  3816. } else {
  3817. _console.log('EaglePlayer function already exists.');
  3818. if (inIFrame) {
  3819. let _setAttribute = Function.prototype.apply.bind(_Element.setAttribute);
  3820. let isAutoplay = /^autoplay$/i;
  3821. _Element.setAttribute = function setAttribute(name) {
  3822. if (!this._stopped && isAutoplay.test(name)) {
  3823. _console.log('Prevented assigning autoplay attribute.');
  3824. this._stopped = true;
  3825. this.play = () => {
  3826. _console.log('Prevented attempt to force-start playback.');
  3827. delete this.play;
  3828. };
  3829. return null;
  3830. }
  3831. return _setAttribute(this, arguments);
  3832. };
  3833. }
  3834. }
  3835. if (location.hostname.endsWith('.media.eagleplatform.com'))
  3836. return;
  3837. let nt = new nullTools();
  3838. // Adblock Detector
  3839. let _hidden = void 0;
  3840. Object.defineProperty(win, 'QW50aS1BZEJsb2Nr', {
  3841. set: vl => {
  3842. for (let name in vl) delete vl[name];
  3843. nt.define(vl, 'Detector', nt.proxy({
  3844. getBlockingStatus: () => new Promise(),
  3845. blockingDetectors: [],
  3846. baitURLPrefix: '',
  3847. commonRules: []
  3848. }));
  3849. nt.define(vl, 'isAdBlockFlag', '');
  3850. nt.define(vl, 'ruid', '');
  3851. nt.define(vl, 'user', nt.proxy({
  3852. getOrSetUid: () => null
  3853. }));
  3854. _console.log('Found Adblock Detector.');
  3855. _hidden = vl;
  3856. },
  3857. get: () => _hidden
  3858. });
  3859. // prevent ads from loading
  3860. let blockObfuscated = false;
  3861. let obfuscation = /\[[a-z]{4}\("0x\d+"\)\]/i;
  3862. let _toString = Function.prototype.call.bind(Function.prototype.toString);
  3863. let CSSRuleProto = 'cssText' in CSSRule.prototype ? CSSRule.prototype : CSSStyleRule.prototype;
  3864. let _cssText = Object.getOwnPropertyDescriptor(CSSRuleProto, 'cssText');
  3865. let _cssText_get = _cssText.get;
  3866. _cssText.configurable = false;
  3867. _cssText.get = function() {
  3868. let cssText = _cssText_get.call(this);
  3869. if (cssText.includes('content:')) {
  3870. _console.warn('Blocked access to suspicious cssText:', cssText.slice(0,60), '\u2026', cssText.length);
  3871. blockObfuscated = true;
  3872. return null;
  3873. }
  3874. return cssText;
  3875. };
  3876. Object.defineProperty(CSSRuleProto, 'cssText', _cssText);
  3877. let _setTimeout = win.setTimeout;
  3878. win.setTimeout = function(f) {
  3879. if (blockObfuscated && obfuscation.test(_toString(f))) {
  3880. _console.warn('Stopped setTimeout for:', _toString(f).slice(0,100), '\u2026');
  3881. return null;
  3882. };
  3883. return _setTimeout.apply(this, arguments);
  3884. };
  3885. // fake global Adf object
  3886. let Adf_banner = {};
  3887. [
  3888. 'reloadssp', 'sspScroll',
  3889. 'sspRich', 'ssp'
  3890. ].forEach(name => void(Adf_banner[name] = nt.proxy(() => new Promise(r => r({status: true})))));
  3891. nt.define(win, 'Adf', nt.proxy({
  3892. banner: nt.proxy(Adf_banner)
  3893. }));
  3894. // extra script to remove partner news on gazeta.ru
  3895. if (!location.hostname.includes('gazeta.ru'))
  3896. return;
  3897. (new MutationObserver(
  3898. (ms) => {
  3899. let m, node, header;
  3900. for (m of ms) for (node of m.addedNodes)
  3901. if (node instanceof HTMLDivElement && node.matches('.sausage')) {
  3902. header = node.querySelector('.sausage-header');
  3903. if (header && /новости\s+партн[её]ров/i.test(header.textContent))
  3904. node.style.display = 'none';
  3905. }
  3906. }
  3907. )).observe(_document.documentElement, { childList:true, subtree: true });
  3908. }, `let inIFrame = ${inIFrame}`, nullTools)
  3909. }
  3910. };
  3911.  
  3912. scripts['reactor.cc'] = {
  3913. other: ['joyreactor.cc', 'pornreactor.cc'],
  3914. now: () => {
  3915. selectiveEval();
  3916. scriptLander(() => {
  3917. let nt = new nullTools();
  3918. win.open = function(){
  3919. throw new Error('Redirect prevention.');
  3920. };
  3921. nt.define(win, 'Worker', function(){});
  3922. nt.define(win, 'JRCH', win.CoinHive);
  3923. }, nullTools);
  3924. },
  3925. click: function(e) {
  3926. let node = e.target;
  3927. if (node.nodeType === _Node.ELEMENT_NODE &&
  3928. node.style.position === 'absolute' &&
  3929. node.style.zIndex > 0)
  3930. node.parentNode.removeChild(node);
  3931. },
  3932. dom: function() {
  3933. let tid = void 0;
  3934. function probe() {
  3935. let node = selectNodeByTextContent('блокировщик рекламы');
  3936. if (!node) return;
  3937. while (node.parentNode.offsetHeight < 750 && node !== _document.body)
  3938. node = node.parentNode;
  3939. _setAttribute(node, 'style', 'background:none!important');
  3940. // stop observer
  3941. if (!tid) tid = setTimeout(() => this.disconnect(), 1000);
  3942. }
  3943. (new MutationObserver(probe))
  3944. .observe(_document, { childList:true, subtree:true });
  3945. }
  3946. };
  3947.  
  3948. scripts['auto.ru'] = () => {
  3949. let words = /Реклама|Яндекс.Директ|yandex_ad_/;
  3950. let userAdsListAds = (
  3951. '.listing-list > .listing-item,'+
  3952. '.listing-item_type_fixed.listing-item'
  3953. );
  3954. let catalogAds = (
  3955. 'div[class*="layout_catalog-inline"],'+
  3956. 'div[class$="layout_horizontal"]'
  3957. );
  3958. let otherAds = (
  3959. '.advt_auto,'+
  3960. '.sidebar-block,'+
  3961. '.pager-listing + div[class],'+
  3962. '.card > div[class][style],'+
  3963. '.sidebar > div[class],'+
  3964. '.main-page__section + div[class],'+
  3965. '.listing > tbody'
  3966. );
  3967. gardener(userAdsListAds, words, {root:'.listing-wrap', observe:true});
  3968. gardener(catalogAds, words, {root:'.catalog__page,.content__wrapper', observe:true});
  3969. gardener(otherAds, words);
  3970. };
  3971.  
  3972. scripts['rsload.net'] = {
  3973. load: () => {
  3974. let dis = _document.querySelector('label[class*="cb-disable"]');
  3975. if (dis)
  3976. dis.click();
  3977. },
  3978. click: e => {
  3979. let t = e.target;
  3980. if (t && t.href && (/:\/\/\d+\.\d+\.\d+\.\d+\//.test(t.href)))
  3981. t.href = t.href.replace('://','://rsload.net:rsload.net@');
  3982. }
  3983. };
  3984.  
  3985. let domain;
  3986. // add alternative domain names if present and wrap functions into objects
  3987. for (let name in scripts) {
  3988. if (scripts[name] instanceof Function)
  3989. scripts[name] = { now: scripts[name] };
  3990. for (domain of (scripts[name].other||[])) {
  3991. if (domain in scripts)
  3992. _console.log('Error in scripts list. Script for', name, 'replaced script for', domain);
  3993. scripts[domain] = scripts[name];
  3994. }
  3995. delete scripts[name].other;
  3996. }
  3997. // look for current domain in the list and run appropriate code
  3998. domain = _document.domain;
  3999. while (domain.includes('.')) {
  4000. if (domain in scripts) for (let when in scripts[domain])
  4001. switch(when) {
  4002. case 'now':
  4003. scripts[domain][when]();
  4004. break;
  4005. case 'dom':
  4006. _document.addEventListener('DOMContentLoaded', scripts[domain][when], false);
  4007. break;
  4008. default:
  4009. _document.addEventListener (when, scripts[domain][when], false);
  4010. }
  4011. domain = domain.slice(domain.indexOf('.') + 1);
  4012. }
  4013.  
  4014. // Batch script lander
  4015. if (!skipLander)
  4016. landScript(batchLand, batchPrepend);
  4017.  
  4018. { // JS Fixes Tools Menu
  4019. let openOptions = function() {
  4020. let ovl = _createElement('div'),
  4021. inner = _createElement('div');
  4022. ovl.style = (
  4023. 'position: fixed;'+
  4024. 'top:0; left:0;'+
  4025. 'bottom: 0; right: 0;'+
  4026. 'background: rgba(0,0,0,0.85);'+
  4027. 'z-index: 2147483647;'+
  4028. 'padding: 5em'
  4029. );
  4030. inner.style = (
  4031. 'background: whitesmoke;'+
  4032. 'font-size: 10pt;'+
  4033. 'color: black;'+
  4034. 'padding: 1em'
  4035. );
  4036. inner.textContent = 'JS Fixes Tools';
  4037. inner.appendChild(_createElement('br'));
  4038. inner.appendChild(_createElement('br'));
  4039. ovl.addEventListener(
  4040. 'click', function(e) {
  4041. if (e.target === ovl) {
  4042. ovl.parentNode.removeChild(ovl);
  4043. e.preventDefault();
  4044. }
  4045. e.stopPropagation();
  4046. }, false
  4047. );
  4048.  
  4049. let sObjBtn = _createElement('button');
  4050. sObjBtn.onclick = getStrangeObjectsList;
  4051. sObjBtn.textContent = 'Print (in console) list of unusual window properties';
  4052. inner.appendChild(_createElement('br'));
  4053. inner.appendChild(sObjBtn);
  4054.  
  4055. _document.body.appendChild(ovl);
  4056. ovl.appendChild(inner);
  4057. };
  4058.  
  4059. // monitor keys pressed for Ctrl+Alt+Shift+J > s > f code
  4060. let opPos = 0, opKey = ['KeyJ','KeyS','KeyF'];
  4061. _document.addEventListener(
  4062. 'keydown', function(e) {
  4063. if ((e.code === opKey[opPos] || e.location) &&
  4064. (!!opPos || e.altKey && e.ctrlKey && e.shiftKey)) {
  4065. opPos += e.location ? 0 : 1;
  4066. e.stopPropagation();
  4067. e.preventDefault();
  4068. } else
  4069. opPos = 0;
  4070. if (opPos === opKey.length) {
  4071. opPos = 0;
  4072. openOptions();
  4073. }
  4074. }, false
  4075. );
  4076. }
  4077. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址