// ==UserScript== // @name 4khd 广告屏蔽 // @namespace https://viayoo.com // @version 0.46 // @description 移除4khd广告 // @author Via // @license MIT // @match *://*.4khd.com/* // @match *://*.xxtt.ink/* // @match *://*.uuss.uk/* // @run-at document-start // @grant unsafeWindow // @grant GM_addStyle // ==/UserScript== (function() { 'use strict'; const AD_SELECTORS = '.exo_wrapper,.popup,.centbtd,.exo-native-widget,.exo-native-widget-outer-container,ins[data-processed="true"],.popup-iframe,ins.adsbynetwork,.wb-contai'; GM_addStyle(`${AD_SELECTORS}{display:none !important}`); const BLOCK_PATTERNS = [/magsrv|pemsrv|ad-provider|exoclick|ads?[0-9]*\.|popunder|venor|popup/i]; ['AdProvider', 'adConfig', 'popMagic', 'RocketBrowser', 'exoclick'].forEach(prop => { Object.defineProperty(unsafeWindow, prop, { value: [], writable: false }); }); location.reload = () => false; const shouldBlock = url => BLOCK_PATTERNS.some(p => p.test(url)); window.fetch = new Proxy(window.fetch, { apply(target, thisArg, args) { const url = args[0]?.url || args[0]; return shouldBlock(url) ? Promise.resolve(new Response()) : target.apply(thisArg, args); } }); XMLHttpRequest.prototype.open = new Proxy(XMLHttpRequest.prototype.open, { apply(target, thisArg, args) { return shouldBlock(args[1]) ? (thisArg._blocked = true) : target.apply(thisArg, args); } }); window.open = new Proxy(window.open, { apply(target, thisArg, args) { return shouldBlock(args[0]) ? null : target.apply(thisArg, args); } }); unsafeWindow.addEventListener = new Proxy(unsafeWindow.addEventListener, { apply(target, thisArg, [type, listener]) { return type === "load" && listener.toString().includes("popMagic") ? undefined : target.apply(thisArg, arguments); } }); unsafeWindow.document.querySelector = new Proxy(unsafeWindow.document.querySelector, { apply(target, thisArg, [selector]) { return selector === "[disable-devtool-auto]" ? null : target.apply(thisArg, arguments); } }); document.createElement = new Proxy(document.createElement, { apply(target, thisArg, [tagName]) { const el = target.apply(thisArg, arguments); if (tagName === 'iframe') Object.defineProperty(el, 'src', { set() {} }); if (tagName === 'a') el.click = () => {}; return el; } }); const clean = () => { document.querySelectorAll(AD_SELECTORS).forEach(el => el.remove()); document.querySelectorAll('iframe').forEach(iframe => { if (shouldBlock(iframe.src) || getComputedStyle(iframe).position === 'fixed') iframe.remove(); }); ['storedResult', 'inData', 'extranks', 'Better'].forEach(key => localStorage.removeItem(key)); }; new MutationObserver(() => clean()).observe(document, { childList: true, subtree: true, attributes: true }); document.readyState === 'loading' ? document.addEventListener('DOMContentLoaded', clean) : clean(); })();