Greasy Fork

哔哩哔哩、腾讯视频、芒果TV自动网页全屏(个人自用)

哔哩哔哩、腾讯视频、芒果TV视频播放页自动网页全屏

目前为 2024-12-06 提交的版本。查看 最新版本

// ==UserScript==
// @author       Feny
// @license      MIT
// @version      0.7
// @name         哔哩哔哩、腾讯视频、芒果TV自动网页全屏(个人自用)
// @namespace    http://tampermonkey.net/
// @description  哔哩哔哩、腾讯视频、芒果TV视频播放页自动网页全屏
// @icon         https://i0.hdslb.com/bfs/static/jinkela/long/images/favicon.ico
// @include      http*://www.mgtv.com/b/*
// @include      http*://v.qq.com/x/cover/*
// @include      http*://www.bilibili.com/video/*
// @include      http*://www.bilibili.com/bangumi/play/*
// ==/UserScript==

(function () {
    "use strict";

    const orig = history.pushState;
    // 重写pushState方法
    history.pushState = function () {
        orig.apply(history, arguments);
        window.dispatchEvent(new Event('pushstate'));
    };

    const webfullscreen = {
        init() {
            const interval = setInterval(() => {
                const element = this.getElement()
                if (element) this.fullScreen(element) && clearInterval(interval);
            }, 300);
        },
        getElement() {
            return document.querySelector('div[aria-label="网页全屏"]')
                || document.querySelector(".bpx-player-ctrl-web")
                || document.querySelector(".webfullscreenBtn i")
        },
        fullScreen(elem) {
            const offsetWidth = document.querySelector("video").offsetWidth
            if (window.innerWidth === offsetWidth) return true
            elem.click ? elem.click() : elem.dispatchEvent(new Event("click"));
            return true
        },
    };

    webfullscreen.init();
    window.addEventListener('pushstate', () => webfullscreen.init());
})();