bilibili 首页刷新可选择上一个

在b站首页刷一刷按钮上添加上一个下一个按钮以此来回到上一个想看的视频

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         bilibili 首页刷新可选择上一个
// @namespace    https://fybgame.top/
// @version      1.01
// @description  在b站首页刷一刷按钮上添加上一个下一个按钮以此来回到上一个想看的视频
// @author       fyb
// @match        https://www.bilibili.com/
// @match        https://www.bilibili.com/?*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {

window.onload = function (){
    let videoArray = []
    let videos = document.getElementsByClassName('feed-card');
    let itemArray = []
    for(let i = 0 ; i < videos.length ; i ++){
        itemArray.push(videos[i].cloneNode(true))
    }
    videoArray.push(itemArray)
    let nowIndex = 0
    let toAppendLast = document.createElement("BUTTON");
    let spanTextLast = document.createElement("span");
    spanTextLast.innerHTML = '上一个';
    toAppendLast.addEventListener("click", function () {
        if(nowIndex != 0){
            nowIndex -- ;
            nowCountText.innerHTML = (nowIndex+1)+'/'+videoArray.length
            for(let i = 0 ; i < videos.length ; i ++){
                videos[i].innerHTML = videoArray[nowIndex][i].innerHTML;
            }
        }

    })
    toAppendLast.className = 'primary-btn roll-btn';
    toAppendLast.style.marginBottom = "8px"
    toAppendLast.appendChild(spanTextLast);

    let toAppendNext = document.createElement("BUTTON");
    let spanTextNext = document.createElement("span");
    spanTextNext.innerHTML = '下一个';
    toAppendNext.addEventListener("click", function () {
        if(nowIndex < videoArray.length -1){
            nowIndex ++ ;
            nowCountText.innerHTML = (nowIndex+1)+'/'+videoArray.length
            for(let i = 0 ; i < videos.length ; i ++){
                videos[i].innerHTML = videoArray[nowIndex][i].innerHTML;
            }
        }

    })
    toAppendNext.className = 'primary-btn roll-btn';
    toAppendNext.style.marginBottom = "8px"
    toAppendNext.appendChild(spanTextNext);



    var nowCount = document.createElement("BUTTON");
    var nowCountText = document.createElement("span");
    nowCountText.innerHTML = '1/1';
    nowCount.className = 'primary-btn roll-btn';
    nowCount.style.marginBottom = "8px"
    nowCount.appendChild(nowCountText);


    let c = document.getElementsByClassName('feed-roll-btn')[0];
    c.children[0].removeChild(c.children[0].children[0]);
    c.children[0].children[0].innerHTML = '刷新下';

    c.children[0].addEventListener("click", function () {

            setTimeout(function (){
                let itemArray = []
                for(let i = 0 ; i < videos.length ; i ++){
                    itemArray.push(videos[i].cloneNode(true))
                }
                videoArray.push(itemArray)
                nowIndex = videoArray.length-1;
                nowCountText.innerHTML = (nowIndex+1)+'/'+videoArray.length
            },500)

    })

    c.insertBefore(toAppendNext,c.children[0])
    c.insertBefore(nowCount,c.children[0])
    c.insertBefore(toAppendLast,c.children[0])

}

})();