RU AdList JS Fixes

try to take over the world!

当前为 2017-10-28 提交的版本,查看 最新版本

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

QingJ © 2025

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