Jump to content

User:Writ Keeper/Scripts/mainspaceCreationBlocker.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.
mw.hook('wikipage.content').add(function() 
{
	if(mw.config.get("wgCanonicalNamespace") == "" && mw.config.get("wgCurRevisionId") == 0)
	{
		var wgAction = mw.config.get("wgAction");
		var draftUrl = "/w/index.php?title=Draft:" + mw.config.get("wgPageName");
		if((wgAction == "edit" || wgAction == "submit" || wgAction == "editredlink") || $("html.ve-active").length > 0)
		{
			if(confirm('You are about to create a page in main article space! Do you want to edit in Draft space instead?\n\n(Hit "OK" to be taken to a draft for this page)'))
			{
				window.location.assign(draftUrl);
			}
		}
		else
		{
			$("#ca-edit>a").attr("href", draftUrl).text("Go to Draft");
			$("#ca-edit").off("click");
			$("#ca-ve-edit>a").attr("href", draftUrl).text("Go to Draft");
			$("#ca-ve-edit").off("click");
		}
	}
});