本帖最后由 梦汐 于 2022-11-4 11:01 编辑
哔哩哔哩的云端播放记录有猫饼,得改本地保存才能正常使用[JavaScript] 纯文本查看 复制代码 (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', `[url=https://api.bilibili.com/x/web-interface/view?bvid=]https://api.bilibili.com/x/web-interface/view?bvid=[/url]${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', `[url=https://api.bilibili.com/x/player/v2?aid=]https://api.bilibili.com/x/player/v2?aid=[/url]${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)
} |