// ==UserScript== // @name Bilibili H键网页全屏 // @namespace http://tampermonkey.net/ // @version 1.3 // @description 按下 H 键切换 Bilibili 网页全屏/退出全屏(自动忽略输入框、编辑区与评论框,且按下Shift/Alt/Ctrl/Win时不触发) // @author Grok+ChatGPT+Gemini // @match https://www.bilibili.com/video/* // @match https://www.bilibili.com/list/* // @match https://www.bilibili.com/watchroom/* // @match https://player.bilibili.com/player.html* // @match https://live.bilibili.com/* // @grant none // @run-at document-start // ==/UserScript== (function() { 'use strict'; function toggleWebFullscreen() { const btn = document.querySelector('.bpx-player-ctrl-btn.bpx-player-ctrl-web') || document.querySelector('.bpx-player-ctrl-web'); if (btn) btn.click(); else setTimeout(toggleWebFullscreen, 500); } function pathIndicatesTyping(path) { if (!path) return false; for (const node of path) { if (!node) continue; const tag = node.tagName ? node.tagName.toUpperCase() : ''; if (tag === 'INPUT' || tag === 'TEXTAREA') return true; if (node.isContentEditable) return true; if (tag === 'BILI-COMMENT-TEXTAREA' || tag === 'BILI-COMMENT') return true; if (node.classList && ( node.classList.contains('bili-comment-textarea__inner') || node.classList.contains('reply-box') || node.classList.contains('editor') )) return true; } return false; } document.addEventListener('keydown', function(event) { const key = event.key.toLowerCase(); if (key !== 'h') return; // 支持 H 和 更多 键 // 【新增功能】检查修饰键 // 如果 Shift, Alt, Ctrl, 或 Meta(Win/Cmd) 键被按下,则不触发功能 if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) { return; } const path = (typeof event.composedPath === 'function' && event.composedPath()) || event.path || [event.target]; if (pathIndicatesTyping(path)) return; const active = document.activeElement; if (active) { const tag = active.tagName ? active.tagName.toUpperCase() : ''; if (tag === 'INPUT' || tag === 'TEXTAREA' || active.isContentEditable) return; if (tag === 'BILI-COMMENT-TEXTAREA' || tag === 'BILI-COMMENT') return; } event.preventDefault(); event.stopPropagation(); toggleWebFullscreen(); }, true); new MutationObserver(() => { if (document.querySelector('.bpx-player-ctrl-web') || document.querySelector('.bpx-player-ctrl-btn.bpx-player-ctrl-web')) { console.log('H键全屏可用'); } }).observe(document.body || document.documentElement, { childList: true, subtree: true }); })();