diff --git a/copyparty/web/ui.css b/copyparty/web/ui.css index 7ebe02e3..572a76b9 100644 --- a/copyparty/web/ui.css +++ b/copyparty/web/ui.css @@ -239,3 +239,6 @@ html.light #tt em { #modali:focus { border-color: #06d; } +#repl_pre { + max-width: 24em; +} \ No newline at end of file diff --git a/copyparty/web/util.js b/copyparty/web/util.js index 1d81647a..48fbdfe7 100644 --- a/copyparty/web/util.js +++ b/copyparty/web/util.js @@ -1023,9 +1023,67 @@ function winpopup(txt) { } +var last_repl = null; +function repl_load() { + var ipre = ebi('repl_pre'), + tb = ebi('modali'); + + function getpres() { + var o, ret = jread("repl_pre", []); + if (!ret.length) + ret = [ + 'var v=Object.keys(localStorage); v.sort(); JSON.stringify(v)', + 'console.hist.slice(-10).join("\\n")' + ]; + + ipre.innerHTML = ''; + for (var a = 0; a < ret.length; a++) { + o = mknod('option'); + o.setAttribute('value', ret[a]); + o.textContent = ret[a]; + ipre.appendChild(o); + } + last_repl = ipre.value = (last_repl || (ret.length ? ret.slice(-1)[0] : '')); + return ret; + } + ebi('repl_pdel').onclick = function (e) { + var val = ipre.value, + pres = getpres(); + + apop(pres, val); + jwrite('repl_pre', pres); + getpres(); + }; + ebi('repl_pnew').onclick = function (e) { + var val = tb.value, + pres = getpres(); + + apop(pres, ipre.value); + pres.push(val); + jwrite('repl_pre', pres); + getpres(); + ipre.value = val; + }; + ipre.oninput = function () { + tb.value = last_repl = ipre.value; + }; + tb.oninput = function () { + last_repl = this.value; + }; + getpres(); + tb.value = last_repl; + +} function repl(e) { ev(e); - modal.prompt('js repl (prefix with , to allow raise)', 'var v=Object.keys(localStorage); v.sort(); JSON.stringify(v)', function (cmd) { + var html = [ + '

js repl (prefix with , to allow raise)

', + '

', + '   ', + '  

' + ]; + + modal.prompt(html.join(''), '', function (cmd) { if (!cmd) return toast.inf(3, 'eval aborted'); @@ -1038,7 +1096,7 @@ function repl(e) { catch (ex) { modal.alert('
exception
' + esc(ex + '')); } - }); + }, undefined, repl_load); } if (ebi('repl')) ebi('repl').onclick = repl;