6218d6bad1
update names based on the element from the mutation event rather than checking the chatbox for unchecked messages each mutation
34 lines
963 B
TypeScript
34 lines
963 B
TypeScript
export interface ChatMessage {
|
|
username: string
|
|
isMod: boolean
|
|
}
|
|
|
|
export function innermostElement<T extends Element, U extends Element>(
|
|
elem: T
|
|
): U {
|
|
if (elem.children.length === 0) {
|
|
// 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
|
|
}
|
|
let child = elem.children[0]
|
|
return innermostElement<Element, U>(child)
|
|
}
|
|
|
|
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
|
|
}
|
|
if (!elem.parentElement) {
|
|
return null
|
|
}
|
|
return elementTreeFind<Element, U>(elem.parentElement, fn)
|
|
}
|