User:DreamRimmer/adminnewslettertools.js: Difference between revisions

Content deleted Content added
Restored revision 1305710703 by DreamRimmer (talk): Restore
fixes
Line 571:
const timestampMatch = rfcquoteText.match(/(\d{2}:\d{2}, \d{1,2} \w+ \d{4} \(UTC\))/);
let daysDiff = })NaN;
htmllet timestampStr += '</tr>';
});
if (timestampMatch) {
const timestampStr = timestampMatch[1];
const// rfcDateParse =timestamp new Date(timestampStr.replace(' (UTC)', 'as UTC'));
constlet nowdtParts = newtimestampStr.replace(' Date(UTC)', '').split(', ');
constif daysDiff(dtParts.length === Math.floor((now - rfcDate2) / (1000 * 60 * 60 * 24));{
let timePart = dtParts[0];
const url = anchor ?let datePart = dtParts[1];
// Convert to ISO });string
`https://en.wikipedia.org/wiki/${encodeURIComponent(pageName)}#${encodeURIComponent(anchor)}` :
`https://enlet isoStr = datePart.wikipedia.org/wiki/${encodeURIComponentsplit(pageName' ')}`;
let day = isoStr[1];
rfcs.push({ let month = isoStr[2];
topic:let topicName,year = isoStr[3];
title:let pageName,time = timePart;
url:let url,dateStr = `${year}-${month}-${day}T${time}:00Z`;
daysOld:let daysDiffparsedDate = new Date(timestampStr.replace(' (UTC)', ' UTC'));
timestamp:if timestampStr(isNaN(parsedDate)) {
}); // fallback to Date.parse
parsedDate = Date.parse(timestampStr.replace(' (UTC)', ' UTC'));
}
if (topicRfcs.length > 0!isNaN(parsedDate)) {
htmllet now += '</ul>'new Date();
daysDiff = Math.floor((now - parsedDate) / (1000 * 60 * 60 * 24));
}
}); else {
let parsedDate = new Date(timestampStr.replace(' (UTC)', ' UTC'));
if topicRfcs.forEach(rfc =>!isNaN(parsedDate)) {
let now = new Date();
daysDiff = Math.floor((now - parsedDate) / (1000 * 60 * 60 * 24));
}
});
}
const displayStyleurl = age === 7anchor ? 'block' : 'none';
`https://en.wikipedia.org/wiki/${encodeURIComponent(pageName)}#${encodeURIComponent(anchor)}` :
`https://en.wikipedia.org/wiki/${encodeURIComponent(pageName)}`;
ageOptionsrfcs.forEachpush(age => {
html += `<tr><td>${ topic}</td>`;: topicName,
htmltitle: += `<td>${count}</td>`;pageName,
html += `<th>${age}d</th>`; url: url,
daysOld: daysDiff,
timestamp: timestampStr
});
}
Line 615 ⟶ 643:
 
let html = `<p><small>Current date: ${currentDate}</small></p>`;
html += `<p>Age filter: <select id="rfc-age-filter" onchange="filterRfCs()">`;
ageOptions.forEach(age => {
const selected = age === 7 ? ' selected' : '';
Line 621 ⟶ 649:
});
html += `</select></p>`;
 
iffunction renderRfCTable(rfcs.length > 0filteredRfcs) {
htmlif (filteredRfcs.length > 0) {
let table += '<h4>All Current RfCs</h4><table class="wikitable sortable"><thead><tr><th>Topic</th><th>Title</th><th>Days Old</th><th>Started</th></tr></thead><tbody>';
rfcs filteredRfcs.sort((a, b) => a.daysOld - b.daysOld).forEach(rfc => {
html table += `<tr><td>${rfc.topic}</td><td><a href="${rfc.url}" target="_blank">${rfc.title}</a></td><td>${rfc.daysOld}</td><td>${rfc.timestamp}</td></tr>`;
});
html table += '</tbody></table>';
} return table;
 
html += '<div id="rfc-summary-table"><h4>RfC Count Summary</h4><table class="wikitable"><thead><tr><th>Topic</th>';
ageOptions.forEach(age => {
html += `<th>${age}d</th>`;
});
html += '</tr></thead><tbody>';
 
topicNames.forEach(topic => {
html += `<tr><td>${topic}</td>`;
ageOptions.forEach(age => {
const count = rfcs.filter(rfc => rfc.topic === topic && rfc.daysOld <= age).length;
html += `<td>${count}</td>`;
});
html += '</tr>';
});
html += '</tbody></table></div>';
 
ageOptions.forEach(age => {
const filteredRfcs = rfcs.filter(rfc => rfc.daysOld <= age);
const displayStyle = age === 7 ? 'block' : 'none';
html += `<div class="rfc-age-group" data-age="${age}" style="display: ${displayStyle};">`;
if (filteredRfcs.length === 0) {
html += `<p>No RfCs found that are ${age} days old or newer.</p>`;
} else {
topicNames.forEach(topicreturn =`<p>No {RfCs found for selected age filter.</p>`;
const topicRfcs = filteredRfcs.filter(rfc => rfc.topic === topic);
if (topicRfcs.length > 0) {
html += `<h4>${topic} (${topicRfcs.length})</h4><ul>`;
topicRfcs.forEach(rfc => {
html += `<li><a href="${rfc.url}" target="_blank">${rfc.title}</a> (${rfc.daysOld} days old)</li>`;
});
html += '</ul>';
}
});
}
html += '</div>';}
});
html += '`</trdiv id="rfc-list-table"></thead><tbodydiv>'`;
 
html += '<p><a href="https://en.wikipedia.org/wiki/Wikipedia:Requests_for_comment/All" target="_blank">All open RfCs</a></p>';
 
html += `<script>
functionwindow._rfcs filterRfCs()= ${JSON.stringify(rfcs)};
const selectedAgewindow._ageOptions = document${JSON.getElementByIdstringify('rfc-age-filter'ageOptions).value};
function const groups = document.querySelectorAllupdateRfCTable('.rfc-age-group'); {
groups.forEach(groupvar rfcs => {window._rfcs;
var group.style.displayage = group.datasetparseInt(document.getElementById('rfc-age == selectedAge ? 'block-filter').value, : 'none'10);
const var filteredRfcs = rfcs.filter(function(rfc) => rfc.daysOld <= age);{
const count = rfcs.filter(rfc =>return !isNaN(rfc.topic === topicdaysOld) && rfc.daysOld <= age).length;
});
document.getElementById('rfc-list-table').innerHTML = (${renderRfCTable.toString()})(filteredRfcs);
}
document.getElementById('rfc-age-filter').addEventListener('change', updateRfCTable);
updateRfCTable();
</script>`;