b站自动点赞投币

自动b站点赞投币

// ==UserScript==
// @name         b站自动点赞投币
// @namespace    http://tampermonkey.net/
// @version      0.98
// @description  自动b站点赞投币
// @author       whiteGoose
// @match        https://www.bilibili.com/video/BV*
// @icon         http://www.bilibili.com/favicon.ico
// @require		 https://code.jquery.com/jquery-3.7.1.min.js
// @require		 https://cdn.jsdelivr.net/npm/sweetalert2@11.12.2/dist/sweetalert2.all.min.js
// @license      MIT
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_deleteValue
// @grant GM_listValues
// ==/UserScript==

function GetUp() {
    let name = $(".up-avatar").attr("href");
    //    console.log(name);
    if (name != undefined) {
        name = name.split("/")[3];
        return name;
    }
}
function GetUps(){
    let name = $(".membersinfo-upcard");
    console.log(name.length);
    for (var i = 0; i < name.length; i++) {
        console.log(name[i].children[0].href.split("/")[3]);
    }
    return name;
}
function GetUpName() {
    let name = $("#mirror-vdcon > div.right-container.is-in-large-ab > div > div.up-panel-container > div.up-info-container > div.up-info--right > div.up-info__detail > div > div.up-detail-top > a.up-name.is_vip");
    name = name.text().trim();
    if (name == "") {
        name = $("#mirror-vdcon > div.right-container.is-in-large-ab > div > div.up-panel-container > div.up-info-container > div.up-info--right > div.up-info__detail > div > div.up-detail-top > a.up-name");
        name = name.text().trim();
    }
    return name;
}
function AddId() {
    let id = GetId();
    GetUpName();
    if (id == "None") {
        GM_setValue(GetUp(), [GetUpName(), 0]);  //数字0,1,2,3.只点赞,投一个币,投两个币,三连
        console.log("已添加");
        Init();
    }
    //    console.log(id);
}
function GetId() {
    let result = GM_getValue(GetUp(), "None");
    return result;
}
function DeleteId() {
    let deleteResult = GM_deleteValue(GetUp());
    console.log("已删除");
    Init();
}
function GetListId() {
    console.log(GM_listValues());
}
function GetListName() {
    let list = GM_listValues();
    let data=[];
    for (var i = 0; i < list.length; i++) {
        // console.log(GM_getValue(list[i]),list[i]);
        let status=GM_getValue(list[i]);
        let result={'uid':list[i],'name':status[0],'mode':status[1]}
        data.push(result)
    }
    console.log(data)
    return data;
}
//投币
function toubi(result=null) {
    //    console.log("tou?");
    let dianzanr = $("#arc_toolbar_report > div.video-toolbar-left > div.video-toolbar-left-main > div:nth-child(1) > div").attr("class") == "video-like video-toolbar-left-item on";
    if (dianzanr == true) return false;
    let toubis = $("#arc_toolbar_report > div.video-toolbar-left > div.video-toolbar-left-main > div:nth-child(2) > div");
    toubis.click();
    console.log(result[1])
    setTimeout(function () {
        if (result[1] == 1) {
            let quantity = $("body > div.bili-dialog-m > div > div > div.mc.clearfix > div.mc-box.left-con");
            quantity.click();
        }
        let confi = $("body > div.bili-dialog-m > div > div > div.coin-bottom > span");
        //    console.log(confi.text());
        confi.click();
    }, 1);
    return true;
}
//点赞
function dianzan() {
    let dianzanr = $("#arc_toolbar_report > div.video-toolbar-left > div.video-toolbar-left-main > div:nth-child(1) > div").attr("class") == "video-like video-toolbar-left-item on";
    // console.log(dianzanr);
    if (dianzanr == true) return true;
    let button = $("#arc_toolbar_report > div.video-toolbar-left > div.video-toolbar-left-main > div:nth-child(1) > div");
    if (button == undefined) return false;
    button.click();
    return true;
}
//初始化按钮
function Init() {
    let button = $("#gooseAdd");
    let button2 = $("#gooseSetting");
    let button3= $("#gooseInfo");
    // let buttons=$(".gooseCards");
    // if(buttons!="undefined"){
    //     buttons.each((index,element)=>{
    //         $(element).remove();
    //     })
    // }
    button.remove();
    button2.remove();
    button3.remove();
    SetButton();
}
//设置按钮
function SetButton() {
    // let upDiv = $("#mirror-vdcon > div.right-container.is-in-large-ab > div > div.up-panel-container > div.up-info-container > div.up-info--right > div.up-info__btn-panel");
    //关注行
    let upDiv2 = $("#mirror-vdcon > div.right-container.is-in-large-ab > div > div.up-panel-container > div.up-info-container > div.up-info--right > div.up-info__btn-panel > div");
    //up名字行
    let upDiv3 = $("#mirror-vdcon > div.right-container.is-in-large-ab > div > div.up-panel-container > div.up-info-container > div.up-info--right > div.up-info__detail > div > div.up-detail-top");
    let upDiv1 = $("#mirror-vdcon > div.right-container.is-in-large-ab > div > div.up-panel-container > div.up-info-container > div.up-info--left > div > a > div > div > img");
    let combinit = $(".membersinfo-upcard");
    let div4=$("#mirror-vdcon > div.right-container.is-in-large-ab > div > div.up-panel-container");
    let customerDiv=$("<div id='gooseCustomerDiv'></div>");
    div4.append(customerDiv);
    let ups=GetId();
    customerDiv.css({
        "text-align": "center",
    })
    let infoButton=InitInfoButton();
    customerDiv.append(infoButton);
    if(combinit.length!=0){
        console.log(ups)
    }else{
        if (ups != "None") {
            let settingButton = InitSettingButton();
            customerDiv.append(settingButton);
        }
        let button = InitButton();
        customerDiv.append(button);
    }
}
//获取添加的按钮
function InitButton() {
    let result = GetId();
    let value = "";
    if (result == "None") {
        value = "添加";
    } else {
        value = "删除";
    }
    let button = document.createElement("input");
    button.setAttribute("id", "gooseAdd");
    button.setAttribute("value", value);
    button.setAttribute("type", "button");
    let styles = "border-radius:6px;border-color:pink;margin-left:10px;height:auto;width:25%;background-color:white;"
    button.setAttribute('style', styles);
    if (value == "添加") {
        $(button).on("click", AddId);
    } else {
        $(button).on("click", DeleteId);
    }
    return button;
}
//获取设置按钮
function InitSettingButton() {
    let result = GetId()[1];
    let value=whatModeIs(result);
    let button = document.createElement("input");
    button.setAttribute("id", "gooseSetting");
    button.setAttribute("value", value);
    button.setAttribute("type", "button");
    let styles = "border-radius:6px;border-color:pink;margin-left:10px;height:auto;width:25%;background-color:white;"
    button.setAttribute('style', styles);
    button.addEventListener("click", setting);
    return button;
}
//获取信息按钮
function InitInfoButton(){
    let button=document.createElement("input");
    button.setAttribute("id", "gooseInfo");
    button.setAttribute("value","列表");
    button.setAttribute("type", "button");
    let styles = "border-radius:6px;border-color:pink;margin-left:10px;height:auto;width:25%;background-color:white;"
    button.setAttribute('style', styles);
    button.addEventListener("click",Info);
    return button;
}
//信息详情
function Info() {
    let text =
        "<table id='gooseTable'>" +
        "<thead>" +
        "<tr>" +
        "<td>uid</td>" +
        "<td>up名</td>" +
        "<td>设置</td>" +
        "<td>操作</td>" +
        "</tr>" +
        "</thead>" +
        "<tbody id='gooseUpsBody'>" +
        "</tbody>" +
        "</table>";
    Swal.fire({
        title: '自动点赞的列表',
        html: text,
        showConfirmButton: false,
        showCloseButton: true,
    })
    let data=GetListName();
    data.forEach((element) => {
        let uid = element['uid'];
        let name = element['name'];
        let mode =whatModeIs(element['mode']);
        let tr = `
        <tr>
            <td class="canclick" id="gooseUid">${uid}</td>
            <td class="canclick">${name}</td>
            <td class="canclick" id="gooseMode">${mode}</td>
            <td>删除</td>
        </tr>
        `;
        $("#gooseUpsBody").append(tr);
        $("#gooseTable").css({
            "width": "100%",
            "border-collapse": "collapse",
            "background-color":"#e9e9e9",
        })
        $("#gooseTable thead tr").css({
            "background-color":"lightskyblue",
        })
        $("#gooseTable tr td").css({
            "border": " 1px solid #ccc",
            "cursor":"pointer",
        })
    })
    $("#gooseTable tbody tr").each((index,element)=>{
        let uid=$(element).children()[0];
        let name=$(element).children()[1];
        let mode=$(element).children()[2];
        let del=$(element).children()[3];
        let thisId=$(uid).text()
        let thisName=$(name).text();
        if(thisId==GetUp()){
            $(element).css({"background-color":"#bae5ff"})
        }
        $(uid).click(()=>{
            // console.log($(uid).text(),$(uid).val())
            window.open("https://space.bilibili.com/"+$(uid).text(),"_blank")
        })
        $(name).click(()=>{
            window.open("https://space.bilibili.com/"+$(uid).text(),"_blank")
        })
        $(mode).click(()=>{
            let result = GM_getValue(thisId);
            result[1] = (result[1] + 1) % 3;
            GM_deleteValue(thisId);
            GM_setValue(thisId, [thisName, result[1]]);
            $(mode).text(whatModeIs(result[1]))
            // console.log(result);
            if(thisId==GetUp()) Init();
        })
        $(del).click(()=>{
            console.log($(element));
            GM_deleteValue($(uid).text());
            $(element).remove()
            if(thisId==GetUp()) Init();
        })
    })
}
function whatModeIs(id){
    let mode="";
    switch (id) {
        case 0:
            mode = "只点赞";
            break;
        case 1:
            mode = "投一个币";
            break;
        case 2:
            mode = "投两个币";
            break;
        case 3:
            mode = "三连";
            break;
    }
    return mode;
}
//设置 按钮的事件
function setting() {
    let list=GetId()
    list[1] = (list[1] + 1) % 3;
    GM_deleteValue(GetId());
    GM_setValue(GetUp(), [GetUpName(), list[1]]);
    Init();
}
function GetBV() {
    let URL = window.location.href.split("/")[4];
    return URL;
}
function IsJunmping(BV,send) {
    console.log(BV,send);
    console.log(BV!=GetBV());
    if(BV==null){
        console.log("这是刚进网页的时候");
    }
    if(BV==GetBV()&&send!=0){
        console.log("还没跳转哦")
        setTimeout(IsJunmping,3000,BV,send-=1)
    }
    if(BV!=GetBV()){
        console.log("跳转啦!")
        setTimeout(PageInit(),1);
        return true;
    }
    if(send==0){
        console.log("你是不是取消了呀?")
        return false;
    }
    console.log("what happend?");
}

