User:JJPMaster/Scripts/masscat.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. |
Documentation for this user script can be added at User:JJPMaster/Scripts/masscat. |
var contentContent = document.getElementById("bodyContent");
if (mw.config.get("wgCanonicalNamespace") == "Category" || mw.config.get("wgCanonicalNamespace") == "Category talk") {
mw.util.addPortletLink("p-tb", `/wiki/Special:MassCat?cat=${mw.config.get("wgTitle")}`, "Mass categorizer", "p-masscat", "Mass categorizer");
}
// Adapted from User:Ahecht/Scripts/massmove.js
function massCatGetArticles() {
var articles = document.getElementById("wpMassCatPages").value.split("\n");
var ret = [];
var i, len;
for (i = 0, len = articles.length; i < len; i++) {
var s = articles[i];
s = s.trim();
if (s) {
ret.push(s);
}
}
return ret;
}
function massCatGetCat() {
return document.getElementById("wpMassCatName").value;
}
function massCatPrepare(e) {
e.preventDefault();
var MCarts = confirm("Your articles are these, right?\n" + massCatGetArticles());
var MCcat;
var MCfinal;
if (MCarts) MCcat = confirm(`And you're adding them to ${massCatGetCat()}, right?`);
if (MCcat) MCfinal = confirm("Are you sure you want to do this mass categorization?");
if (MCfinal) doMassCat();
}
function doMassCat() {
var params;
massCatGetArticles().forEach((e) => {
params = {
action: "edit",
title: e,
appendtext: `\n[[Category:${massCatGetCat()}]]`,
summary: "Mass categorization with [[User:JJPMaster/masscat.js]]"
},
api = new mw.Api();
api.postWithToken( 'csrf', params ).done( function ( data ) {
console.log( data );
location.reload();
} );
});
}
$(function() {
if(mw.config.get("wgPageName").toLowerCase() == "special:masscat") {
document.title = "Mass categorizer - " + mw.config.get("wgSiteName");
document.getElementById("firstHeading").innerText = "Mass categorizer";
// Adapted from [[User:Ahecht/Scripts/massmove.js]]
contentContent.innerHTML = `<form id="wpMassCat" name="wpMassCat">
<b>If you abuse this tool, it\'s <i>your</i> fault, not mine.</b>
<div id="wpMassCatFailedContainer"></div>
The name of the category:<br/>
<input type="text" id="wpMassCatName" name="wpMassCatName" value="${new URLSearchParams(window.location.search).get("cat")}"/>
<br /><br />
Pages to add to the category (one on each line, please):<br />
<textarea tabindex="1" accesskey="," name="wpMassCatPages" id="wpMassCatPages" rows="10" cols="80"></textarea>
<input type="submit"/>
</form>`;
document.getElementById("wpMassCat").addEventListener("submit", massCatPrepare);
}
});