Jump to content

User:Writ Keeper/Scripts/renameWarner.js

From Wikipedia, the free encyclopedia
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.
if(typeof hasCheckedForUsernameChangeRequests == "undefined")
{
	hasCheckedForUsernameChangeRequests = false;
}
if(typeof hasRequestedNameChange == "undefined")
{
	hasRequestedNameChange = "";
}

$(document).ready(function()
{
	if(mw.config.get("wgCanonicalSpecialPageName") == "Block")
	{
		$("#mw-input-wpReason").change(function()
		{
			var blockReason = $("#mw-input-wpReason").val();
			if(blockReason == "{{usernameblock}}" || blockReason == "{{causeblock}}" || blockReason == "{{softerblock}}")
			{
				if(!hasCheckedForUsernameChangeRequests)
				{
					var data = {action:"query",format:"json",prop:"revisions",rvprop:"ids",rvlimit:"1",rvuser:$("#mw-bi-target").val(),pageids:"7535778"};
					$.post("/w/api.php",data,function(response)
					{
						if(typeof response.query.pages["7535778"].revisions != "undefined")
						{
							hasRequestedNameChange = hasRequestedNameChange + "S";
							$("#mw-input-wpReason").after('<div id="rename-warning-simple"><span style="color:red;">NOTE: this user has made edits to WP:CHU/S; they may have already requested a rename.</span> <a target="_blank" href="//en.wikipedia.org/w/index.php?diff='+response.query.pages["7535778"].revisions[0].revid +'&direction=prev">Here\'s their most recent edit.</a></div>');
						}
					});
					data.pageids = "8868700";
					$.post("/w/api.php",data,function(response)
					{
						if(typeof response.query.pages["8868700"].revisions != "undefined")
						{
							hasRequestedNameChange = hasRequestedNameChange + "U";
							var usurpWarningAnchor;
							if($("#rename-warning-simple").length > 0)
							{
								usurpWarningAnchor = $("#rename-warning-simple");
							}
							else
							{
								usurpWarningAnchor = $("#mw-input-wpReason");
							}
							usurpWarningAnchor.after('<div id="rename-warning-usurp"><span style="color:red;">NOTE: this user has made edits to WP:CHU/U; they may have already requested a rename.</span> <a target="_blank" href="//en.wikipedia.org/w/index.php?diff='+response.query.pages["8868700"].revisions[0].revid +'&direction=prev">Here\'s their most recent edit.</a></div>');
						}
					});
					hasCheckedForUsernameChangeRequests = true;
				}
				else
				{
					$("#rename-warning-simple").show();
					$("#rename-warning-usurp").show();
				}
			}
			else
			{
				$("#rename-warning-simple").hide();
				$("#rename-warning-usurp").hide();
			}
		});
	}
});