Widget:CommentsRSS: Difference between revisions

From Jcastle.info
No edit summary
No edit summary
Line 13: Line 13:
       return;
       return;
     }
     }
    let html = "";


     items.forEach(item => {
     items.forEach(item => {
Line 24: Line 26:
       const pageTitle = match ? match[2] : 'a page';
       const pageTitle = match ? match[2] : 'a page';


       const entry = document.createElement("div");
       html += `
      entry.style.marginBottom = "1em";
        <div style="margin-bottom: 1em;">
 
          <div>
      entry.innerHTML = `
            <strong>${actor}</strong> commented on  
        <div>
            <a href="${link}" target="_blank">${pageTitle}</a>
          <strong>${actor}</strong> commented on  
            <small style="color: #555;"> (${pubDate.toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric' })})</small>
          <a href="${link}" target="_blank">${pageTitle}</a>
          </div>
          <small style="color: #555;"> (${pubDate.toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric' })})</small>
          <div style="margin-top: 0.25em;">${commentText}</div>
         </div>
         </div>
        <div style="margin-top: 0.25em;">${commentText}</div>
       `;
       `;
    });


       container.appendChild(entry);
    html += `<div style="font-size: 0.85em; margin-top: 1em;">
     });
       💌 <a href="/view/Subscribe_To_Comments" target="_blank">Subscribe to comments by email</a>
    </div>`;
 
     container.innerHTML = html;
   })
   })
   .catch(error => {
   .catch(error => {

Revision as of 09:43, 26 May 2025

<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;
   }
   let html = "";
   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';
     html += `
           ${actor} commented on 
           <a href="${link}" target="_blank">${pageTitle}</a>
            (${pubDate.toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric' })})
${commentText}
     `;
   });

html += `

     💌 <a href="/view/Subscribe_To_Comments" target="_blank">Subscribe to comments by email</a>

`;

   container.innerHTML = html;
 })
 .catch(error => {

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

Error loading comments.

";

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

</script>