User:Gerry Ashton/monobook.js

function monthStringFromMonthNumber(monthNumber) {   switch (monthNumber) {       case "01": return "January" case "02": return "February" case "03": return "March" case "04": return "April" case "05": return "May" case "06": return "June" case "07": return "July" case "08": return "August" case "09": return "September" case "10": return "October" case "11": return "November" case "12": return "December" default: alert(monthNumber) throw "Bad month!" } }

function removeLeadingZero(numberString) {   if (numberString.substr(0, 1) == "0") {       return numberString.substr(1) }   else {       return numberString } }

function unifyIsoDateFormats(formattingAmericanStyle) {   var wpTextbox1 = document.getElementById("wpTextbox1") var pageSource = wpTextbox1.value var isoRegex = /(\[\[)?([0-9][0-9][0-9][0-9])(\]\])?-(\[\[)?([0-1][0-9])-([0-3][0-9])(\]\])?/ var lastIsoRegexFoundAt = 0 var isoRegexResult = isoRegex.exec(pageSource) while (isoRegexResult) {       if (formattingAmericanStyle) {           reformattedDate = monthStringFromMonthNumber(isoRegexResult[5]) + " " + removeLeadingZero(isoRegexResult[6]) + ", " + isoRegexResult[2] }       else {           reformattedDate = removeLeadingZero(isoRegexResult[6]) + " " + monthStringFromMonthNumber(isoRegexResult[5]) + " " + isoRegexResult[2] }       var regexFoundAt = pageSource.search(isoRegex, lastIsoRegexFoundAt) if (regexFoundAt != -1) {           pageSource = pageSource.substr(0, regexFoundAt) + reformattedDate + pageSource.substr(regexFoundAt + isoRegexResult[0].length) isoRegexResult = isoRegex.exec(pageSource.substr(regexFoundAt + reformattedDate.length)) }       else {           isoRegexResult = null }       lastIsoRegexFoundAt = regexFoundAt }   wpTextbox1.value = pageSource document.getElementById("wpDiff").click }

function setUpIsoDateFormatUnifier {   document.getElementById("p-tb").getElementsByTagName("div")[0].getElementsByTagName("ul")[0].innerHTML += "Format ISO dates in American styleFormat ISO dates in international style" }

if (location.href.indexOf("action=edit") != -1 || location.href.indexOf("action=submit") != -1) {   addOnloadHook(setUpIsoDateFormatUnifier) }