refactor: extract inline scripts to dedupe and sort_filter modules
This commit is contained in:
18
static/dedupe.ts
Normal file
18
static/dedupe.ts
Normal 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()
|
||||
Reference in New Issue
Block a user