mirror of
https://github.com/kuhyx/steam-backlog-enforcer.git
synced 2026-11-11 20:13:49 +01:00
Labels, descriptions and lock reasons are spoken only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
27 lines
1.0 KiB
TypeScript
27 lines
1.0 KiB
TypeScript
// Textgate guard helper (textgate-rework R6): the words an element paints.
|
|
// Spoken-only text (.sr-only, [hidden]) and content the caller passes in
|
|
// `allowed` (game names, server messages) do not count. aria-hidden text
|
|
// still paints, so it counts.
|
|
|
|
const WORD_RE = /[A-Za-z]{2,}/
|
|
|
|
function spokenOnly(el: Element | null): boolean {
|
|
for (let cur = el; cur; cur = cur.parentElement) {
|
|
if (cur.classList.contains('sr-only')) return true
|
|
if (cur instanceof HTMLElement && cur.hidden) return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
/** Visible text nodes holding a word of 2+ letters, minus `allowed` content. */
|
|
export function visibleWords(root: Element, allowed: readonly string[] = []): string[] {
|
|
const out: string[] = []
|
|
const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT)
|
|
for (let n = walker.nextNode(); n; n = walker.nextNode()) {
|
|
const t = n.textContent?.trim() ?? ''
|
|
if (!WORD_RE.test(t) || spokenOnly(n.parentElement) || allowed.includes(t)) continue
|
|
out.push(t)
|
|
}
|
|
return out
|
|
}
|