Greasy Fork is available in English.

跳过b站充电鸣谢

隐藏b站充电鸣谢,并且在视频结束时自动跳过。加入渐变,防止结束时闪屏

// ==UserScript==
// @name         跳过b站充电鸣谢
// @namespace    voeoc
// @version      1.2
// @description  隐藏b站充电鸣谢,并且在视频结束时自动跳过。加入渐变,防止结束时闪屏
// @author       voeoc
// @match        https://www.bilibili.com/video/*
// @icon         https://www.bilibili.com/favicon.ico
// @grant        GM_addStyle
// @run-at       document-idle
// @license      MIT License
// ==/UserScript==

(function () {
    'use strict';

    // 防止闪屏
    // @ts-ignore
    GM_addStyle(`
.bilibili-player-electric-panel,
.bpx-player-electric-panel {
visibility: hidden;
}
.bilibili-player-ending-panel,
.bpx-player-ending-panel {
opacity: 0;
transition: opacity 0.3s ease;
}
.bilibili-player-ending-panel.visible,
.bpx-player-ending-panel.visible {
opacity: 1;
}`);

    function waitElementLoaded(selector, func, millisecond) {
        const TIME_OUT = 100; // 找100次没有找到就放弃
        let findTimeNum = 0; // 记录查找的次数
        let timer = setInterval(() => {
            let element = document.querySelector(selector);
            if (element != null) {
                // 清除定时器
                clearInterval(timer);
                func(element);
            } else {
                findTimeNum++;
                if (TIME_OUT < findTimeNum) {
                    // 清除定时器
                    clearInterval(timer);
                }
            }
        }, millisecond);
    }

    waitElementLoaded(".bilibili-player-video, .bpx-player-video-wrap", (videoObjParent) => {
        let electricPanelSelector = ".bilibili-player-electric-panel";
        let endingPanelSelector = ".bilibili-player-ending-panel";
        let jumpBtnSelector = ".bilibili-player-electric-panel-jump-content";

        if (videoObjParent.classList.contains("bpx-player-video-wrap")) { // 兼容新版页面
            electricPanelSelector = ".bpx-player-electric-panel";
            endingPanelSelector = ".bpx-player-ending-panel";
            jumpBtnSelector = ".bpx-player-electric-jump";
        }

        let videoObj = videoObjParent.querySelector("video");
        if (!videoObj) {
            videoObj = videoObjParent.querySelector("bwp-video");
        }
        videoObj.addEventListener('play', function () {
            try {
                // @ts-ignore
                document.querySelector(endingPanelSelector).classList.remove("visible");
            } catch (e) { console.error(e);}
        }, false);

        videoObj.addEventListener('ended', function () {
            // 渐变显示结束屏
            waitElementLoaded(endingPanelSelector, (endingPanel) => {
                endingPanel.classList.add("visible");
            }, 100)

            waitElementLoaded(electricPanelSelector, (electricPanel) => {
                if (electricPanel.style.display != 'none') {
                    // 自动点击跳过按钮
                    electricPanel.querySelector(jumpBtnSelector).click();
                }
            }, 1)
        }, false);
    }, 200)
})();