Bilibili 自动网页全屏

打开视频页面后自动进入网页全屏模式,避免手动点击按钮。

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Bilibili 自动网页全屏
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  打开视频页面后自动进入网页全屏模式,避免手动点击按钮。
// @author       [email protected]
// @match        https://www.bilibili.com/video/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // 进入网页全屏的函数
    function enterWebFullScreen() {
        // 网页全屏按钮
        const btn = document.querySelector('.bpx-player-ctrl-web');
        if (btn && !btn.classList.contains('bpx-state-entered')) {
            btn.click();
            console.log('✅ 已自动进入网页全屏');
            return true;
        }
        return false;
    }

    // 先尝试一次
    if (!enterWebFullScreen()) {
        // 如果没找到,监听 DOM 变化
        const observer = new MutationObserver(() => {
            if (enterWebFullScreen()) {
                observer.disconnect();
            }
        });
        observer.observe(document.body, { childList: true, subtree: true });
    }
})();