User:Polygnotus/Scripts/PreviousAfDs.js: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Line 50:
aplimit: 50,
format: 'json'
}).donethen(function(data) {
var exactMatches = data.query.allpages || [];
Line 61:
srlimit: 50,
format: 'json'
}).donethen(function(searchData) {
var searchMatches = searchData.query.search || [];
Line 90:
displayAfDResults(allMatches, articleTitle);
}
}).failcatch(function() {
// If search fails, just show exact matches
displayAfDResults(exactMatches, articleTitle);
});
}).failcatch(function() {
$('#afd-search-btn').text('Search AfD').css('color', '#0645ad');
mw.notify('Error searching for AfD discussions', { type: 'error' });
Line 103:
var api = new mw.Api();
var pageTitles = pages.map(function(page) { return page.title; });
console.log('Fetching dates for:', pageTitles); // Debug log
// Get creation dates for all pages
Line 113 ⟶ 115:
rvprop: 'timestamp',
format: 'json'
}).donethen(function(data) {
console.log('API response:', data); // Debug log
var pagesWithDates = [];
var mostRecentDate = null;
Line 119 ⟶ 123:
// Process each page and add creation date
Object.keysif (data.query && data.query.pages).forEach(function(pageId) {
var pageData = Object.keys(data.query.pages[).forEach(function(pageId];) {
if ( var pageData.revisions &&= pageDatadata.revisionsquery.length > 0) {pages[pageId];
var timestamp = pageData.revisions[0].timestamp;
var date = new Date(timestamp);
var timestampMs = date.getTime();
pagesWithDates.push({// Check if page exists and has revisions
if (pageData && !pageData.missing title:&& pageData.title,revisions && pageData.revisions.length > 0) {
date:var date,timestamp = pageData.revisions[0].timestamp;
timestamp:var timestampMsdate = new Date(timestamp);
} var timestampMs = date.getTime();
console.log('Page:', pageData.title, 'Date:', date.toDateString()); // Debug log
// Track most recent
if (timestampMs > mostRecentTimestamp) {
mostRecentTimestamp = timestampMs;pagesWithDates.push({
mostRecentDate = date; title: pageData.title,
date: date,
timestamp: timestampMs
});
// Track most recent
if (timestampMs > mostRecentTimestamp) {
mostRecentTimestamp = timestampMs;
mostRecentDate = date;
}
} else {
console.log('No revisions found for:', pageData ? pageData.title : 'unknown page');
// Still add the page without date
pagesWithDates.push({
title: pageData ? pageData.title : 'Unknown page',
var timestampMs = date.getTime();: null,
var date = new Date( timestamp);: 0
});
}
});
});
// SortIf bywe datecouldn't (mostget recentany first)dates, fall back to original pages
if (pagesWithDates.sort(function(a,length b=== 0) { return b.timestamp - a.timestamp; });
pagesWithDates = pages;
}
// Sort by date (most recent first, pages without dates last)
pagesWithDates.sort(function(a, b) {
if (!a.timestamp && !b.timestamp) return 0;
if (!a.timestamp) return 1;
if (!b.timestamp) return -1;
return var b.timestamp =- pageData.revisions[0]a.timestamp;
});
// Check if most recent is within 3 months
Line 147 ⟶ 175:
threeMonthsAgo.setMonth(threeMonthsAgo.getMonth() - 3);
var isRecent = mostRecentDate && mostRecentDate > threeMonthsAgo;
console.log('Most recent date:', mostRecentDate ? mostRecentDate.toDateString() : 'none', 'Is recent:', isRecent); // Debug log
displayAfDResults(pagesWithDates, articleTitle, mostRecentDate, isRecent);
}).failcatch(function(error) {
console.log('API error:', error); // Debug log
// If date fetching fails, display without dates
displayAfDResults(pages, articleTitle);