From 2b01c789b627f554ca5a5e6149326ec702c579f9 Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Wed, 10 Jun 2026 19:01:58 -0400 Subject: [PATCH] Add URL deep-linking for searches (?e=) - Write the searched identifier to the URL on submit so results are bookmarkable and shareable - Auto-run the search on load when ?e= (or ?id=/?q=, or a bare #hash) is present; normalize a bare hash into ?e= - Re-run/clear the search on back/forward via popstate - Refactor fetch logic into a shared runSearch(input) Co-Authored-By: Claude Opus 4.8 --- src/index.html | 48 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/src/index.html b/src/index.html index d9f7482..1f7ebaa 100644 --- a/src/index.html +++ b/src/index.html @@ -1037,11 +1037,11 @@ } } - // ---- Submit ------------------------------------------------------------ - $("form").onsubmit = async (e) => { - e.preventDefault(); - const input = $("eventId").value.trim(); + // ---- Search ------------------------------------------------------------ + async function runSearch(input) { + input = (input || "").trim(); if (!input) return showError("Please enter an event ID or identifier."); + $("eventId").value = input; let query; try { @@ -1075,8 +1075,41 @@ pool.close(relays); } catch (_) {} } + } + + // ---- URL deep-linking (?e=, or a bare #) ------- + function inputFromUrl() { + const params = new URLSearchParams(location.search); + let v = params.get("e") || params.get("id") || params.get("q"); + if (!v && location.hash.length > 1) v = decodeURIComponent(location.hash.slice(1)); + return v ? v.trim() : ""; + } + function writeUrl(input, replace) { + const url = new URL(location.href); + url.searchParams.set("e", input); + url.hash = ""; + history[replace ? "replaceState" : "pushState"]({ e: input }, "", url.pathname + url.search); + } + + $("form").onsubmit = (e) => { + e.preventDefault(); + const input = $("eventId").value.trim(); + if (!input) return showError("Please enter an event ID or identifier."); + writeUrl(input, false); + runSearch(input); }; + // Back/forward navigation re-runs (or clears) the search. + window.addEventListener("popstate", () => { + const v = inputFromUrl(); + if (v) { + runSearch(v); + } else { + $("eventId").value = ""; + $("result").innerHTML = ""; + } + }); + // ---- Init -------------------------------------------------------------- setRelayTextarea(loadRelays()); $("relays").addEventListener("input", updateRelayCount); @@ -1084,6 +1117,13 @@ setRelayTextarea(DEFAULT_RELAYS); saveRelays(DEFAULT_RELAYS); }); + + // Auto-run a search if the page was opened with an identifier in the URL. + const initial = inputFromUrl(); + if (initial) { + writeUrl(initial, true); // normalize a bare #hash into ?e= + runSearch(initial); + }