Widget:CommentsRSS

From Jcastle.info
Revision as of 21:38, 25 May 2025 by Eric (talk | contribs)

<script> fetch('/smw139/resources/assets/comments_feed.xml')

 .then(res => res.text())
 .then(str => (new window.DOMParser()).parseFromString(str, "text/xml"))
 .then(data => {
   const items = data.querySelectorAll("item");
   const container = document.getElementById("recent-comments");
   if (items.length === 0) {

container.innerHTML = "

No recent comments.

";

     return;
   }
   items.forEach(item => {
     const titleText = item.querySelector("title").textContent;
     const link = item.querySelector("link").textContent;
     const commentText = item.querySelector("description").textContent;
     const pubDate = new Date(item.querySelector("pubDate").textContent);
     const match = titleText.match(/^(.*?) commented on (.*?)$/);
     const actor = match ? match[1] : 'User';
     const pageTitle = match ? match[2] : 'a page';
     const entry = document.createElement("div");
     entry.style.marginBottom = "1em";
     entry.innerHTML = `
         ${actor} commented on 
         <a href="${link}" target="_blank">${pageTitle}</a>
          (${pubDate.toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric' })})
${commentText}
     `;
     container.appendChild(entry);
   });
 })
 .catch(error => {

document.getElementById("recent-comments").innerHTML = "

Error loading comments.

";

   console.error("RSS Load Error:", error);
 });

</script>