Jump to content

User:Writ Keeper/Scripts/deletionFinder.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Writ Keeper (talk | contribs) at 16:06, 9 May 2012 (new script). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
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.
$(document).ready(deletionChecker);
encodedTitle = encodeURIComponent(wgTitle);

function deletionChecker()
{
	if(wgCanonicalNamespace == "" || wgCanonicalNamespace == "User"|| wgCanonicalNamespace == "Talk"|| wgCanonicalNamespace == "User talk")
	{
		var encodedTitle = encodeURIComponent(wgTitle);
		var delRequest = $.get("/w/api.php?action=query&list=logevents&format=json&leprop=ids&letype=delete&letitle=" + encodedTitle + "&lelimit=1", null, delCallback, "json");
		var afdRequest = $.get("/w/api.php?action=query&list=allpages&format=json&apprefix=Articles%20for%20deletion%2F" + encodedTitle + "&apnamespace=4&aplimit=1", null, afdCallback, "json");
	}
}
function delCallback(response)
{
	var delResults = $.parseJSON(delRequest.responseText);
	if(delResults.query.logevents[0] != null)
	{	
		var searchNode = document.createElement("a");
		searchNode.href = "http://en.wikipedia.org/w/index.php?title=Special%3ALog&type=delete&page=" + encodedTitle;
		searchNode.target = "_blank";
		searchNode.innerHTML = "<span style='font-size:x-small;'> prev dels </span>";
		document.getElementById("firstHeading").appendChild(searchNode);
	}
}
function afdCallback(response)
{
	var afdResults = $.parseJSON(delRequest.responseText);
	if(delResults.query.logevents[0] != null)
	{
		var searchNode = document.createElement("a");
		searchNode.href = "http://en.wikipedia.org/wiki/Special:PrefixIndex/Wikipedia:Articles_for_deletion/" + encodedTitle;
		searchNode.target = "_blank";
		searchNode.innerHTML = "<span style='font-size:x-small;'> prev AfDs </span>";
		document.getElementById("firstHeading").appendChild(searchNode);
	}
}