User:JPxG/Monthreplacer.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:JPxG/Monthreplacer. |
// 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>