Bilibili-Evolved/registry/lib/components/utils/comments/content-replace/handlers/emoticon-to-emoticon.ts
2024-10-20 10:45:21 +08:00

19 lines
535 B
TypeScript

import { isUrl } from '../utils'
import { NodeContentReplacer } from './node-content-replacer'
export class EmoticonToEmoticonReplacer extends NodeContentReplacer {
isKeywordMatch(node: Node, keyword: string, target: string) {
if (node instanceof HTMLImageElement) {
return node.alt === keyword && isUrl(target)
}
return false
}
replaceContent(node: Node, keyword: string, target: string): Node[] {
if (!(node instanceof HTMLImageElement)) {
return []
}
node.src = target
return []
}
}