mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
63 lines
1.9 KiB
TypeScript
63 lines
1.9 KiB
TypeScript
const url = {
|
|
include: [
|
|
'//www.bilibili.com/video/',
|
|
'//www.bilibili.com/bangumi/',
|
|
]
|
|
}
|
|
const styleID = 'showCoverBeforePlayStyle'
|
|
let lastCid: string
|
|
const entry = () => {
|
|
if (url.include.every(it => !document.URL.includes(it))) {
|
|
return
|
|
}
|
|
resources.applyStyle(styleID)
|
|
const removeCover = () => document.body.style.removeProperty('--cover-url')
|
|
const isBwpVideo = unsafeWindow.__ENABLE_WASM_PLAYER__ || dq('bwp-video')
|
|
const proto = isBwpVideo ? BwpElement.prototype : HTMLVideoElement.prototype
|
|
const originalPlay = proto.play
|
|
proto.play = function (...args: any[]) {
|
|
removeCover()
|
|
return originalPlay.call(this, ...args)
|
|
}
|
|
const showCover = async () => {
|
|
const aid = await SpinQuery.select(() => unsafeWindow.aid)
|
|
if (!aid) {
|
|
console.warn('[播放前显示封面] 未找到av号')
|
|
return
|
|
}
|
|
const { cid } = unsafeWindow
|
|
if (cid === lastCid || !cid) {
|
|
return
|
|
}
|
|
lastCid = cid
|
|
// const video = await SpinQuery.select('video') as HTMLVideoElement
|
|
// if (!video) {
|
|
// console.warn('[播放前显示封面] 未找到视频')
|
|
// return
|
|
// }
|
|
const { VideoInfo } = await import('../video-info')
|
|
const info = new VideoInfo(aid)
|
|
await info.fetchInfo()
|
|
// const video = dq('video') as HTMLVideoElement
|
|
// if (!video || !video.paused) {
|
|
// return
|
|
// }
|
|
document.body.style.setProperty('--cover-url', `url('${info.coverUrl}')`)
|
|
// video.addEventListener('play', () => {
|
|
// removeCover()
|
|
// }, { once: true })
|
|
// unsafeWindow.trackingVideo = video
|
|
}
|
|
Observer.videoChange(showCover)
|
|
// if (document.URL.includes('//www.bilibili.com/bangumi/')) {
|
|
// Observer.videoChange(showCover)
|
|
// } else {
|
|
// showCover()
|
|
// }
|
|
}
|
|
entry()
|
|
export default {
|
|
reload: () => resources.applyStyle(styleID),
|
|
unload: () => resources.removeStyle(styleID),
|
|
}
|