B站播单按时间统计进度

F12打开控制台,直接拷贝以下代码回车,注意修改页号为当前页

var targetPageNum = 1; //修改为当前观看到的页号,第一个为1。
var menuList = $(jQuery('.list-box .duration'));
if(targetPageNum < 0 || targetPageNum > menuList.length) {
    alert("页号范围为0-" + menuList.length);
}else {
    var currentHour = caculateHour(targetPageNum);
    var totalHour = caculateHour(menuList.length);
    var percent = ((currentHour / totalHour) * 100).toFixed(2) + "%";
    console.log("当前播单观看进度:" + percent + "。观看总时长" + currentHour.toFixed(2) + "小时,播单总时长" + totalHour.toFixed(2) + "小时");
}

function caculateHour(index) {
    let hour = 0.0;
    for(var i = 0; i < index; i++) {
        let hourArr = menuList[i].innerText.split(":");
        
        if(hourArr.length === 4) {
            hour += parseInt(hourArr[0]) * 24.0;
            hour += (parseInt(hourArr[1]) * 1.0);
            hour += (parseInt(hourArr[2]) * 1.0 / 60);
            hour += (parseInt(hourArr[3]) * 1.0 / 3600);
        }

        if(hourArr.length === 3) {
            hour += parseInt(hourArr[0]) * 1.0;
            hour += (parseInt(hourArr[1]) * 1.0 / 60);
            hour += (parseInt(hourArr[2]) * 1.0 / 3600);
        }

        if(hourArr.length === 2) {
            hour += (parseInt(hourArr[0]) * 1.0 / 60);
            hour += (parseInt(hourArr[1]) * 1.0 / 3600);
        }

        if(hourArr.length === 1) {
            hour += (parseInt(hourArr[0]) * 1.0 / 3600);
        }
    }

    return hour;
}

  参考:

https://github.com/xnuwu/bilibili-percent

 
上一篇:考研机试 18.特殊乘法


下一篇:Eos持久化实体