Greasy Fork

Greasy Fork is available in English.

网页一键模糊防窥屏

按alt+Q快捷键切换网页模糊,防止他人窥屏

当前为 2025-07-17 提交的版本,查看 最新版本

// ==UserScript==
// @name         网页一键模糊防窥屏
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  按alt+Q快捷键切换网页模糊,防止他人窥屏
// @author       AI助手
// @match        *://*/*
// @grant        none
// @license Apache-2.0
// ==/UserScript==

(function() {
    'use strict';
    const MASK_ID = '__tampermonkey_blur_mask__';
    const STYLE_ID = '__tampermonkey_blur_style__';

    function createBlurMask() {
        if (document.getElementById(MASK_ID)) return;
        // 创建遮罩层
        const mask = document.createElement('div');
        mask.id = MASK_ID;
        mask.style.position = 'fixed';
        mask.style.top = '0';
        mask.style.left = '0';
        mask.style.width = '100vw';
        mask.style.height = '100vh';
        mask.style.zIndex = '2147483647';
        mask.style.pointerEvents = 'none';
        mask.style.backdropFilter = 'blur(12px)';
        mask.style.background = 'rgba(255,255,255,0.15)';
        mask.style.transition = 'backdrop-filter 0.2s';
        document.body.appendChild(mask);
        // 插入样式,兼容不支持backdrop-filter的浏览器
        if (!document.getElementById(STYLE_ID)) {
            const style = document.createElement('style');
            style.id = STYLE_ID;
            style.innerHTML = `
                #${MASK_ID} {
                    -webkit-backdrop-filter: blur(12px);
                    backdrop-filter: blur(12px);
                }
            `;
            document.head.appendChild(style);
        }
    }

    function removeBlurMask() {
        const mask = document.getElementById(MASK_ID);
        if (mask) mask.remove();
    }

    function toggleBlur() {
        if (document.getElementById(MASK_ID)) {
            removeBlurMask();
        } else {
            createBlurMask();
        }
    }

    document.addEventListener('keydown', function(e) {
        // Alt+Q
        if (e.altKey && !e.ctrlKey && !e.shiftKey && !e.metaKey && (e.key === 'q' || e.key === 'Q')) {
            e.preventDefault();
            toggleBlur();
        }
    });
})();