Jump to content

User:JPxG/Monthreplacer.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.
// JPxG, 2021 December 5
// A very, very silly script. Replaces "January" with "01", etc.

function doReplaceMonths() {
	tbox = document.editform.wpTextbox1.value;
	// Get the text from the edit box and store it as "tbox".
	tbox = String(tbox);
	tbox = tbox.replaceAll("January", "01");
	tbox = tbox.replaceAll("February", "02");
	tbox = tbox.replaceAll("March", "03");
	tbox = tbox.replaceAll("April", "04");
	tbox = tbox.replaceAll("May", "05");
	tbox = tbox.replaceAll("June", "06");
	tbox = tbox.replaceAll("July", "07");
	tbox = tbox.replaceAll("August", "08");
	tbox = tbox.replaceAll("September", "09");
	tbox = tbox.replaceAll("October", "10");
	tbox = tbox.replaceAll("November", "11");
	tbox = tbox.replaceAll("December", "12");
	document.editform.wpTextbox1.value = tbox;
} // function to replace the stuff with the other stuff

function undoReplaceMonths() {
	tbox = document.editform.wpTextbox1.value;
	// Get the text from the edit box and store it as "tbox".
	tbox = String(tbox);
	tbox = tbox.replaceAll("-01", " January");
	tbox = tbox.replaceAll("-02", " February");
	tbox = tbox.replaceAll("-03", " March");
	tbox = tbox.replaceAll("-04", " April");
	tbox = tbox.replaceAll("-05", " May");
	tbox = tbox.replaceAll("-06", " June");
	tbox = tbox.replaceAll("-07", " July");
	tbox = tbox.replaceAll("-08", " August");
	tbox = tbox.replaceAll("-09", " September");
	tbox = tbox.replaceAll("-10", " October");
	tbox = tbox.replaceAll("-11", " November");
	tbox = tbox.replaceAll("-12", " December");
	document.editform.wpTextbox1.value = tbox;
} // function to replace the stuff with the other stuff

addOnloadHook(function() {
	if (document.editform) {
		mw.util.addPortletLink("p-cactions", "javascript:doReplaceMonths()", "Numberify months", "ca-monthno", "January -> 01", "");
		mw.util.addPortletLink("p-cactions", "javascript:undoReplaceMonths()", "Denumberify months", "ca-nomonthno", "2021-01 -> 2021 January", "");
	}
}); // onloadhook
// </nowiki>