Universal Webpage Panic Mode

Instantly freeze animations, mute/pause media, and kill all running scripts/timers via a hotkey (Ctrl + Shift + X).

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

Advertisement:

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

Advertisement:

// ==UserScript==
// @name         Universal Webpage Panic Mode
// @namespace    https://github.com
// @version      1.1
// @description  Instantly freeze animations, mute/pause media, and kill all running scripts/timers via a hotkey (Ctrl + Shift + X).
// @author       Your Name
// @match        *://*/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    // Unique ID for the panic mode elements
    const ID = '__bm_panic_mode';
    const NOTICE_ID = '__bm_panic_notice';

    // The main function that triggers panic mode
    function triggerPanicMode() {
        // Toggle off if already active
        if (document.getElementById(ID)) {
            document.getElementById(ID).remove();
            const oldNotice = document.getElementById(NOTICE_ID);
            if (oldNotice) oldNotice.remove();
            alert('Panic mode visual rules removed. Note: Cleared timers cannot be restored automatically.');
            return;
        }

        // 1. Inject aggressive CSS to freeze all visual movements
        const style = document.createElement('style');
        style.id = ID;
        style.textContent = `
            * {
                animation: none !important;
                transition: none !important;
            }
            img, video, iframe, canvas {
                animation: none !important;
                transition: none !important;
            }
            body {
                backface-visibility: hidden !important;
                -webkit-backface-visibility: hidden !important;
            }
        `;
        (document.head || document.documentElement).appendChild(style);

        // 2. Mute, pause, and stop loading all HTML5 media elements
        try {
            Array.from(document.querySelectorAll('video, audio')).forEach(media => {
                try {
                    media.pause();
                    media.muted = true;
                    media.preload = 'none';
                } catch (e) {}
            });
        } catch (e) {}

        // 3. Destructive timer wipeout (Nuke loops and timeouts)
        try {
            const probe = setInterval(() => {}, 1000);
            const maxId = probe;
            clearInterval(probe);

            // Fixed syntax: added + operators for the loop and increment
            for (let i = 0; i <= maxId + 1000; i++) {
                try {
                    clearInterval(i);
                    clearTimeout(i);
                } catch (e) {}
            }
        } catch (e) {}

        console.log('Panic Mode Activated: Page activity frozen.');
    }

    // 4. Keyboard Shortcut Listener
    // Note: Changed from Ctrl+Shift+Escape (reserved by Windows for Task Manager) to Ctrl+Shift+X
    window.addEventListener('keydown', function(event) {
        if (event.ctrlKey && event.shiftKey && event.key.toLowerCase() === 'x') {
            event.preventDefault();
            triggerPanicMode();
        }
    }, true); // Using capture phase to intercept events early
})();