// ==UserScript== // @name Bilibili 视频自动网页全屏 // @namespace https://bbs.tampermonkey.net.cn/ // @version 0.1.1 // @description 进入视频详情页自动打开网页全屏,支持快捷键H,支持设置关闭/启用自动打开网页全屏 // @author zr // @match *://www.bilibili.com/video* // @grant GM_registerMenuCommand // @grant GM_setValue // @grant GM_getValue // @grant GM_info // ==/UserScript== (function () { 'use strict'; if (GM_info) { const scriptHandler = GM_info.scriptHandler; /** * 仅在油侯插件上运行,避免无法点击注册开关 */ if (scriptHandler == "Tampermonkey" || scriptHandler == "Violentmonkey" || scriptHandler == "ScriptCat" || scriptHandler == "Via") { if (GM_getValue("AutoFullscreen123")) { GM_registerMenuCommand("[√]自动网页全屏", function () { GM_setValue("AutoFullscreen123", false); location.reload(); }); }else{ GM_registerMenuCommand("[x]自动网页全屏", function () { GM_setValue("AutoFullscreen123", true); location.reload(); }); } if(GM_getValue("AutoFullscreen123")){ var a = setInterval(() => { var btn = document.querySelector(".bpx-player-ctrl-web") if (btn) { btn.click() clearInterval(a) } }, 1000) } } } class VideoFullpage { constructor() { this.handleGlobalKey = this.handleGlobalKey.bind(this); document.addEventListener('keydown', this.handleGlobalKey); this.originalStates = new Map(); } handleGlobalKey(e) { if (e.code === 'KeyH' && !e.ctrlKey && !e.altKey && !e.metaKey) { e.preventDefault(); const video = document.querySelector('video'); var btn = document.querySelector(".bpx-player-ctrl-web") if (btn) { btn.click() clearInterval(a) } } } } new VideoFullpage(); })();