feat: refactor static frontend
Kim committed
Nov 15, 2025 at 11:16 UTC
f6a6181a6d55a2b38a3e7ee2e58996639d97cbf4
2 files changed
+31
-25
cmd/relay-server/static/admin.js
new
+30
@@ -0,0 +1,30 @@
1
+function filterCards(q) {
2
+ q = (q || "").toLowerCase().trim();
3
+ const cards = document.querySelectorAll(".grid .card");
4
+ cards.forEach((card) => {
5
+ const name = (card.getAttribute("data-name") || "").toLowerCase();
6
+ const show = !q || name.includes(q);
7
+ card.style.display = show ? "" : "none";
8
+ });
9
+}
10
+
11
+function setupSearch() {
12
+ const input = document.getElementById("search");
13
+ if (!input) return;
14
+ input.addEventListener("input", (event) => {
15
+ filterCards(event.target.value);
16
+ });
17
+}
18
+
19
+(function () {
20
+ setupSearch();
21
+ const opts = { dateStyle: "medium", timeStyle: "short" };
22
+ document.querySelectorAll("time.lastseen").forEach((el) => {
23
+ const iso = el.getAttribute("datetime");
24
+ if (!iso) return;
25
+ const d = new Date(iso);
26
+ if (isNaN(d.getTime())) return;
27
+ el.textContent = new Intl.DateTimeFormat(undefined, opts).format(d);
28
+ el.title = d.toString();
29
+ });
30
+})();
cmd/relay-server/static/index.html
+1
-25
@@ -30,7 +30,6 @@
30
type="text"
31
placeholder="Search by name"
32
aria-label="Search by name"
33
- oninput="filterCards(this.value)"
33
/>
34
</div>
35
<a
@@ -124,29 +123,6 @@
123
</div>
124
</main>
125
</div>
127
- <script>
128
- function filterCards(q) {
129
- q = (q || "").toLowerCase().trim();
130
- const cards = document.querySelectorAll(".grid .card");
131
- cards.forEach((card) => {
132
- const name = (card.getAttribute("data-name") || "").toLowerCase();
133
- const show = !q || name.includes(q);
134
- card.style.display = show ? "" : "none";
135
- });
136
- }
137
- (function () {
138
- try {
139
- const opts = { dateStyle: "medium", timeStyle: "short" };
140
- document.querySelectorAll("time.lastseen").forEach((el) => {
141
- const iso = el.getAttribute("datetime");
142
- if (!iso) return;
143
- const d = new Date(iso);
144
- if (isNaN(d.getTime())) return;
145
- el.textContent = new Intl.DateTimeFormat(undefined, opts).format(d);
146
- el.title = d.toString();
147
- });
148
- } catch (_) {}
149
- })();
150
- </script>
126
+ <script src="/static/admin.js"></script>
127
</body>
128
</html>