User:JPxG/Monthcounter-agnostic.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/Monthcounter-agnostic. |
// A very, very silly script. Counts the amount of occurrences of each month of the year in an editbox.
function doCountag() {
console.log("Starting to count months.");
tbox = document.editform.wpTextbox1.value;
// Get the text from the edit box and store it as "tbox".
tbox = String(tbox);
countAgJan = 0;
console.log("About to start for January.");
if (tbox.match(/January/g) != null) {
countAgJan = (tbox.match(/January/g)).length;
}
countAgFeb = 0;
if (tbox.match(/February/g) != null) {
countAgFeb = (tbox.match(/February/g)).length;
}
countAgMar = 0;
if (tbox.match(/March/g) != null) {
countAgMar = (tbox.match(/March/g)).length;
}
countAgApr = 0;
if (tbox.match(/April/g) != null) {
countAgApr = (tbox.match(/April/g)).length;
}
countAgMay = 0;
if (tbox.match(/May/g) != null) {
countAgMay = (tbox.match(/May/g)).length;
}
countAgJun = 0;
if (tbox.match(/June/g) != null) {
countAgJun = (tbox.match(/June/g)).length;
}
console.log("About to start for July.");
countAgJul = 0;
if (tbox.match(/July/g) != null) {
countAgJul = (tbox.match(/July/g)).length;
}
countAgAug = 0;
if (tbox.match(/August/g) != null) {
countAgAug = (tbox.match(/August/g)).length;
}
countAgSep = 0;
if (tbox.match(/September/g) != null) {
countAgSep = (tbox.match(/September/g)).length;
}
countAgOct = 0;
if (tbox.match(/October/g) != null) {
countAgOct = (tbox.match(/October/g)).length;
}
countAgNov = 0;
if (tbox.match(/November/g) != null) {
countAgNov = (tbox.match(/November/g)).length;
}
countAgDec = 0;
if (tbox.match(/December/g) != null) {
countAgDec = (tbox.match(/December/g)).length;
}
var box = "";
box = box + " Jan: " + String(countAgJan);
box = box + " Feb: " + String(countAgFeb);
box = box + " Mar: " + String(countAgMar);
box = box + " Apr: " + String(countAgApr);
box = box + " May: " + String(countAgMay);
box = box + " Jun: " + String(countAgJun);
box = box + " Jul: " + String(countAgJul);
box = box + " Aug: " + String(countAgAug);
box = box + " Sep: " + String(countAgSep);
box = box + " Oct: " + String(countAgOct);
box = box + " Nov: " + String(countAgNov);
box = box + " Dec: " + String(countAgDec);
box = "";
box = box + String(countAgJan);
box = box + " " + String(countAgFeb);
box = box + " " + String(countAgMar);
box = box + " " + String(countAgApr);
box = box + " " + String(countAgMay);
box = box + " " + String(countAgJun);
box = box + " " + String(countAgJul);
box = box + " " + String(countAgAug);
box = box + " " + String(countAgSep);
box = box + " " + String(countAgOct);
box = box + " " + String(countAgNov);
box = box + " " + String(countAgDec);
console.log("About to set edit summary to the count.");
document.editform.wpSummary.value = box;
} // function to replace the stuff with the other stuff
addOnloadHook(function() {
if (document.editform) {
console.log("Setting portlet link.");
mw.util.addPortletLink("p-cactions", "javascript:doCountag()","Months (agnostic)", "ca-monthsag", "Count month name occurrences agnostic to year", "");
}
}); // onloadhook
// </nowiki>