Screen Freeze

Freeze everything on the page with a button or key press

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Screen Freeze
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Freeze everything on the page with a button or key press
// @author       KukuModZ
// @match        *://*/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    let frozen = false;
    const timers = [];

    // Function to stop all intervals and timeouts
    function freezeTimers() {
        let id = window.setTimeout(() => {}, 0);
        while (id--) {
            clearTimeout(id);
            clearInterval(id);
        }
    }

    // Pause all videos and audios
    function pauseMedia() {
        document.querySelectorAll('video, audio').forEach(media => media.pause());
    }

    // Freeze CSS animations and transitions
    function freezeAnimations() {
        document.querySelectorAll('*').forEach(el => {
            el.style.animationPlayState = 'paused';
            el.style.transition = 'none';
        });
    }

    // Create a fullscreen overlay to prevent interactions
    const overlay = document.createElement('div');
    overlay.style.position = 'fixed';
    overlay.style.top = '0';
    overlay.style.left = '0';
    overlay.style.width = '100%';
    overlay.style.height = '100%';
    overlay.style.backgroundColor = 'rgba(0,0,0,0)';
    overlay.style.zIndex = '999999';
    overlay.style.display = 'none';
    document.body.appendChild(overlay);

    // Create control panel
    const panel = document.createElement('div');
    panel.style.position = 'fixed';
    panel.style.top = '10px';
    panel.style.right = '10px';
    panel.style.padding = '10px';
    panel.style.backgroundColor = 'rgba(0,0,0,0.7)';
    panel.style.color = 'white';
    panel.style.zIndex = '1000000';
    panel.style.borderRadius = '5px';
    panel.style.fontFamily = 'Arial, sans-serif';
    panel.style.cursor = 'pointer';
    panel.textContent = 'Freeze Page';
    document.body.appendChild(panel);

    function toggleFreeze() {
        frozen = !frozen;
        overlay.style.display = frozen ? 'block' : 'none';
        panel.textContent = frozen ? 'Unfreeze Page' : 'Freeze Page';

        if (frozen) {
            freezeTimers();
            pauseMedia();
            freezeAnimations();
            document.body.style.pointerEvents = 'none';
        } else {
            document.body.style.pointerEvents = 'auto';
            // Refresh page elements to resume animations if needed
            document.querySelectorAll('*').forEach(el => {
                el.style.animationPlayState = '';
                el.style.transition = '';
            });
            document.querySelectorAll('video, audio').forEach(media => media.play());
        }
    }

    panel.addEventListener('click', toggleFreeze);
    document.addEventListener('keydown', e => {
        if (e.key === 'f' || e.key === 'F') toggleFreeze();
    });

})();