Jump to content

User:Bobblewik/monobook.js/dates.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Bobblewik (talk | contribs) at 20:00, 25 January 2006. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
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.
function formatdates() {
    var txt = document.editform.wpTextbox1;

    // Capitalize units correctly
    txt.value = txt.value.replace(/(\d)\s?(khz)([\s,.])/gi, '$1 kHz$3');
    txt.value = txt.value.replace(/(\d)\s?(mhz)([\s,.])/gi, '$1 MHz$3');
    txt.value = txt.value.replace(/(\d)\s?(ghz)([\s,.])/gi, '$1 GHz$3');
    txt.value = txt.value.replace(/(\d)\s?(Y|Z|E|P|T|G|M|k|K|h|da|d|c|m|µ|μ|µ|n|p|f|a|z|y)?(hz|HZ)([\s,.])/g, '$1 $2Hz$4');
    txt.value = txt.value.replace(/(\d)\s?(Y|Z|E|P|T|G|M|k|K|h|da|d|c|m|µ|μ|µ|n|p|f|a|z|y)?(pa|PA)([\s,.])/g, '$1 $2Pa$4');

    // Add a tag to the summary box
    var txt = document.editform.wpSummary;
    var summary = "[[User:Bobblewik#Regular expressions|Date formatter]]";
	if (txt.value.indexOf(summary) == -1) {
		if (txt.value.match(/[^\*\/\s][^\/\s]?\s*$/)) {
			txt.value += " | ";
		}
		txt.value += summary;
	}

    // Press the diff button to check it
    document.editform.wpDiff.click()
}

addOnloadHook(function () {
    if(document.forms.editform) {
        addLink('p-cactions', 'javascript:formatdates()', '1Jan2001', 'ca-datefixer', 'Fixes some date formatting', '', '');
    }
});