User:DreamRimmer/adminnewslettertools.js: Difference between revisions

Content deleted Content added
fixes
make it simple, fix pattern
Line 555:
function parseRfCs(wikitext, topicName) {
const rfcs = [];
const rfcPatternrfcEntryPattern = /'''\[\[([^\]|]+)(?:\|([^\]]+))?\]\]'''[\s\S]*?\{\{rfcquote\|text=([^}\s\S]+*?)\}\}[\s\S]*?(\d{2}:\d{2}, \d{1,2} \w+ \d{4} \(UTC\))/g;
let match;
while ((match = rfcPatternrfcEntryPattern.exec(wikitext)) !== null) {
let [pageName, anchor] =, linkText.split('#')displayTitle;
while ((match = rfcPattern.exec(wikitext)) !== null) {
const linkTextlink = match[1];
const rfcquoteTextdisplayTitle = match[2] || link;
letif pageName,(link.includes('#')) anchor;{
[pageName, anchor] = link.split('#');
if (linkText.includes('#')) {
[pageName, anchor] = linkText.split('#');
} else {
pageName = linkTextlink;
anchor = '';
}
const timestampMatch = rfcquoteText.match(/(\d{2}:\d{2}, \d{1,2} \w+ \d{4} \(UTC\))/);
let daysDiff = NaN;
let timestampStr = '';
ifconst (timestampMatch)timestampStr {= match[4];
let timestampStrdaysDiff = timestampMatch[1]null;
if (timestampStr) // Parse timestamp as UTC{
letconst dtPartsparsedDate = new Date(timestampStr.replace(' (UTC)', ' UTC').split(', ');
if (dtParts.length === 2!isNaN(parsedDate)) {
letconst timePartnow = dtParts[0]new Date();
let datePartdaysDiff = dtParts[1]Math.floor((now - parsedDate) / (1000 * 60 * 60 * 24));
// Convert to ISO string
let isoStr = datePart.split(' ');
let day = isoStr[1];
let month = isoStr[2];
let year = isoStr[3];
let time = timePart;
let dateStr = `${year}-${month}-${day}T${time}:00Z`;
let parsedDate = new Date(timestampStr.replace(' (UTC)', ' UTC'));
if (isNaN(parsedDate)) {
// fallback to Date.parse
parsedDate = Date.parse(timestampStr.replace(' (UTC)', ' UTC'));
}
if (!isNaN(parsedDate)) {
let now = new Date();
daysDiff = Math.floor((now - parsedDate) / (1000 * 60 * 60 * 24));
}
} else {
let parsedDate = new Date(timestampStr.replace(' (UTC)', ' UTC'));
if (!isNaN(parsedDate)) {
let now = new Date();
daysDiff = Math.floor((now - parsedDate) / (1000 * 60 * 60 * 24));
}
}
}
const url = anchor ?
`https://en.wikipedia.org/wiki/${encodeURIComponent(pageName)}#${encodeURIComponent(anchor)}` :
`https://en.wikipedia.org/wiki/${encodeURIComponent(pageName)}`;
Line 613 ⟶ 585:
rfcs.push({
topic: topicName,
title: displayTitle || pageName,
url: url,
daysOld: daysDiff,
timestamp: timestampStr || ""
});
}
return rfcs;
}