Bilibili自动全屏脚本

在Bilibili网站自动全屏播放视频

目前為 2023-06-20 提交的版本,檢視 最新版本

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Bilibili自动全屏脚本
// @namespace    bilibili-auto-fullscreen-script
// @version      1.2
// @description  在Bilibili网站自动全屏播放视频
// @author       BlingCc
// @match        https://www.bilibili.com/*
// @license      MIT
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    window.onload = function() {
        // 找到包含视频的div元素
        let videoWrap = document.querySelector('.bpx-player-video-area');
        if (videoWrap) {
            // 将鼠标移动到该元素中心
            let rect = videoWrap.getBoundingClientRect();
            let x = rect.left + rect.width / 2;
            let y = rect.top + rect.height / 2;
            simulateMouseEvent(videoWrap, 'mouseenter', x, y);
            simulateMouseEvent(videoWrap, 'mouseover', x, y);


        setTimeout(function() {
            // 找到全屏按钮元素
            let fullscreenButton = document.querySelector('[aria-label="网页全屏"]');
            if (fullscreenButton) {
                // 将鼠标移动到该元素上并模拟点击
                rect = fullscreenButton.getBoundingClientRect();
                x = rect.left + rect.width / 2;
                y = rect.top + rect.height / 2;
                simulateMouseEvent(fullscreenButton, 'mouseenter', x, y);
                simulateMouseEvent(fullscreenButton, 'click', x, y);
                simulateMouseEvent(fullscreenButton, 'mouseleave', x, y);
            }
            }, 1000);
            setTimeout(function() {
                let rect = videoWrap.getBoundingClientRect();
                let x = rect.left + rect.width / 2;
                let y = rect.top + rect.height / 2;
                simulateMouseEvent(videoWrap, 'mouseenter', x, y);
                simulateMouseEvent(videoWrap, 'mouseover', x, y);
            // 找到全屏按钮元素
            let fullscreenButton = document.querySelector('[aria-label="网页全屏"]');
            if (fullscreenButton) {
                // 将鼠标移动到该元素上并模拟点击
                rect = fullscreenButton.getBoundingClientRect();
                x = rect.left + rect.width / 2;
                y = rect.top + rect.height / 2;
                simulateMouseEvent(fullscreenButton, 'mouseenter', x, y);
                simulateMouseEvent(fullscreenButton, 'click', x, y);
                simulateMouseEvent(fullscreenButton, 'mouseleave', x, y);
            }
            }, 1000);
            setTimeout(function() {

                let rect = videoWrap.getBoundingClientRect();
                let x = rect.left + rect.width / 2;
                let y = rect.top + rect.height / 2;
                simulateMouseEvent(videoWrap, 'mouseenter', x, y);
                simulateMouseEvent(videoWrap, 'mouseover', x, y);
            // 找到全屏按钮元素
            let fullscreenButton = document.querySelector('[aria-label="网页全屏"]');
            if (fullscreenButton) {
                // 将鼠标移动到该元素上并模拟点击
                rect = fullscreenButton.getBoundingClientRect();
                x = rect.left + rect.width / 2;
                y = rect.top + rect.height / 2;
                simulateMouseEvent(fullscreenButton, 'mouseenter', x, y);
                simulateMouseEvent(fullscreenButton, 'click', x, y);
                simulateMouseEvent(fullscreenButton, 'mouseleave', x, y);
            }
            }, 4000);

        }
    };

    function simulateMouseEvent(element, eventType, x, y) {
        const event = new MouseEvent(eventType, {
            view: window,
            bubbles: true,
            cancelable: true,
            clientX: x,
            clientY: y
        });
                element.dispatchEvent(event);
    }

})();