Files
browser-scripts/scripts/ttv-obfuscated-names/util.ts
T
zomo 6218d6bad1 changed observer callback
update names based on the element from the mutation event rather than checking the chatbox for unchecked messages each mutation
2026-04-19 19:01:01 -05:00

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)
}