This is an old revision of this page, as edited by Polygnotus(talk | contribs) at 20:12, 8 June 2025(←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',...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.Revision as of 20:12, 8 June 2025 by Polygnotus(talk | contribs)(←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',...')
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// Add AfD search functionality to Wikipedia$(document).ready(function(){// Only run on article pages (namespace 0)if(mw.config.get('wgNamespaceNumber')===0){addAfDSearchButton();}});functionaddAfDSearchButton(){// Create the search buttonvar$button=$('<a>').attr('href','#').attr('id','afd-search-btn').text('Search AfD').css({'margin-left':'10px','font-size':'0.9em','color':'#0645ad','text-decoration':'none'}).on('click',function(e){e.preventDefault();searchAfDDiscussions();});// Add button to the page - you can modify this selector based on where you want it// This adds it after the page title$('#firstHeading').after($('<div>').append($button));// Alternative locations (uncomment one if preferred):// $('.mw-indicators').append($button); // Near other page indicators// $('#p-cactions ul').append($('<li>').append($button)); // In the page actions menu}functionsearchAfDDiscussions(){vararticleTitle=mw.config.get('wgPageName').replace(/_/g,' ');varsearchPrefix='Wikipedia:Articles for deletion/'+articleTitle;// Show loading indicator$('#afd-search-btn').text('Searching...').css('color','#888');// Search for pages with the AfD prefixvarapi=newmw.Api();api.get({action:'query',list:'allpages',apprefix:searchPrefix,apnamespace:4,// Wikipedia namespaceaplimit:50,format:'json'}).done(function(data){displayAfDResults(data.query.allpages,articleTitle);}).fail(function(){$('#afd-search-btn').text('Search AfD').css('color','#0645ad');mw.notify('Error searching for AfD discussions',{type:'error'});});}functiondisplayAfDResults(pages,articleTitle){// Reset button$('#afd-search-btn').text('Search AfD').css('color','#0645ad');// Remove any existing results$('#afd-results').remove();var$resultsDiv=$('<div>').attr('id','afd-results').css({'margin':'10px 0','padding':'10px','border':'1px solid #ccc','background-color':'#f9f9f9','border-radius':'3px'});if(pages.length===0){$resultsDiv.html('<strong>No previous AfD discussions found for "'+articleTitle+'"</strong>');}else{var$title=$('<strong>').text('Previous AfD discussions for "'+articleTitle+'":');var$list=$('<ul>').css('margin','10px 0');pages.forEach(function(page){var$link=$('<a>').attr('href',mw.util.getUrl(page.title)).text(page.title);$list.append($('<li>').append($link));});$resultsDiv.append($title).append($list);}// Add close buttonvar$closeBtn=$('<span>').text(' [close]').css({'cursor':'pointer','color':'#0645ad','font-size':'0.9em'}).on('click',function(){$('#afd-results').remove();});$resultsDiv.append($closeBtn);// Insert results after the button$('#afd-search-btn').parent().after($resultsDiv);}// Optional: Add keyboard shortcut (Alt+A)$(document).on('keydown',function(e){if(e.altKey&&e.which===65&&mw.config.get('wgNamespaceNumber')===0){// Alt+Ae.preventDefault();searchAfDDiscussions();}});