blob: 135cc2452fb1ebf003839f3c4b506659540ab280 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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>';
});
|