mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
Improve expandDanmakuList
- Add option maxDanmakuCount (#2972) - 3.x player support (#3187)
This commit is contained in:
parent
6fdb1b9b2a
commit
b9dfb5e30d
@ -2,13 +2,39 @@ import { ComponentEntry, ComponentMetadata } from '@/components/types'
|
|||||||
import { videoChange } from '@/core/observer'
|
import { videoChange } from '@/core/observer'
|
||||||
import { select } from '@/core/spin-query'
|
import { select } from '@/core/spin-query'
|
||||||
import { matchUrlPattern } from '@/core/utils'
|
import { matchUrlPattern } from '@/core/utils'
|
||||||
|
import { useScopedConsole } from '@/core/utils/log'
|
||||||
import { mediaListUrls, videoAndBangumiUrls } from '@/core/utils/urls'
|
import { mediaListUrls, videoAndBangumiUrls } from '@/core/utils/urls'
|
||||||
|
|
||||||
|
const getDanmakuCount = async () => {
|
||||||
|
const countElement = await select('.bilibili-player-video-info-danmaku-number, .bpx-player-video-info-dm')
|
||||||
|
/*
|
||||||
|
3.x: 已装填 n 条弹幕
|
||||||
|
2.x: n
|
||||||
|
*/
|
||||||
|
const countText = countElement?.textContent ?? ''
|
||||||
|
const countMatch = countText.match(/\d+/)
|
||||||
|
if (!countMatch) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
const count = parseInt(countMatch[0])
|
||||||
|
if (Number.isNaN(count)) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
||||||
const entry: ComponentEntry = async ({ settings: { options } }) => {
|
const entry: ComponentEntry = async ({ settings: { options } }) => {
|
||||||
|
const console = useScopedConsole('展开弹幕列表')
|
||||||
videoChange(async () => {
|
videoChange(async () => {
|
||||||
if (mediaListUrls.some(url => matchUrlPattern(url)) && options.ignoreMediaList) {
|
if (mediaListUrls.some(url => matchUrlPattern(url)) && options.ignoreMediaList) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
const danmakuCount = await getDanmakuCount()
|
||||||
|
console.log(`当前弹幕量: ${danmakuCount}`)
|
||||||
|
if (danmakuCount !== null && danmakuCount > options.maxDanmakuCount) {
|
||||||
|
console.log(`超过了最大弹幕数量 ${options.maxDanmakuCount}, 跳过展开`)
|
||||||
|
return
|
||||||
|
}
|
||||||
const danmakuBox = await select('.bui-collapse-wrap')
|
const danmakuBox = await select('.bui-collapse-wrap')
|
||||||
if (danmakuBox && danmakuBox.classList.contains('bui-collapse-wrap-folded')) {
|
if (danmakuBox && danmakuBox.classList.contains('bui-collapse-wrap-folded')) {
|
||||||
const button = await select('.bui-collapse-header') as HTMLDivElement
|
const button = await select('.bui-collapse-header') as HTMLDivElement
|
||||||
@ -23,13 +49,17 @@ export const component: ComponentMetadata = {
|
|||||||
entry,
|
entry,
|
||||||
tags: [componentsTags.video],
|
tags: [componentsTags.video],
|
||||||
description: {
|
description: {
|
||||||
'zh-CN': '每次加载视频时自动展开弹幕列表.',
|
'zh-CN': '每次加载视频时自动展开弹幕列表, 如果弹幕装载量超过 `最大弹幕数量`, 则不展开以免对页面造成卡顿.',
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
ignoreMediaList: {
|
ignoreMediaList: {
|
||||||
defaultValue: true,
|
defaultValue: true,
|
||||||
displayName: '合集类页面不自动展开',
|
displayName: '合集类页面不自动展开',
|
||||||
},
|
},
|
||||||
|
maxDanmakuCount: {
|
||||||
|
defaultValue: 500,
|
||||||
|
displayName: '最大弹幕数量',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
urlInclude: [
|
urlInclude: [
|
||||||
...videoAndBangumiUrls,
|
...videoAndBangumiUrls,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user