User:Danski454/cat-next.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
This user script seems to have a documentation page at User:Danski454/cat-next. |
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('<div id="cat-next-config" style="background-color:LightGray;border:1px solid black;padding:3px;">Category: <input type="text" id="cat-next-cat" value="' + category + '" size="40"><button id="cat-next-confirm" onclick="cat_next.setCategoryUnencoded();">Confirm</button></div>');
if (mw.config.get("wgNamespaceNumber") === 14) {
$("#cat-next-config").append('<button onclick="cat_next.thisCat();" id="cat-next-this-cat">Use current category</button>');
}
if (category !== "") {
$("#cat-next-config").append('<button onclick="cat_next.clearCat();" id="cat-next-clear">Reset</button>');
}
}
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('<li id="cat-next-next" class="collapsible"><span><a href="" title="Go to the next page in Category:'
+ $("#cat-next-cat").val() + '">Next</a></span></li>');
$("#cat-next-config").append('<button onclick="cat_next.clearCat();" id="cat-next-clear">Reset</button>');
}
$("#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('<li id="cat-next-next" class="collapsible"><span><a href="" title="Go to the next page in Category:'
+ decodeURIComponent(category).replace(/_/g, " ") + '">Next</a></span></li>');
$("#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;
})();
//[[Category:Wikipedia scripts]]