// Universal read-only viewer: // /share/:token -> fetch /api/shared/:token (secret link) // /share?idea=:id -> fetch /api/public/ideas/:id (public Explore item) function resolveEndpoint() { const parts = location.pathname.split("/").filter(Boolean); // ["share", token?] if (parts.length >= 2) return `/api/shared/${encodeURIComponent(parts[1])}`; const id = new URLSearchParams(location.search).get("idea"); if (id) return `/api/public/ideas/${encodeURIComponent(id)}`; return null; } async function load() { const root = $("#share-root"); const endpoint = resolveEndpoint(); if (!endpoint) { root.innerHTML = '
🤔No idea specified.
'; return; } try { const idea = await api.req("GET", endpoint); const isPublic = idea.visibility === "public"; root.innerHTML = `
👁️ You're viewing a read-only ${ isPublic ? "public" : "shared" } idea${idea.author_name ? ` by ${escapeHtml(idea.author_name)}` : ""}.

${escapeHtml(idea.title)}

${ isPublic ? "🌐 Public" : "🔒 Shared" }
${ idea.description ? `

${escapeHtml(idea.description)}

` : "" }
Created ${fullTime(idea.created_at)}

Notes

`; renderNotesInto($("#notes-container"), idea.notes || []); } catch (e) { root.innerHTML = `
🔒${ e.status === 404 ? "This idea doesn't exist, is private, or the link was disabled." : escapeHtml(e.message) }
`; } } load();