自动网页全屏播放

自动网页全屏播放,已支持Bilibili,Youtube(剧场模式),腾讯视频

目前為 2019-06-09 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         自动网页全屏播放
// @namespace    https://tmr.js.org/
// @more         https://github.com/ttttmr/UserJS
// @version      0.7
// @description  自动网页全屏播放,已支持Bilibili,Youtube(剧场模式),腾讯视频
// @author       tmr
// @match        https://www.bilibili.com/video/av*
// @match        https://www.bilibili.com/bangumi/play/ss*
// @match        https://www.bilibili.com/bangumi/play/ep*
// @match        https://www.youtube.com/watch?v=*
// @match        https://v.qq.com/x/page/*
// @match        https://v.qq.com/x/cover/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';
    let counter = 0;
    function fullscreen() {
        console.log('web fullscreen start');
        webFull()
        function webFull() {
            console.log('web fullscreen ing ' + counter);
            counter++;
            let fullscreenClass;
            if (location.host == 'www.bilibili.com') {
                fullscreenClass = '.bilibili-player-video-web-fullscreen';
            } else if (location.host == 'www.youtube.com') {
                fullscreenClass = '.ytp-size-button';
            } else if (location.host == 'v.qq.com') {
                fullscreenClass = '.txp_btn_fake';
            }
            if (fullscreenClass) {
                // 尝试全屏
                if (document.querySelector(fullscreenClass)) {
                    // 网页全屏
                    document.querySelector(fullscreenClass).click();
                    console.log('web fullscreen success');
                    // 重置计数
                    counter = 0;
                    // 移除监听
                    document.removeEventListener('visibilitychange', fullscreen);
                }
                // 失败并重试
                else {
                    // 超过30次就退出
                    if (counter > 30) {
                        console.log('web fullscreen fail');
                        return;
                    };
                    // 延迟0.5秒重试
                    setTimeout(webFull, 500);
                }
            }
        }
        clickVideoLink();
        function clickVideoLink() {
            window.onclick = function (mClick) {
                let mClickElement= mClick.target;
                if (location.host == 'www.bilibili.com') {
                    // 视频链接
                    let videoUrlList = ['https://www.bilibili.com/video/av', 'https://www.bilibili.com/bangumi/play/ss', 'https://www.bilibili.com/bangumi/play/ep'];
                    // 视频Class
                    let videoClassList = ['bilibili-player-ending-panel-box-recommend-cover', 'ep-title', 'ep-item'];
                    // 新tab打开不处理
                    if (mClickElement.target == '_blank') {
                        return;
                    }
                    videoUrlList.forEach(function (videoUrl) {
                        if (String(mClickElement).indexOf(videoUrl) == 0) {
                            fullscreen();
                            return;
                        }
                    });
                    videoClassList.forEach(function (videoClass) {
                        if (mClickElement.classList.contains(videoClass)) {
                            fullscreen();
                            return;
                        }
                    });
                } else if (location.host == 'v.qq.com') {
                    // 视频链接
                    let videoUrlList = ['https://v.qq.com/x/page/', 'https://v.qq.com/x/cover/'];
                    // 视频父级Id
                    let videoParentId = 'video_scroll_wrap';
                    // 新tab打开不处理
                    if (mClickElement.target == '_blank') {
                        return;
                    }
                    videoUrlList.forEach(function (videoUrl) {
                        if (String(mClickElement).indexOf(videoUrl) == 0) {
                            fullscreen();
                            return;
                        }
                    });
                    while (mClickElement.parentElement) {
                        if (mClickElement.parentElement.id == videoParentId) {
                            fullscreen();
                            return;
                        } else {
                            mClickElement = mClickElement.parentElement;
                        }
                    }
                }
            }
        }
    }
    window.addEventListener('load', function () {
        // 判断后台打开
        if (document.visibilityState == 'hidden') {
            console.log("now hidden, wait visible");
            document.addEventListener('visibilitychange', fullscreen);
        }
        // 前台打开,直接直行
        else {
            fullscreen();
        }
    });
})();