哔哩哔哩(bilibili.com)合集循环

播放完合集最后一集视频自动跳转至第一集

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        哔哩哔哩(bilibili.com)合集循环
// @namespace   Violentmonkey Scripts
// @match       *://*.bilibili.com/*
// @grant       none
// @version     1.0
// @author      CyrilSLi
// @description 播放完合集最后一集视频自动跳转至第一集
// @license     MIT
// ==/UserScript==
window.addEventListener("load", () => {
    const player = document.querySelector("#bilibili-player video");
    if (player) {
        player.addEventListener("ended", () => {
            if (location.pathname.includes(document.querySelector(".video-pod__list.section > div:last-child").getAttribute("data-key")) && // 最后一集
                document.querySelector('.bpx-player-ctrl-setting-handoff-content input[type="radio"][value="0"]').checked === true && // 自动切集 on
                document.querySelector('.bpx-player-ctrl-setting-loop input').checked === false) { // 单集循环 off
                function redirect() {
                    window.location.href = "https://www.bilibili.com/video/" + document.querySelector(".video-pod__list.section > div:first-child").getAttribute("data-key"); // 第一集
                }
                const slide = document.querySelector(".pod-slide.video-pod__slide > div");
                if (slide == null) { // 无小节
                    redirect();
                } else if (slide.lastChild.classList.contains("active")) {
                    slide.firstChild.click(); // 切换到第一小节
                    setTimeout(redirect, 1000);
                }
            }
        });
    }
});