User:Danski454/cat-next.js

var cat_next = {}; (function {	function setCategory(category){		mw.cookie.set("catNextCat", category);	}	function getCategory{		return mw.cookie.get("catNextCat");	}	function loadInteface{		$("#ca-cat-next").remove;//only run once		var category = getCategory;		if(!category){			category = "";		}		category = decodeURIComponent(category).replace(/_/g, " ");		var body;		if (mw.config.get("skin") === "cologneblue") {			body = $("#mw-content-text");		} else {			body = $("#bodyContent");		}		body.before(' Category: Confirm ');		if (mw.config.get("wgNamespaceNumber") === 14) {			$("#cat-next-config").append('Use current category ');		}		if (category !== "") {			$("#cat-next-config").append('Reset '); }	}	function setCategoryUnencoded{ var category = $("#cat-next-cat").val; category = encodeURIComponent(category.replace(/ /g, "_")); setCategory(category); if (category === "") { $("#cat-next-next, #cat-next-clear").remove; return; }		if ($("#cat-next-next").length === 0) { $("#ca-watch, #ca-unwatch").before(' Next '); $("#cat-next-config").append('Reset '); }		$("#cat-next-next a").attr("href", mw.config.get("wgArticlePath").replace("$1", "Special:RandomInCategory/" + category)); $("#cat-next-next a").attr("title", 'Go to the next page in Category:' + $("#cat-next-cat").val); }	function clearCat{ $("#cat-next-cat").val(""); setCategory(""); $("#cat-next-next, #cat-next-clear").remove; }	function thisCat{ $("#cat-next-cat").val(mw.config.get("wgTitle")); setCategoryUnencoded; }	$(document).ready(function{		if (mw.config.get("skin") === "minerva") {			return; //does not work with minerva		}		var category = getCategory;		if (category) {			$("#ca-watch, #ca-unwatch").before(' Next ');			$("#cat-next-next a").attr("href", mw.config.get("wgArticlePath").replace("$1", "Special:RandomInCategory/" + category));		}		var portletLink = mw.util.addPortletLink('p-cactions', '#', 'Configure cat next', 'ca-cat-next', 'Configure category next button', '');		$(portletLink).click(loadInteface);	}); cat_next.loadInterface = loadInteface; cat_next.setCategoryUnencoded = setCategoryUnencoded; cat_next.clearCat = clearCat; cat_next.thisCat = thisCat; });

//