【JS】哔哩哔哩 播放进度条
本帖最后由 梦汐 于 2022-11-4 11:01 编辑哔哩哔哩的云端播放记录有猫饼,得改本地保存才能正常使用(function videoList() {
$('.small-item.fakeDanmu-item').each(
function () {
setTimeoutW(Progress_Indicators, 10, this, $(this).attr('data-aid'))
}
)
}())
function Progress_Indicators(node, id) {
var json = getInfo(id)
var progress = Math.trunc(GetPercent(json.response.data.last_play_time / 1000, json.duration))
//----------------------------------------------------------------------------------------------------
var progress_ui = document.createElement('div');
$(progress_ui).attr('class', 'progress').attr('style', 'top: 0px;position: absolute;width: 100%;height: 4px;background-color: #909090;').html(`<div id="content" style="width: ${progress}%;height: 100%;background-color: #f00;"></div>`);
var node = $(node).find('.cover').append(progress_ui);
//----------------------------------------------------------------------------------------------------
function getInfo(bvid) {
this.httpRequest = new XMLHttpRequest();
httpRequest.open('GET', `https://api.bilibili.com/x/web-interface/view?bvid=${bvid}`, false)//改bvid为avid就是支持avid了
httpRequest.send(null);
var json = JSON.parse(httpRequest.responseText);
this.aid = json.data.aid
this.cid = json.data.cid
this.duration = json.data.duration
//--------------------------------------------------------------------------------------------------------
httpRequest.abort();
httpRequest.open('GET', `https://api.bilibili.com/x/player/v2?aid=${aid}&cid=${cid}`, false);
httpRequest.withCredentials = true;//必须附加cookie信息,否则返回的是匿名数据
httpRequest.send(null);
var json = JSON.parse(httpRequest.responseText);
//--------------------------------------------------------------------------------------------------------
return { response: json, duration: duration }
}
function GetPercent(num, total) {
num = parseFloat(num);
total = parseFloat(total);
if (isNaN(num) || isNaN(total)) {
return 0;
}
return total <= 0 ? "0%" : (Math.round(num / total * 10000) / 100.00);
}
}
function setTimeoutW(func, time, ...parameters) {
setTimeout(
(function (func, ...parameters) {
return function () {
func(...parameters)
}
}(func, ...parameters)
), time)
} 赞!!!!! 代码的url格式貌似有点问题,建议禁用链接识别后再保存
赞!!!!! 学习了!!! 有了这和工具,从此b站任我飞 厉害了!! 谢谢分享,又学到了 感谢楼主,收藏了 感谢楼主分享!
页:
[1]