console.log("i am loading!")
let youbian=false;
let alla=false;
let ended=false;
//页面初始化
function PageInit() {
    let mq = new MessageQueue(1000, 10);
    console.log("pageinit running")
    setTimeout(function () {
        mq.Clear()
        let BV=GetBV();
        mq.Add(function bangdingA() {
            let temp = $("#reco_list .framepreview-box a,#reco_list .info > a");
            if (temp == undefined) return false;
            temp.each((index,element)=>{
                $(element).one('click',function(){
                    IsJunmping(BV,5)
                    mq.Clear()
                });  //绑定所有的a标签,只要点击则进行判断
            })
            return true;
        });
        mq.Add(function bangdingYoubian() {
            let temp = $(".video-episode-card__info-title");
            if (temp == undefined) return false;
                temp.one('click',function(){
                    IsJunmping(BV,5)
                    mq.Clear()
                });  //绑定所有的订阅里的视频,只要点击则进行判断
            return true;
        });
        mq.Add(function videoEnd() {
            let temp = $("#bilibili-player > div > div > div.bpx-player-primary-area > div.bpx-player-video-area > div.bpx-player-ending-wrap > div.bpx-player-ending-panel > div > div > div.bpx-player-ending-related > a");
            if (temp == undefined) return false;
            temp.each((index,element)=>{
                $(element).one('ended', function videoEndCatch() {
                    setTimeout(function () {                        
                        let lianBo=$("#mirror-vdcon > div.right-container.is-in-large-ab > div > div:nth-child(8) > div.base-video-sections-v1 > div.video-sections-head > div.video-sections-head_first-line > div.first-line-right > span > span.switch-button.on");
                        let lianBo2=$("#reco_list > div.next-play > p > span > span.switch-button.on");
                        let flag=lianBo.length!=0?true:false;
                        let flag2=lianBo2.length!=0?true:false;
                        if(flag||flag2){
                            $("a").one('click',function t(){
                                IsJunmping(BV,5)
                                mq.Clear()
                            });  //绑定视频结束时的视频,只要点击则进行判断
                        }
                    }, 1);
                });
            })
            return true;
        });
        Init();            //初始化按钮
        //合作视频卡片
        let combinit = $(".membersinfo-upcard");
        let result;
        let max=0;
        if(combinit.length!=0){
            console.log("这是合作视频")
            combinit.each((index,element)=>{
                let up_uid=$(element.children[1].children[0]).attr("href").split("/")[3]
                let up_value=GM_getValue(up_uid,"None")
                if(up_value!="None"){
                    if(up_value[1]>max){
                        max=up_value[1]
                    }
                    result=[up_value[0],max]
                }
            })
        }else{
            result = GetId();
        }
        
        if (result != "None") {    //如果被加入了,则投币
            switch (result[1]) {
                case 0:
                    mq.Add(dianzan);
                    break;
                case 1:
                case 2:
                    mq.Add(function temptou(){
                        toubi(result)
                    });
                    break;
                case 3:
                    break;
            }
        }
        mq.Run();
    }, 4000);
}
class MessageQueue {
    functionArray = [];
    timeouts;
    constructor(timeout, timeouts = 10) {
        this.timeout = timeout;
        this.timeouts = timeouts;
        this.timeouted = 0;
    }
    Add(func) {
        this.functionArray.push(func);
    }
    Print() {
        console.log(this.functionArray);
        // this.functionArray.forEach(element => {
        //     element();
        // });
        // console.log("print is ending");
    }
    async Run() {
        if (this.isRunning) {
            console.log("任务队列已经在运行中,无法重复调用");
            return; // 如果正在运行,则返回
        }
        this.isRunning = true; // 标记为正在运行
        console.log("函数列表:", this.functionArray, "超时计数器:", this.timeouted);
        while (this.functionArray.length > 0) {
            let result;
            const currentFunc = this.functionArray[0];
            result = currentFunc();
            console.log("现在正在运行的函数名为:", currentFunc.name);
            if (result === true || result === 1) {
                this.timeouted = 0;
                this.functionArray.shift(); // 移除已完成的函数
            } else {
                this.timeouted++;
            }
            if (this.timeouted === this.timeouts) {
                console.log("超时!超时的函数为:", currentFunc.name);
                this.isRunning = false; // 结束运行
                this.functionArray =[];
                return false;
            }
            let timeout = (this.timeouted * 150) + 1;
            await this.delay(timeout); // 延时函数
        }

        console.log("所有任务已完成");
        this.isRunning = false; // 结束运行
        return true;
    }
    Clear() {
        this.functionArray = [];
        this.isRunning = false; // 停止运行标志
        this.delay((this.timeouted * 150) + 1)
        this.timeouted = 0; // 重置超时计数器
    }
    delay(ms) {
        return new Promise(resolve => setTimeout(resolve, ms));
    }
}

(function () {
    window.onload = function () {
        // console.log(GetUp());
        PageInit();
    }
})();