User:JPxG/Monthcounter.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.
// A very, very silly script. Counts the amount of occurrences of each month of the year in an editbox.

function doCount() {
    tbox = document.editform.wpTextbox1.value;
    // Get the text from the edit box and store it as "tbox".
    tbox = String(tbox);
    asdf = (tbox.match(/hi/g)).length;
    countJan = 0;
    if (tbox.match(/January 2022/g) != null) {
        countJan = (tbox.match(/January 2022/g)).length;
        }
    countFeb = 0;
    if (tbox.match(/February 2022/g) != null) {
        countFeb = (tbox.match(/February 2022/g)).length;
        }
    countMar = 0;
    if (tbox.match(/March 2022/g) != null) {
        countMar = (tbox.match(/March 2022/g)).length;
        }
    countApr = 0;
    if (tbox.match(/April 2022/g) != null) {
        countApr = (tbox.match(/April 2022/g)).length;
        }
    countMay = 0;
    if (tbox.match(/May 2022/g) != null) {
        countMay = (tbox.match(/May 2022/g)).length;
        }
    countJun = 0;
    if (tbox.match(/June 2022/g) != null) {
        countJun = (tbox.match(/June 2022/g)).length;
        }
    countJul = 0;
    if (tbox.match(/July 2022/g) != null) {
        countJul = (tbox.match(/July 2022/g)).length;
        }
    countAug = 0;
    if (tbox.match(/August 2022/g) != null) {
        countAug = (tbox.match(/August 2022/g)).length;
        }
    countSep = 0;
    if (tbox.match(/September 2022/g) != null) {
        countSep = (tbox.match(/September 2022/g)).length;
        }
    countOct = 0;
    if (tbox.match(/October 2022/g) != null) {
        countOct = (tbox.match(/October 2022/g)).length;
        }
    countNov = 0;
    if (tbox.match(/November 2022/g) != null) {
        countNov = (tbox.match(/November 2022/g)).length;
        }
    countDec = 0;
    if (tbox.match(/December 2022/g) != null) {
        countDec = (tbox.match(/December 2022/g)).length;
        }
    var box = "";
    box = box + " Jan: " + String(countJan);
    box = box + " Feb: " + String(countFeb);
    box = box + " Mar: " + String(countMar);
    box = box + " Apr: " + String(countApr);
    box = box + " May: " + String(countMay);
    box = box + " Jun: " + String(countJun);
    box = box + " Jul: " + String(countJul);
    box = box + " Aug: " + String(countAug);
    box = box + " Sep: " + String(countSep);
    box = box + " Oct: " + String(countOct);
    box = box + " Nov: " + String(countNov);
    box = box + " Dec: " + String(countDec);

    box = "";
    box = box + String(countJan);
    box = box + "   " + String(countFeb);
    box = box + "   " + String(countMar);
    box = box + "   " + String(countApr);
    box = box + "   " + String(countMay);
    box = box + "   " + String(countJun);
    box = box + "   " + String(countJul);
    box = box + "   " + String(countAug);
    box = box + "   " + String(countSep);
    box = box + "   " + String(countOct);
    box = box + "   " + String(countNov);
    box = box + "   " + String(countDec);

    document.editform.wpSummary.value = box;
} // function to replace the stuff with the other stuff

addOnloadHook(function() {
    if (document.editform) {
        mw.util.addPortletLink("p-cactions", "javascript:doCount()", "Count months", "ca-months", "Count month name occurrences", "");
    }
}); // onloadhook
// </nowiki>