Widget:CommentsRSS

From Jcastle.info
Revision as of 20:50, 25 May 2025 by Eric (talk | contribs) (Created page with "<div id="recent-comments" style="font-size: 0.9em;"></div> <script> fetch('/view/Special:CommentsRSS') .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 = "<p>No recent comments.</p>"; return; } container.innerHTML = "...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

<script> fetch('/view/Special:CommentsRSS')

 .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;
   }

container.innerHTML = "

Recent Comments

";

   items.forEach(item => {
     const title = item.querySelector("title").textContent;
     const link = item.querySelector("link").textContent;
     const desc = item.querySelector("description").textContent;
     const date = new Date(item.querySelector("pubDate").textContent);
     const entry = document.createElement("div");
     entry.style.marginBottom = "1em";
     entry.innerHTML = `
       <a href="${link}" target="_blank" style="font-weight: bold;">${title}</a>
${desc}
${date.toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric' })} `;
     container.appendChild(entry);
   });
 })
 .catch(error => {

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

Error loading comments.

";

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

</script>