Skip to content

Instantly share code, notes, and snippets.

@garcon
Created October 24, 2025 07:31
Show Gist options
  • Select an option

  • Save garcon/bc92043dab38f6d6f1fee615cff6f4a8 to your computer and use it in GitHub Desktop.

Select an option

Save garcon/bc92043dab38f6d6f1fee615cff6f4a8 to your computer and use it in GitHub Desktop.
Replace spaces surrounding en-dash on both sides with non-breaking narrow space at left and thin space at right side.
javascript:!function(){function e(e){return e.replace(/\u0020\u2013\u0020/g,"%E2%80%AF%E2%80%93%E2%80%89")}let t=document.activeElement;if(!t){alert("%C5%BD\xe1dn\xfd aktivn\xed prvek!");return}let n=t.tagName.toLowerCase(),l=t.getAttribute("type");if("textarea"!==n&&("input"!==n||l&&"text"!==l)){if(t.isContentEditable){let r=window.getSelection();if(!r.rangeCount){alert("Nejprve ozna%C4%8D text k \xfaprav%C4%9B.");return}let a=r.getRangeAt(0),i=a.toString();if(!i){alert("Nejprve ozna%C4%8D text k \xfaprav%C4%9B.");return}let o=e(i);a.deleteContents(),a.insertNode(document.createTextNode(o)),r.removeAllRanges()}else alert("Aktivn\xed prvek nen\xed textov\xe9 pole ani contenteditable.")}else{let u=t.selectionStart,v=t.selectionEnd;if(u===v){alert("Nejprve ozna%C4%8D text k \xfaprav%C4%9B.");return}let c=t.value.slice(0,u),s=t.value.slice(u,v),$=t.value.slice(v),p=e(s);t.value=c+p+$,t.setSelectionRange(u,u+p.length)}}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment