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

Content deleted Content added
Created page with '// Add AfD search functionality to Wikipedia $(document).ready(function() { // Only run on article pages (namespace 0) if (mw.config.get('wgNamespaceNumber') === 0) { addAfDSearchButton(); } }); function addAfDSearchButton() { // Create the search button var $button = $('<a>') .attr('href', '#') .attr('id', 'afd-search-btn') .text('Search AfD') .css({ 'margin-left': '10px',...'
 
No edit summary
Line 40:
$('#afd-search-btn').text('Searching...').css('color', '#888');
// Search for pages with the AfD prefix
var api = new mw.Api();
// First try exact prefix match
api.get({
action: 'query',
Line 51:
format: 'json'
}).done(function(data) {
displayAfDResults(var exactMatches = data.query.allpages, articleTitle)|| [];
// Then do a broader search using the search API
api.get({
action: 'query',
list: 'search',
srsearch: 'prefix:"Wikipedia:Articles for deletion/' + articleTitle + '"',
srnamespace: 4,
srlimit: 50,
format: 'json'
}).done(function(searchData) {
var searchMatches = searchData.query.search || [];
// Combine and deduplicate results
var allMatches = [];
var seenTitles = new Set();
// Add exact matches first
exactMatches.forEach(function(page) {
if (!seenTitles.has(page.title)) {
allMatches.push({title: page.title});
seenTitles.add(page.title);
}
});
// Add search matches
searchMatches.forEach(function(page) {
if (!seenTitles.has(page.title)) {
allMatches.push({title: page.title});
seenTitles.add(page.title);
}
});
displayAfDResults(allMatches, articleTitle);
}).fail(function() {
// If search fails, just show exact matches
displayAfDResults(exactMatches, articleTitle);
});
}).fail(function() {
$('#afd-search-btn').text('Search AfD').css('color', '#0645ad');