Jump to content

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