Screen Freeze

Freeze everything on the page with a button or key press

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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();
    });

})();