From 95014236ac51daffcb7ea91f9dfb0c4ec98dccd1 Mon Sep 17 00:00:00 2001
From: ed
Date: Thu, 2 Sep 2021 18:50:47 +0200
Subject: [PATCH] js-repl presets
---
copyparty/web/ui.css | 3 +++
copyparty/web/util.js | 62 +++++++++++++++++++++++++++++++++++++++++--
2 files changed, 63 insertions(+), 2 deletions(-)
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('