User:Omegatron/monobook.js/dashfixer.js

In this article we will explore User:Omegatron/monobook.js/dashfixer.js in depth, analyzing its importance, its impacts and its influence on different aspects of daily life. User:Omegatron/monobook.js/dashfixer.js is a phenomenon that has attracted the attention of experts and scholars in different areas, since its relevance ranges from the personal to the global level. Throughout this article, we will examine the various aspects that make User:Omegatron/monobook.js/dashfixer.js a topic of interest and reflection, as well as the different perspectives from which it can be approached. In addition, we will delve into the implications that User:Omegatron/monobook.js/dashfixer.js has in different contexts and its potential to generate significant changes in society.
function replacedash() {
    var txt = document.editform.wpTextbox1;

    // Convert all html entities into actual dash characters 
    txt.value = txt.value.replace(/(—|—|—)/g, '—');
    txt.value = txt.value.replace(/(&#x2013|–|–)/g, '–');
    txt.value = txt.value.replace(/(−|−|−)/g, '−');

    // Convert -- and em dashes *with or without* spaces --> em dash character surrounded by spaces
    txt.value = txt.value.replace(/(\}\)])\s? ?(--|—|—)\s? ?()/g, '$1 — $3');

    // Convert - or en dashes *with* spaces --> em dash character surrounded by spaces
    txt.value = txt.value.replace(/(\}])( | ) ?(-|–|–)  ?()/g, '$1$2— $4');

    // Convert hyphen next to lone number into a minus sign character
//    txt.value = txt.value.replace(/(\>])(\s)-(\d)/g, '$1$2−$3');
//    Should not touch anything inside math tags...

    // Em dashes for dates?
    txt.value = txt.value.replace(/(\d\d\d)\s?(--?|—|—)\s?(\d\d\d|\d\d)()/g, '$1–$3$4');

    // Add a tag to the summary box
    var txt = document.editform.wpSummary;
    var summary = "]";
	if (txt.value.indexOf(summary) == -1) {
		if (txt.value.match(/?\s*$/)) {
			txt.value += " | ";
		}
		txt.value += summary;
	}

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

$(function () {
    if(document.forms.editform) {
        mw.util.addPortletLink('p-cactions', 'javascript:replacedash()', '—', 'ca-dashfixer', 'Fixes dash formatting', '', '');
    }
});