// ==UserScript== // @name 4khd 广告屏蔽 // @namespace https://viayoo.com // @version 0.41 // @description 移除4khd广告。 // @author Via // @license MIT // @match *://*.4khd.com/* // @match *://*.xxtt.ink/* // @match *://*.uuss.uk/* // @run-at document-start // @grant none // ==/UserScript== (function() { 'use strict'; const AD_SELECTORS = '.exo_wrapper,.popup,.centbtd,.exo-native-widget,.exo-native-widget-outer-container,ins[data-processed="true"]'; const BLOCK_REGEX = /(magsrv|pemsrv)\.com/; const BLOCK_PATTERNS = [/(magsrv|pemsrv)\.com/, /\.(js|xmlhttprequest)$/i]; window.fetch = function(...args) { const url = typeof args[0] === 'string' ? args[0] : (args[0].url || ''); return BLOCK_PATTERNS.some(p => p.test(url)) ? Promise.resolve(new Response('', { status: 200 })) : window.fetch.apply(this, args); }; const origOpen = XMLHttpRequest.prototype.open; XMLHttpRequest.prototype.open = function(method, url) { if (typeof url === 'string' && BLOCK_PATTERNS.some(p => p.test(url))) return; return origOpen.apply(this, arguments); }; const origOpenWin = window.open; window.open = function(...args) { const url = args[0] || ''; return /magsrv|ads|pop/.test(url) ? null : origOpenWin.apply(this, args); }; const blockScript = node => { if (node.tagName !== 'SCRIPT') return; const src = node.src || ''; const txt = node.textContent || ''; if (BLOCK_REGEX.test(src) || BLOCK_REGEX.test(txt)) node.remove(); }; const removeAds = () => { document.querySelectorAll(AD_SELECTORS).forEach(el => el.remove()); }; new MutationObserver(muts => { for (const m of muts) { for (const n of m.addedNodes) { if (n.nodeType !== 1) continue; blockScript(n); n.querySelectorAll?.('script').forEach(blockScript); removeAds(); } } }).observe(document, { childList: true, subtree: true }); const init = () => { if (!document.body) return requestAnimationFrame(init); removeAds(); }; if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); } else { init(); } })();