feat: add discover page with surprise me and deduplication

This commit is contained in:
2026-05-02 16:27:16 +02:00
committed by Mikkel Elvers
parent e89e05c6e8
commit c708afe4fe
7 changed files with 231 additions and 9 deletions

View File

@@ -1,13 +1,12 @@
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
console.log('Dedupe running...')
const seen = new Set<string>()
container.querySelectorAll('[data-id]').forEach((item) => {
const elements = document.querySelectorAll('[data-id]')
console.log('Found elements:', elements.length)
elements.forEach((item) => {
const id = item.getAttribute('data-id')
if (id && seen.has(id)) {
console.log('Removing duplicate:', id)
item.remove()
} else if (id) {
seen.add(id)
@@ -15,4 +14,10 @@ const dedupe = (): void => {
})
}
dedupe()
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', dedupe)
} else {
dedupe()
}
// Also run on window load to be sure
window.addEventListener('load', dedupe)