fetch("https://api.bilibili.com/x/player/pagelist?bvid=BV1bs41197KN&jsonp=jsonp") .then(response => response.json()) .then(function(info){ let data = info.data; let urlSearchParams = newURLSearchParams(window.location.search); let params = Object.fromEntries(urlSearchParams.entries()); let currentPage = params.p; let isCurrentPage = function(item){return (item.page==currentPage);};
let wanted = data.filter(isCurrentPage); let pageIndex = data.findIndex(isCurrentPage);
let restPages = data.slice(pageIndex); // duration 的单位是秒 let restTime = restPages.map(item => item.duration).reduce((a, b) => a + b) / 60; alert(`当前正在观看第 ${currentPage} 节: "${wanted[0].part}"\n剩余时间: ${parseInt(restTime)} 分钟`); }) .catch(err => { console.log('caught it!',err); });
})(); })
脚本调试方法
谷歌浏览器 -> F12 -> “Source” Tab -> “Snippets” -> “Net Snippets” -> write your script and enjoy debuging…