diff options
| author | sillylaird <sillyfanboy@gmail.com> | 2026-09-03 00:33:59 +0000 |
|---|---|---|
| committer | sillylaird <sillyfanboy@gmail.com> | 2026-09-03 00:33:59 +0000 |
| commit | 898b52edcb47bcb3e9d6106e74ca73e74ea01e70 (patch) | |
| tree | 85c6ee5ad58b860144551184d4cf86b560c62b91 /assets/js/pages/guestbook-comments.js | |
| download | www-898b52edcb47bcb3e9d6106e74ca73e74ea01e70.tar.gz www-898b52edcb47bcb3e9d6106e74ca73e74ea01e70.zip | |
Diffstat (limited to 'assets/js/pages/guestbook-comments.js')
| -rw-r--r-- | assets/js/pages/guestbook-comments.js | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/assets/js/pages/guestbook-comments.js b/assets/js/pages/guestbook-comments.js new file mode 100644 index 0000000..135cc24 --- /dev/null +++ b/assets/js/pages/guestbook-comments.js @@ -0,0 +1,39 @@ +fetch("/api/guestbook-proxy.php") + .then(r => r.text()) + .then(html => { + const doc = new DOMParser().parseFromString(html, "text/html"); + const entries = doc.querySelectorAll(".entry"); + const container = document.getElementById("comments"); + container.innerHTML = ""; + + entries.forEach(e => { + const entry = document.createElement("article"); + entry.className = "guestbook-entry"; + + const nameText = e.querySelector("strong")?.textContent || "Anonymous"; + const timeEl = e.querySelector("time"); + const messageText = e.querySelector("p")?.textContent || ""; + + const strong = document.createElement("strong"); + strong.textContent = nameText; + entry.appendChild(strong); + + if (timeEl) { + const t = document.createElement("time"); + const dt = timeEl.getAttribute("datetime"); + if (dt) t.setAttribute("datetime", dt); + t.textContent = timeEl.textContent || ""; + entry.appendChild(t); + } + + const p = document.createElement("p"); + p.textContent = messageText; + entry.appendChild(p); + + container.appendChild(entry); + }); + }) + .catch(() => { + document.getElementById("comments").innerHTML = + '<p class="guestbook-error">Unable to load comments. Please try refreshing.</p>'; + }); |
