Widget:CommentsRSS: Difference between revisions
From Jcastle.info
No edit summary |
No edit summary |
||
Line 17: | Line 17: | ||
items.forEach((item, index) => { | items.forEach((item, index) => { | ||
if (index >= 5) return; // | if (index >= 5) return; // stop after 5 items | ||
const titleText = item.querySelector("title").textContent; | const titleText = item.querySelector("title").textContent; | ||
const link = item.querySelector("link").textContent; | const link = item.querySelector("link").textContent; | ||
Line 32: | Line 32: | ||
<strong>${actor}</strong> commented on | <strong>${actor}</strong> commented on | ||
<a href="${link}" target="_blank">${pageTitle}</a> | <a href="${link}" target="_blank">${pageTitle}</a> | ||
<small style="color: #555;"> (${pubDate | <small style="color: #555;"> (${pubDate(undefined, { year: 'numeric', month: 'short', day: 'numeric' })})</small> | ||
</div> | </div> | ||
<div style="margin-top: 0.25em;">${commentText}</div> | <div style="margin-top: 0.25em;">${commentText}</div> |
Revision as of 18:30, 31 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, index) => { if (index >= 5) return; // stop after 5 items 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(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>