// ==UserScript== // @name Bilibili H键网页全屏 // @namespace http://tampermonkey.net/ // @version 1.0 // @description 按下H键切换Bilibili网页全屏/退出全屏 // @author Grok // @match https://www.bilibili.com/video/* // @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'; let toggleWebFullscreen = function() { // 查找网页全屏按钮 const webFullBtn = document.querySelector('.bpx-player-ctrl-btn.bpx-player-ctrl-web'); if (webFullBtn) { // 模拟点击 webFullBtn.click(); console.log('Bilibili网页全屏已切换'); } else { // 如果没找到,稍后重试(玩家可能异步加载) setTimeout(toggleWebFullscreen, 500); } }; // 监听键盘事件 document.addEventListener('keydown', function(event) { // 检查是否按下H键(忽略大小写) if (event.key.toLowerCase() === 'h') { // 防止默认行为(如浏览器快捷键) event.preventDefault(); event.stopPropagation(); toggleWebFullscreen(); } }, true); // 使用捕获阶段,确保优先响应 // 如果页面已加载,额外监听DOM变化(以防动态加载) const observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { if (mutation.addedNodes.length > 0) { // 检查是否新增了玩家控件 if (document.querySelector('.bpx-player-ctrl-web')) { console.log('Bilibili玩家已加载,H键全屏就绪'); } } }); }); observer.observe(document.body || document.documentElement, { childList: true, subtree: true }); })();