diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2020-09-02 15:16:01 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2020-09-02 15:16:01 -0400 |
| commit | 9e0495c1f83cd392348ee9c67737efa0eed5ee8e (patch) | |
| tree | ee4bfa97168db140a925416e6083b1b27a3ac11f /docs/repl.js | |
| parent | dac860740b56a580c0b71a83a5614f5a78e011f5 (diff) | |
Add a character counter to the main online REPL
Diffstat (limited to 'docs/repl.js')
| -rw-r--r-- | docs/repl.js | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/docs/repl.js b/docs/repl.js index 2580d325..f911c8d3 100644 --- a/docs/repl.js +++ b/docs/repl.js @@ -1,10 +1,15 @@ let body = document.body; let doc={}; // html elements with a class body.querySelectorAll('[class]').forEach(e=>doc[e.classList[0]]=e); +let setcount = !doc.count ? (s=>s) : (s=>{ + let l = s.length; + doc.count.textContent = l+" char"+(l!=1?"s":""); +}); let repl = ()=>{ let s=doc.code.value; doc.rslt.classList.remove('err'); doc.rslt.textContent=' '; + setcount(s); setTimeout(() => { try { doc.rslt.textContent=fmt(bqn(s)); @@ -97,7 +102,8 @@ if (location.hash) { }); let b=atob(code); b=new Uint8Array([...b].map(c=>c.charCodeAt(0))); - doc.code.value = (new TextDecoder()).decode(b); + setcount(doc.code.value = (new TextDecoder()).decode(b)); + if (doc.count) doc.count.textContent=(l=>l+" char"+(l!=1?"s":""))(s.length); if (run) repl(); } doc.code.focus(); |
