User:JJPMaster/Scripts/masscat.js

This is an old revision of this page, as edited by JJPMaster (talk | contribs) at 18:30, 16 November 2024 (move to onload section). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
var contentContent = document.getElementById("bodyContent");

// 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 massCatPrepare(e) {
	alert("Your articles are these, right?\n" + massCatGetArticles());
	alert(`And you're adding them to ${category}, right?`);
	e.preventDefault();
}

$(function() {
	var category = document.getElementById("wpMassCatName").value;
	if(mw.config.get("wgPageName").toLowerCase() == "special:masscat") {
		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"/>
			<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);	
	}
});