async function loadComments() { try { const response = await fetch("comments.json"); const allComments = await response.json(); renderComments(allComments); } catch (error) { console.error("Error loading comments:", error); document.getElementById("comments-list").innerHTML = '
  • Error loading comments. Please check if comments.json exists.
  • '; } } /** * Likes get formatted, every 1000 likes is a K, every 1,000,000 is a M * @param {*} count * @returns */ function formatLikes(count) { if (count >= 1000) { return (count / 1000).toFixed(count >= 10000 ? 0 : 1) + "K"; } if (count >= 1000000000) { return (count / 1000000000).toFixed(count >= 10000 ? 0 : 1) + "M"; } return count.toString(); } function createCommentHTML(comment) { const badges = []; if (comment.is_pinned) { badges.push('📌 Pinned'); } // if (comment.is_favorited) { // badges.push('❤️ Favorited'); // } return `
    ${comment.author}
    ${comment.author}

    ${comment.text}

    ${badges.join("")}
    ${comment._time_text}
    `; } //
    // Like // Reply //
    /** * Render the comments into the HTML * @param {} comments */ function renderComments(comments) { const commentsList = document.getElementById("comments-list"); commentsList.innerHTML = ""; comments.forEach((comment) => { const li = document.createElement("li"); li.innerHTML = createCommentHTML(comment); commentsList.appendChild(li); }); } document.addEventListener("DOMContentLoaded", loadComments);