B站 自动播放 & 网页全屏

Bilibili Autoplay & FullScreen

目前為 2019-12-04 提交的版本,檢視 最新版本

// ==UserScript==
// @name         B站 自动播放 & 网页全屏
// @version      0.12
// @description  Bilibili Autoplay & FullScreen
// @author       Erimus
// @include      http*://*bilibili.com/video/*
// @grant        none
// @namespace https://greasyfork.org/users/46393
// ==/UserScript==

(function() {
    'use strict';

    console.log('=== autoplay & fullscreen')
    // Your code here...
    let playing = 0 //把判断条件改为计数,防止网络不好时长时间Loading,或者播了数秒,判断为已播放,其实暂停了的情况。
    let fullscreen = false

    let find_and_click = setInterval(function() {

        if (!fullscreen) {
            let fullScreenBtn = document.getElementsByClassName('bilibili-player-video-web-fullscreen')
            console.log('=== Full Screen Button:', fullScreenBtn)
            if (fullScreenBtn) {
                fullScreenBtn[0].click()
                // check player status
                let closed = document.getElementsByClassName('bilibili-player-video-web-fullscreen')[0].className.includes('closed')
                console.log('=== Closed:', closed)
                if (closed) {
                    console.log('=== fullscreen OK')
                    fullscreen = true
                }
            }
        }

        if (playing < 100) {
            let playBtn = document.getElementsByClassName('bilibili-player-video-btn-start');
            console.log('=== Play Button:', playBtn)
            if (playBtn) {
                // check player status
                let play = document.getElementsByClassName('bilibili-player-area')[0].className
                console.log('=== Playing check:', play)
                if (play=='bilibili-player-area video-state-blackside') {
                    playing++
                    console.log('=== playing', playing)
                }else{
                    playBtn[0].click()
                }
            }
        }

        if (playing >= 100 && fullscreen) {
            console.log('=== quit loop')
            clearInterval(find_and_click);
        }
    }, 500);

})();