Jump to content

User:Qwerfjkl/scripts/convertAbbreviations.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.
function fixAbbreviations() {
    var text = document.editform.wpTextbox1.value;
	text = text.replace(/(\|\s*)AK(?!\w)/g, '$1Alaska');
	text = text.replace(/(\|\s*)AL(?!\w)/g, '$1Alabama');
	text = text.replace(/(\|\s*)AR(?!\w)/g, '$1Arkansas');
	text = text.replace(/(\|\s*)AZ(?!\w)/g, '$1Arizona');
	text = text.replace(/(\|\s*)CA(?!\w)/g, '$1California');
	text = text.replace(/(\|\s*)CO(?!\w)/g, '$1Colorado');
	text = text.replace(/(\|\s*)CT(?!\w)/g, '$1Connecticut');
	text = text.replace(/(\|\s*)DE(?!\w)/g, '$1Delaware');
	text = text.replace(/(\|\s*)FL(?!\w)/g, '$1Florida');
	text = text.replace(/(\|\s*)GA(?!\w)/g, '$1Georgia');
	text = text.replace(/(\|\s*)HI(?!\w)/g, '$1Hawaii');
	text = text.replace(/(\|\s*)IA(?!\w)/g, '$1Iowa');
	text = text.replace(/(\|\s*)ID(?!\w)/g, '$1Idaho');
	text = text.replace(/(\|\s*)IL(?!\w)/g, '$1Illinois');
	text = text.replace(/(\|\s*)IN(?!\w)/g, '$1Indiana');
	text = text.replace(/(\|\s*)KS(?!\w)/g, '$1Kansas');
	text = text.replace(/(\|\s*)KY(?!\w)/g, '$1Kentucky');
	text = text.replace(/(\|\s*)LA(?!\w)/g, '$1Louisiana');
	text = text.replace(/(\|\s*)MA(?!\w)/g, '$1Massachusetts');
	text = text.replace(/(\|\s*)MD(?!\w)/g, '$1Maryland');
	text = text.replace(/(\|\s*)ME(?!\w)/g, '$1Maine');
	text = text.replace(/(\|\s*)MI(?!\w)/g, '$1Michigan');
	text = text.replace(/(\|\s*)MN(?!\w)/g, '$1Minnesota');
	text = text.replace(/(\|\s*)MO(?!\w)/g, '$1Missouri');
	text = text.replace(/(\|\s*)MS(?!\w)/g, '$1Mississippi');
	text = text.replace(/(\|\s*)MT(?!\w)/g, '$1Montana');
	text = text.replace(/(\|\s*)NC(?!\w)/g, '$1North Carolina');
	text = text.replace(/(\|\s*)ND(?!\w)/g, '$1North Dakota');
	text = text.replace(/(\|\s*)NE(?!\w)/g, '$1Nebraska');
	text = text.replace(/(\|\s*)NH(?!\w)/g, '$1New Hampshire');
	text = text.replace(/(\|\s*)NJ(?!\w)/g, '$1New Jersey');
	text = text.replace(/(\|\s*)NM(?!\w)/g, '$1New Mexico');
	text = text.replace(/(\|\s*)NV(?!\w)/g, '$1Nevada');
	text = text.replace(/(\|\s*)NY(?!\w)/g, '$1New York');
	text = text.replace(/(\|\s*)OH(?!\w)/g, '$1Ohio');
	text = text.replace(/(\|\s*)OK(?!\w)/g, '$1Oklahoma');
	text = text.replace(/(\|\s*)OR(?!\w)/g, '$1Oregon');
	text = text.replace(/(\|\s*)PA(?!\w)/g, '$1Pennsylvania');
	text = text.replace(/(\|\s*)RI(?!\w)/g, '$1Rhode Island');
	text = text.replace(/(\|\s*)SC(?!\w)/g, '$1South Carolina');
	text = text.replace(/(\|\s*)SD(?!\w)/g, '$1South Dakota');
	text = text.replace(/(\|\s*)TN(?!\w)/g, '$1Tennessee');
	text = text.replace(/(\|\s*)TX(?!\w)/g, '$1Texas');
	text = text.replace(/(\|\s*)UT(?!\w)/g, '$1Utah');
	text = text.replace(/(\|\s*)VA(?!\w)/g, '$1Virginia');
	text = text.replace(/(\|\s*)VT(?!\w)/g, '$1Vermont');
	text = text.replace(/(\|\s*)WA(?!\w)/g, '$1Washington');
	text = text.replace(/(\|\s*)WI(?!\w)/g, '$1Wisconsin');
	text = text.replace(/(\|\s*)WV(?!\w)/g, '$1West Virginia');
	text = text.replace(/(\|\s*)WY(?!\w)/g, '$1Wyoming');
	document.editform.wpTextbox1.value = text;
}

mw.loader.using( 'mediawiki.util', function () {

    // Wait for the page to be parsed
    $( document ).ready( function () { 

if (document.editform) {
        var link =     mw.util.addPortletLink("p-tb", "#", "Convert abbreviations", "tb-convertabbreviations", "Convert column of US state abbreviations to full names", "");
        $( link ).click( function ( event ) {
            event.preventDefault();
            fixAbbreviations();

        } );
        }
    } );
} );