mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
fix(default-video-speed): 防止在非视频页面抛出异常
This commit is contained in:
parent
335ff2ce87
commit
a157745cac
@ -38,22 +38,19 @@ const addSpeedToSetting = (speed: supportedVideoPlayRates, aid: string, force =
|
||||
settings.defaultVideoSpeedList = settings.defaultVideoSpeedList
|
||||
}
|
||||
|
||||
Observer.videoChange(async () => {
|
||||
if (settings.useDefaultVideoSpeed) {
|
||||
await setVideoSpeed((getSpeedFromSetting() || getDefaultVideoSpeed()) as supportedVideoPlayRates)
|
||||
}
|
||||
})
|
||||
const setup = _.once(async () => {
|
||||
const menu = await SpinQuery.select(".bilibili-player-video-btn-speed-menu")
|
||||
|
||||
SpinQuery.select(".bilibili-player-video-btn-speed-menu").then(value => {
|
||||
if (!value) {
|
||||
if (!menu) {
|
||||
throw "speed menu not found!"
|
||||
}
|
||||
Observer.all(value, (mutations) => {
|
||||
|
||||
Observer.all(menu, (mutations) => {
|
||||
if (!settings.useDefaultVideoSpeed) {
|
||||
return
|
||||
}
|
||||
mutations.forEach(mutation => {
|
||||
const selectedSpeedOption = mutation.target as HTMLLIElement;
|
||||
const selectedSpeedOption = mutation.target as HTMLLIElement
|
||||
if (selectedSpeedOption.classList.contains("bilibili-player-active")) {
|
||||
const currentSpeed = parseFloat(selectedSpeedOption.dataset.value || '1')
|
||||
if (!unsafeWindow.aid) {
|
||||
@ -64,3 +61,10 @@ SpinQuery.select(".bilibili-player-video-btn-speed-menu").then(value => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Observer.videoChange(async () => {
|
||||
await setup()
|
||||
if (settings.useDefaultVideoSpeed) {
|
||||
await setVideoSpeed((getSpeedFromSetting() || getDefaultVideoSpeed()) as supportedVideoPlayRates)
|
||||
}
|
||||
})
|
||||
|
||||
Loading…
Reference in New Issue
Block a user