let hasLoadedComments = false; const container = document.getElementById("comments-container"); container.addEventListener("toggle", (_) => { if (container.open && !hasLoadedComments) { hasLoadedComments = true; fetchComments(); } }); async function fetchComments() { if (typeof commentsPostID !== "undefined") { const res = await fetch( `https://social.shadowfacts.net/api/v1/statuses/${commentsPostID}/context`, ); const json = await res.json(); const comments = json.descendants.map(makeCommentHTML).join(""); const list = document.getElementById("comments-list"); list.innerHTML = comments; list.querySelectorAll(".comment-body a").forEach((a) => { a.target = "_blank"; a.rel = "nofollow"; }); } } function makeCommentHTML(status) { const date = new Date(status.created_at); const month = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", ][date.getMonth()]; return `

${status.account.display_name}

@${status.account.acct}
${status.content}
`; }