视频网站自动网页全屏

支持哔哩哔哩、B站直播、腾讯视频、优酷视频、爱奇艺、芒果TV、搜狐视频、AcFun弹幕网播放页自动网页全屏,B站视频播放完成后自动退出网页全屏

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

// ==UserScript==
// @license      MIT
// @author       Feny
// @version      0.9.6
// @name         视频网站自动网页全屏
// @namespace    http://tampermonkey.net/
// @description  支持哔哩哔哩、B站直播、腾讯视频、优酷视频、爱奇艺、芒果TV、搜狐视频、AcFun弹幕网播放页自动网页全屏,B站视频播放完成后自动退出网页全屏
// @include      https://tv.sohu.com/v/*
// @include      https://www.acfun.cn/v/*
// @include      https://www.mgtv.com/b/*
// @include      https://www.iqiyi.com/v_*
// @include      https://v.pptv.com/show/*
// @include      https://v.qq.com/x/page/*
// @include      https://v.qq.com/x/cover/*
// @include      https://haokan.baidu.com/v*
// @include      https://v.youku.com/v_show/*
// @include      https://live.acfun.cn/live/*
// @include      https://live.bilibili.com/\d+*
// @include      https://www.acfun.cn/bangumi/*
// @include      https://www.bilibili.com/list/*
// @include      https://www.bilibili.com/video/*
// @include      https://v.qq.com/live/p/newtopic/*
// @include      https://www.bilibili.com/festival/*
// @include      /https:\/\/live.bilibili.com\/\d+.*/
// @include      https://www.bilibili.com/cheese/play/*
// @include      https://www.bilibili.com/bangumi/play/*
// @icon         data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAqdJREFUWEftl91LFFEYxp/3jB9ESZjtSl51F1RUSgRCF/kHlF1IhiFhF65dqEQkBUErdJMStBukGwQre2NZUiCRqUiURkW65mIfqGUFsW6Ii0jY7p4Tc3Rqd5zaGVldAudynve8z28e3jMzh5Dmi1R/V0vQyRRWxgWG6x22SrcnOAhQcQIbwVtXba8y1EANSpS1xzJin5c/Dz+jRDPvGWoErwRw35zuh8ChpcXXFjbwi9k/WADA9viGgovGnxtFs6EmcApMvCdBA3oIIirl4N8NNQngmRYJiwTOE7EHHLERAmXFawQ6AdCQkRbjsZIMUvIFoV0HMSsEDjCgSK8tJqAHAEDAMWLKLOexx8tiVVDEhLLVQAtzRPcwKOUANSWCw1/rsBe6PcFz8dpfAdTFgtF+EmIvBG7pID7mZNl2zkVCFQbahzqHfYerddpNhFpdsnfqauzl8ZoEuO4JXdIKOefynnZlimxXhBbqjTZL/el8pzrAVjTGmKh12Bq1ddJs974abQDXfFMuAhQ6EodwDTHWAf6/BAoK8nD0cDEKtuVhyD+OzvvLXnyWJshyApedJ1F65M9n4tlAAF5fL168fGfJWCu2DDA61GpodLvjCdp8vfjyNWQJJGUAquvMzBzafD0yEc65KZCUAmiOo4FPEqS753VSiFUB0FxbPF244en6J8SqAoTD8zhYcjZ9AP6RCVRWNacHYPD5GJqudmBi8tvaAkxNBeUuuNv5NOkAqgUpm4FIJCrfA+r0z4bnTZmvCKCv+wrsts0JBg8fvZLGY28NfoqToFhOoOJ4CS40lMu2I28mpXFP37DpJ9YXWgZQG+Tm5mBL7qakA2aGakUAZhqbrVkH0BLoB34fzcyml5K6pd/yaicRlQlgV0q6mmwitMOpyfpVKfsFya4w73cz9xQAAAAASUVORK5CYII=
// ==/UserScript==

(function () {
    "use strict";

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

    // 重写replaceState方法
    const original = history.replaceState;
    history.replaceState = function () {
        original.apply(this, arguments);
        window.dispatchEvent(new Event('replaceState'));
    };

    const selector = {
        "v.pptv.com": ".w-expandIn",
        "www.acfun.cn": ".fullscreen-web",
        "live.acfun.cn": ".fullscreen-web",
        "v.youku.com": "#webfullscreen-icon",
        "www.mgtv.com": ".webfullscreenBtn i",
        "www.iqiyi.com": ".iqp-btn-webscreen",
        "v.qq.com": 'div[aria-label="网页全屏"]',
        "tv.sohu.com": 'button[data-title="网页全屏"',
        "www.bilibili.com": 'div[aria-label="网页全屏"]',
        "live.bilibili.com": "#businessContainerElement",
        "haokan.baidu.com": 'div[aria-label="网页全屏"]',
    }

    const _q = (selector) => document.querySelector(selector);
    const webfullscreen = {
        init(win) {
            let i = 0
            const time = 60000, delay = 300, interval = setInterval(() => {
                const href = location.href;
                const video = this.getVideo();
                const element = this.getElement();
                if (++i * delay >= time) clearInterval(interval);
                if (element) this.fullScreen(element, win) && clearInterval(interval);
                if (video && /www\.bilibili\.com\/video/.test(href)) this.exitWebFull(video);
            }, delay);
        },
        getVideo: () => _q("video"),
        getElement: () => _q(selector[location.host]),
        fullScreen(elem, win) {
            // B站直播
            if (Object.is(location.host, "live.bilibili.com")) {
                const e = new MouseEvent("dblclick", {
                    view: win,
                    bubbles: true,
                    cancelable: true,
                });
                elem.dispatchEvent(e);
                localStorage.setItem("FULLSCREEN-GIFT-PANEL-SHOW", 0);
                document.body.classList.add("hide-asida-area", "hide-aside-area")
                return true
            }

            const video = this.getVideo();
            if (!video) return false;
            const offsetWidth = video.offsetWidth;
            if (Object.is(0, offsetWidth)) return false;
            if (Object.is(window.innerWidth, offsetWidth)) return true;
            elem.click ? elem.click() : elem.dispatchEvent(new Event("click"));
            return true;
        },
        /**
         * B站视频播放完成后自动退出网页全屏,取消连播
         */
        exitWebFull(video) {
            video.addEventListener('ended', () => {
                if (Object.is(window.innerWidth, video.offsetWidth)) {
                    this.getElement().click();
                    const cancel = _q(".bpx-player-ending-related-item-cancel");
                    if (cancel) cancel.click();
                }
            });
        }
    };

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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址