B站播单按时间统计进度

时间:2021-03-05 13:13:11   收藏:0   阅读:0

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

 
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!