Jump to content

User:Writ Keeper/Scripts/SearchNamespaceMono.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.
function NSSearch()
{
	var prefixList = document.createElement("select");
	prefixList.id = "searchNSSelect";
	prefixList.innerHTML = "<option >Article:</option>\n <option>Article talk:</option>\n <option>Wikipedia:</option>\n <option>Wikipedia talk:</option>\n <option>User:</option>\n <option>User talk:</option>\n<option>WikiProject:</option>\n <option>WikiProject talk:</option>\n<option>Category:</option>\n <option>Category talk:</option>\n<option>Template:</option>\n <option>Template talk:</option>\n <option>Book:</option>\n <option>Book talk:</option>\n <option>Help:</option>\n <option>Special:</option>";
	
	var hiddenInput = document.createElement("input");
	hiddenInput.type = "hidden";
	hiddenInput.name = "search";
	hiddenInput.id = "hiddenNSInput";
	
	var searchInput = $("#searchInput");
	searchInput.before(hiddenInput);
	searchInput.before(prefixList);
	searchInput.removeAttr("name");
	
    prefixList.tabIndex = searchInput[0].tabIndex;
	
	$("#searchform").submit(function()
	{
		var prefixValue = $("#searchNSSelect").prop("value");
		switch(prefixValue)
		{
			case "Article:":
				$("#hiddenNSInput").prop("value", $("#searchInput").prop("value"));
				break;
			case "Article talk:":
				$("#hiddenNSInput").prop("value", "Talk:" + $("#searchInput").prop("value"));
				break;
			case "WikiProject:":
				$("#hiddenNSInput").prop("value", "Wikipedia:WikiProject " + $("#searchInput").prop("value"));
				break;
			case "WikiProject talk:":
				$("#hiddenNSInput").prop("value", "Wikipedia talk:WikiProject " + $("#searchInput").prop("value"));
				break;
			default:
				$("#hiddenNSInput").prop("value", prefixValue + $("#searchInput").prop("value"));
				break;
		}
	});
}
$(document).ready(NSSearch);