changed observer callback
update names based on the element from the mutation event rather than checking the chatbox for unchecked messages each mutation
This commit is contained in:
@@ -1,31 +1,33 @@
|
||||
import { NameConfigInstance } from './options'
|
||||
|
||||
export interface ChatMessage {
|
||||
username: string
|
||||
isMod: boolean
|
||||
}
|
||||
|
||||
export function innermostElement<T extends Element>(elem: T) {
|
||||
export function innermostElement<T extends Element, U extends Element>(
|
||||
elem: T
|
||||
): U {
|
||||
if (elem.children.length === 0) {
|
||||
return elem
|
||||
// U is the type of the innermost element
|
||||
// since we're at the innermost element, we know T = U
|
||||
// so we can cast elem (T) to U
|
||||
return elem as any as U
|
||||
}
|
||||
return innermostElement(elem.children[0])
|
||||
let child = elem.children[0]
|
||||
return innermostElement<Element, U>(child)
|
||||
}
|
||||
|
||||
export function usernameTemplateSuffix(newChatMessage: NameConfigInstance) {
|
||||
if (newChatMessage.nameCount === 0) {
|
||||
return ''
|
||||
export function elementTreeFind<T extends Element, U extends Element>(
|
||||
elem: T,
|
||||
fn: (elem: Element) => boolean
|
||||
): U | null {
|
||||
if (fn(elem)) {
|
||||
// U is the type of the element that satisfies fn()
|
||||
// since we're at the element that satisfies fn(), we know T = U
|
||||
// so we can cast elem (T) to U
|
||||
return elem as any as U
|
||||
}
|
||||
|
||||
return `${newChatMessage.nameCount}`
|
||||
}
|
||||
|
||||
export function usernameImageTemplateSuffix(
|
||||
newChatMessage: NameConfigInstance
|
||||
) {
|
||||
if (newChatMessage.nameCount === 0) {
|
||||
return ''
|
||||
if (!elem.parentElement) {
|
||||
return null
|
||||
}
|
||||
|
||||
return `${newChatMessage.nameCount}`
|
||||
return elementTreeFind<Element, U>(elem.parentElement, fn)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user