本帖最后由 一个学渣 于 2024-2-27 13:12 编辑
例如如下合集视频,播放单个视频不会记录进度,每次都重新开始。
https://www.bilibili.com/video/BV1oJ4m1W7UD/?spm_id_from=333.788&vd_source=41a8a53d53212f30c2f1f0e069cf966e
我想在脚本的这个部分,加入记录合集中单个视频的“播放进度并恢复”功能,该怎么写?
有没有大佬帮写下啊?
[Java] 纯文本查看 复制代码 /* 记录播放速度的信息 */
let rateKey = "_h5_player_playback_rate_"
// 修改
let url = window.location.href;
let url2 = document.querySelector('.first-line-title')?.href || 'not_season';
const regex = /\/(BV\w+)/;
const match = url.match(regex);
if(match){
let bvNumber = match[1];
// 如果是合集,用合集id替换BV
if(url2 != 'not_season'){
let regex2 = /\?(sid=\w+)/;
let match2 = url2.match(regex2)[1].replace('sid=', '');
console.log("合集",match2);
bvNumber =match2;
}
rateKey += bvNumber;
}else if(url.includes("bvid")){
rateKey += url.substr(url.lastIndexOf("bvid=")+5)
}
console.log("设置播放速度",rateKey,curPlaybackRate,)
!isInCrossOriginFrame() && window.localStorage.setItem(rateKey, curPlaybackRate);
t.playbackRate = curPlaybackRate;
delete player.playbackRate;
player.playbackRate = curPlaybackRate;
try {
originalMethods.Object.defineProperty.call(Object, player, 'playbackRate', {
configurable: true,
get: function () {
return curPlaybackRate
},
set: function () {}
});
} catch (e) {
debug.error('解锁playbackRate失败', e);
}
/* 本身处于1倍播放速度的时候不再提示 */
if (!num && curPlaybackRate === 1) {
return true
} else {
!notips && t.tips(i18n.t('tipsMsg.playspeed') + player.playbackRate);
}
},
|