播放完合集最后一集视频自动跳转至第一集
// ==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);
}
}
});
}
});