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.
if (document.getElementById("wpTextbox1") && mw.config.get('wgCanonicalNamespace') != "Template"){
 spaces = /(\s)-(\s)/g;
 document.getElementById("wpTextbox1").innerHTML = document.getElementById("wpTextbox1").innerHTML.replace(spaces, "$1–$2");
}