Empire Streaming xyz

Block ak.weewoogloogru.net redirects, sanitize links, stop malicious popups

目前為 2025-10-22 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Empire Streaming xyz
// @namespace    Balta zar
// @version      1.0
// @description  Block ak.weewoogloogru.net redirects, sanitize links, stop malicious popups
// @match        *://empire-streami.xyz/*
// @run-at       document-start
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const BLOCKED_HOST = "ak.weewoogloogru.net";

    // --- 1. Sanitize all link/button clicks instantly ---
    document.addEventListener('click', function(e) {
        const el = e.target.closest('a, button');
        if (!el) return;

        // Handle <a> links
        if (el.tagName === "A" && el.href) {
            if (el.href.includes(BLOCKED_HOST)) {
                e.preventDefault();
                e.stopImmediatePropagation();

                const cleanUrl = extractCleanUrl(el.href);
                if (cleanUrl) {
                    console.info("[Anti-Redirect] Clean redirect →", cleanUrl);
                    window.location.assign(cleanUrl);
                } else {
                    console.warn("[Anti-Redirect] Malicious redirect blocked:", el.href);
                }
            }
        }

        // Handle <button> with inline onclick redirection
        if (el.tagName === "BUTTON") {
            const onclick = el.getAttribute('onclick');
            if (onclick && onclick.includes(BLOCKED_HOST)) {
                e.preventDefault();
                e.stopImmediatePropagation();
                el.removeAttribute('onclick');
                console.info("[Anti-Redirect] Cleaned malicious onclick:", el);

                const safeLink = extractCleanUrl(onclick);
                if (safeLink) window.location.assign(safeLink);
            }
        }
    }, true);

    // --- 2. MutationObserver: continuously sanitize DOM ---
    const observer = new MutationObserver(() => {
        document.querySelectorAll('a[href], button[onclick]').forEach(el => {
            try {
                if (el.href && el.href.includes(BLOCKED_HOST)) {
                    el.href = extractCleanUrl(el.href) || "#";
                }
                const onclick = el.getAttribute('onclick');
                if (onclick && onclick.includes(BLOCKED_HOST)) {
                    el.removeAttribute('onclick');
                }
            } catch {}
        });
    });

    observer.observe(document.documentElement, { childList: true, subtree: true });

    // --- 3. Override window.open to block forced popups ---
    const nativeOpen = window.open;
    window.open = function(url, ...args) {
        if (typeof url === "string" && url.includes(BLOCKED_HOST)) {
            console.warn("[Popup Blocker] Blocked:", url);
            return null;
        }
        const popup = nativeOpen.apply(this, [url, ...args]);
        if (popup && (!url || url === "about:blank")) {
            setTimeout(() => { try { popup.close(); } catch {} }, 100);
        }
        return popup;
    };

    // --- Helper: Extract real destination safely ---
    function extractCleanUrl(input) {
        try {
            const decoded = decodeURIComponent(String(input));
            const match = decoded.match(/https?:\/\/(?!ak\.weewoogloogru\.net)[^"'\\s)]+/i);
            return match ? match[0] : null;
        } catch {
            return null;
        }
    }

})();