Greasy Fork

Greasy Fork is available in English.

全屏视频自动隐藏鼠标(通用版)

在任何网站全屏播放视频时自动隐藏鼠标指针

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

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

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

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

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

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         全屏视频自动隐藏鼠标(通用版)
// @namespace    http://tampermonkey.net/
// @version      2.0
// @description  在任何网站全屏播放视频时自动隐藏鼠标指针
// @match        *://*/*
// @grant        none
// @run-at       document-start
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    let hideTimer = null;
    let isFullscreen = false;

    // 创建样式来隐藏鼠标
    const style = document.createElement('style');
    style.textContent = `
        .hide-cursor,
        .hide-cursor * {
            cursor: none !important;
        }
    `;
    document.head.appendChild(style);

    // 隐藏鼠标的函数
    function hideCursor() {
        document.body.classList.add('hide-cursor');
    }

    // 显示鼠标的函数
    function showCursor() {
        document.body.classList.remove('hide-cursor');
    }

    // 鼠标移动时的处理
    function handleMouseMove() {
        if (!isFullscreen) return;

        showCursor();
        clearTimeout(hideTimer);

        // 3秒无操作后隐藏鼠标
        hideTimer = setTimeout(hideCursor, 3000);
    }

    // 监听全屏状态变化
    function handleFullscreenChange() {
        isFullscreen = !!(document.fullscreenElement ||
                         document.webkitFullscreenElement ||
                         document.mozFullScreenElement ||
                         document.msFullscreenElement);

        if (isFullscreen) {
            // 进入全屏,启动自动隐藏
            hideTimer = setTimeout(hideCursor, 3000);
        } else {
            // 退出全屏,清除定时器并显示鼠标
            clearTimeout(hideTimer);
            showCursor();
        }
    }

    // 添加事件监听
    document.addEventListener('mousemove', handleMouseMove);
    document.addEventListener('fullscreenchange', handleFullscreenChange);
    document.addEventListener('webkitfullscreenchange', handleFullscreenChange);
    document.addEventListener('mozfullscreenchange', handleFullscreenChange);
    document.addEventListener('MSFullscreenChange', handleFullscreenChange);

    console.log('通用全屏自动隐藏鼠标脚本已加载 - 适用于所有网站');
})();