refactor: extract inline scripts to dedupe and sort_filter modules

This commit is contained in:
2026-04-21 01:22:09 +02:00
parent bece1a970a
commit 28cacdd7c5
5 changed files with 46 additions and 28 deletions

18
static/dedupe.ts Normal file
View File

@@ -0,0 +1,18 @@
const dedupe = (): void => {
const script = document.currentScript as HTMLScriptElement | null
if (!script) return
const containerId = script.getAttribute('data-container')
const container = containerId ? document.getElementById(containerId) : document
if (!container) return
const seen = new Set<string>()
container.querySelectorAll('[data-id]').forEach((item) => {
const id = item.getAttribute('data-id')
if (id && seen.has(id)) {
item.remove()
} else if (id) {
seen.add(id)
}
})
}
dedupe()