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

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

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 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('通用全屏自动隐藏鼠标脚本已加载 - 适用于所有网站');
})();