mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
Add CommentContentReplaceMap plugin data
This commit is contained in:
parent
83f70e949b
commit
437b7ad2a2
@ -1,4 +1,4 @@
|
||||
import { registerData } from '@/plugins/data'
|
||||
import { registerAndGetData } from '@/plugins/data'
|
||||
import { getComponentSettings } from '@/core/settings'
|
||||
import { CommentContentReplaceHandler } from './types'
|
||||
import { CommentContentReplaceOptions } from '../options'
|
||||
@ -19,10 +19,12 @@ const contentReplacers: NodeContentReplacer[] = [
|
||||
new RecursiveReplacer(),
|
||||
]
|
||||
|
||||
export const defaultHandler: CommentContentReplaceHandler = content => {
|
||||
export const CommentContentReplaceMap = 'commentContentReplace.map'
|
||||
const defaultHandler: CommentContentReplaceHandler = content => {
|
||||
const { replaceMap } = options
|
||||
const [finalReplaceMap] = registerAndGetData(CommentContentReplaceMap, replaceMap)
|
||||
content.forEach(node => {
|
||||
Object.entries(replaceMap).forEach(([from, to]) => {
|
||||
Object.entries(finalReplaceMap).forEach(([from, to]) => {
|
||||
const replacer = contentReplacers.find(r => r.isKeywordMatch(node, from, to))
|
||||
if (!replacer) {
|
||||
return
|
||||
@ -34,4 +36,4 @@ export const defaultHandler: CommentContentReplaceHandler = content => {
|
||||
}
|
||||
|
||||
export const CommentContentReplaceHandlers = 'commentContentReplace.handlers'
|
||||
export const handlers = registerData(CommentContentReplaceHandlers, [defaultHandler])
|
||||
export const handlers = registerAndGetData(CommentContentReplaceHandlers, [defaultHandler])
|
||||
|
||||
Loading…
Reference in New Issue
Block a user