// ==UserScript== // @name Bilibili H键网页全屏 // @namespace http://tampermonkey.net/ // @version 1.2 // @description 按下 H 键切换 Bilibili 网页全屏/退出全屏(自动忽略输入框、编辑区与评论框) // @author Grok+ChatGPT // @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) { if (event.key.toLowerCase() !== 'h') 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 }); })();