Jump to content

User:JJPMaster/Scripts/catredirector.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.
let queryString = new URLSearchParams(window.location.search);
upperName = mw.config.get("wgPageName").toUpperCase();
if(queryString.get("redirect") !== "no") {
	if(mw.config.get("wgArticleId") == 0) {
		if(upperName.startsWith("CAT:")) {
			window.location.href = "/wiki/" + mw.config.get("wgFormattedNamespaces")[14] + ":" + mw.config.get("wgPageName").replace("CAT:", "");
		}
		else if(upperName.startsWith("P:")) {
			window.location.href = "/wiki/" + mw.config.get("wgFormattedNamespaces")[100] + ":" + mw.config.get("wgPageName").replace("P:", "");
		}
		else if(upperName.startsWith("H:")) {
			window.location.href = "/wiki/" + mw.config.get("wgFormattedNamespaces")[12] + ":" + mw.config.get("wgPageName").replace("H:", "");
		}
	}
}