mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
feat: 添加推荐列表自动连播处理器
This commit is contained in:
parent
541fa51bf1
commit
3a9b500176
@ -2,9 +2,9 @@ import { matchUrlPattern } from '@/core/utils'
|
||||
import { AutoplayActionType } from '../AutoplayActionType'
|
||||
import { BaseAutoplayHandler } from './BaseAutoplayHandler'
|
||||
|
||||
/** 自动连播处理器-推荐视频 */
|
||||
/** 自动连播处理器-推荐视频(接下来播放) */
|
||||
export class RecommendAutoplayHandler extends BaseAutoplayHandler {
|
||||
type = '推荐视频'
|
||||
type = '推荐视频(接下来播放)'
|
||||
|
||||
async match() {
|
||||
const videoUrl = '//www.bilibili.com/video/'
|
||||
|
||||
@ -0,0 +1,52 @@
|
||||
import { matchUrlPattern } from '@/core/utils'
|
||||
import { AutoplayActionType } from '../AutoplayActionType'
|
||||
import { BaseAutoplayHandler } from './BaseAutoplayHandler'
|
||||
import { bangumiUrls, favoriteListUrls, watchlaterUrls } from '@/core/utils/urls'
|
||||
|
||||
/** 自动连播处理器-推荐视频(列表第一个) */
|
||||
export class RecommendListAutoplayHandler extends BaseAutoplayHandler {
|
||||
type = '推荐视频(列表第一个)'
|
||||
|
||||
async match() {
|
||||
const videoUrl = '//www.bilibili.com/video/'
|
||||
let matchUrl = matchUrlPattern(videoUrl)
|
||||
matchUrl = matchUrl || bangumiUrls.some(url => matchUrlPattern(url))
|
||||
matchUrl = matchUrl || favoriteListUrls.some(url => matchUrlPattern(url))
|
||||
matchUrl = matchUrl || watchlaterUrls.some(url => matchUrlPattern(url))
|
||||
|
||||
return matchUrl && this.getFirstRecommend() !== null
|
||||
}
|
||||
|
||||
async shouldAutoplay() {
|
||||
return BaseAutoplayHandler.shouldAutoplayWithAutoHandler(
|
||||
BaseAutoplayHandler.settings.options.recommendListAutoplayAction as AutoplayActionType,
|
||||
() => false,
|
||||
)
|
||||
}
|
||||
|
||||
async setupAutoPlay(enable: boolean) {
|
||||
// 原网页不存在的功能,不需要专门禁用
|
||||
if (!enable) {
|
||||
return
|
||||
}
|
||||
|
||||
const video = document.querySelector('video')
|
||||
|
||||
// 在视频播放完时触发一次
|
||||
video.addEventListener(
|
||||
'ended',
|
||||
() => {
|
||||
const a = this.getFirstRecommend() as HTMLElement
|
||||
a.click()
|
||||
},
|
||||
{ once: true },
|
||||
)
|
||||
}
|
||||
|
||||
/** 获取推荐视频列表首个视频链接 */
|
||||
getFirstRecommend() {
|
||||
return document.querySelector(
|
||||
'.rec-list .pic a,.recommend-list-container .pic-box a,.plp-r div[class^=RecommendItem_wrap] a',
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -14,6 +14,7 @@ import { PlaylistAutoplayHandler } from './handlers/PlaylistAutoplayHandler'
|
||||
import { RecommendAutoplayHandler } from './handlers/RecommendAutoplayHandler'
|
||||
import { WatchLaterAutoplayHandler } from './handlers/WatchLaterAutoplayHandler'
|
||||
import { MultipartAutoplayHandler } from './handlers/MultipartAutoplayHandler'
|
||||
import { RecommendListAutoplayHandler } from './handlers/RecommendListAutoplayHandler'
|
||||
|
||||
export const logger = useScopedConsole('定制自动连播行为')
|
||||
|
||||
@ -43,6 +44,7 @@ const entry: ComponentEntry = async ({ metadata, settings }) => {
|
||||
BaseAutoplayHandler.register(new PlaylistAutoplayHandler())
|
||||
BaseAutoplayHandler.register(new RecommendAutoplayHandler())
|
||||
BaseAutoplayHandler.register(new WatchLaterAutoplayHandler())
|
||||
BaseAutoplayHandler.register(new RecommendListAutoplayHandler())
|
||||
}
|
||||
|
||||
// 入口代码
|
||||
@ -90,7 +92,12 @@ export const component = defineComponentMetadata({
|
||||
dropdownEnum: AutoplayActionType,
|
||||
},
|
||||
recommendAutoplayAction: {
|
||||
displayName: '自动连播行为-推荐视频',
|
||||
displayName: '自动连播行为-推荐视频(接下来播放)',
|
||||
defaultValue: AutoplayActionType.AUTO,
|
||||
dropdownEnum: AutoplayActionType,
|
||||
},
|
||||
recommendListAutoplayAction: {
|
||||
displayName: '自动连播行为-推荐视频(列表第一个)',
|
||||
defaultValue: AutoplayActionType.AUTO,
|
||||
dropdownEnum: AutoplayActionType,
|
||||
},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user