Jump to content

User:MECU/br.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.
//<pre>
function brfixer() {
    var txt = document.editform.wpTextbox1;

    //replace
    txt.value = txt.value.replace(new RegExp('<BR>', 'gi'), '<br />');
    txt.value = txt.value.replace(new RegExp('<BR/>' ,'gi'), '<br />');
    txt.value = txt.value.replace(new RegExp('<BR />', 'gi'), '<br />');
    txt.value = txt.value.replace(new RegExp('</BR>', 'gi'), '<br />');
    txt.value = txt.value.replace(new RegExp('<BR/ >', 'gi'), '<br />');

    // Add a tag to the summary box
    var txt = document.editform.wpSummary;
    var summary = "<BR>s fixed using [[User talk:Mecu/br.js|the <BR> fixer]]";
	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) {
        mw.util.addPortletLink('p-cactions', 'javascript:brfixer()', '<BR>', 'ca-brfixer', 'Fixes <BR>s to <br />', '', '');
    }
});
//</pre>