From fc49cb1e671a152fad5a20f9ea7ead2f75217b6c Mon Sep 17 00:00:00 2001 From: ed Date: Mon, 30 Aug 2021 01:09:27 +0200 Subject: [PATCH] add js repl --- copyparty/web/browser.css | 3 +++ copyparty/web/browser.html | 2 ++ copyparty/web/md.css | 11 +++++++++++ copyparty/web/md.html | 1 + copyparty/web/mde.css | 9 +++++++++ copyparty/web/mde.html | 1 + copyparty/web/splash.css | 5 +++++ copyparty/web/splash.html | 5 ++++- copyparty/web/ui.css | 4 ++++ copyparty/web/util.js | 21 +++++++++++++++++++++ 10 files changed, 61 insertions(+), 1 deletion(-) diff --git a/copyparty/web/browser.css b/copyparty/web/browser.css index 2ede6e63..2f4f2033 100644 --- a/copyparty/web/browser.css +++ b/copyparty/web/browser.css @@ -204,6 +204,9 @@ a, #files tbody div a:last-child { color: #f4c; border-bottom: 1px solid rgba(255,68,204,0.6); } +#repl { + padding: .33em; +} #files tbody a.play { color: #e70; padding: .2em; diff --git a/copyparty/web/browser.html b/copyparty/web/browser.html index cefd0ec1..66b649b4 100644 --- a/copyparty/web/browser.html +++ b/copyparty/web/browser.html @@ -113,6 +113,8 @@
{{ logues[1] }}

control-panel

+ + π diff --git a/copyparty/web/md.css b/copyparty/web/md.css index 501264cc..d7b48e1b 100644 --- a/copyparty/web/md.css +++ b/copyparty/web/md.css @@ -8,6 +8,14 @@ html, body { font-family: sans-serif; line-height: 1.5em; } +#repl { + position: absolute; + top: 0; + right: .2em; + border: none; + color: inherit; + background: none; +} #mtw { display: none; } @@ -506,6 +514,9 @@ blink { border-bottom: .07em solid #4ac; padding: 0 .3em; } + #repl { + display: none; + } #toc>ul { border-left: .1em solid #84c4dd; } diff --git a/copyparty/web/md.html b/copyparty/web/md.html index d1e72f32..fbb548b2 100644 --- a/copyparty/web/md.html +++ b/copyparty/web/md.html @@ -45,6 +45,7 @@
+ π {%- if edit %}
diff --git a/copyparty/web/mde.css b/copyparty/web/mde.css index d146e8eb..b0508c2f 100644 --- a/copyparty/web/mde.css +++ b/copyparty/web/mde.css @@ -22,6 +22,15 @@ html, body { bottom: auto; top: 1.4em; } +#repl { + position: absolute; + top: 0; + right: .5em; + border: none; + color: inherit; + background: none; + text-decoration: none; +} #mn { font-weight: normal; margin: 1.3em 0 .7em 1em; diff --git a/copyparty/web/mde.html b/copyparty/web/mde.html index 5170865f..20c9fc72 100644 --- a/copyparty/web/mde.html +++ b/copyparty/web/mde.html @@ -21,6 +21,7 @@
+ π + - \ No newline at end of file + diff --git a/copyparty/web/ui.css b/copyparty/web/ui.css index 447c3ac5..4c7aca08 100644 --- a/copyparty/web/ui.css +++ b/copyparty/web/ui.css @@ -107,6 +107,7 @@ html { padding: 1.5em 2em; border-width: .5em 0; } +#modalc code, #tt code { background: #3c3c3c; padding: .1em .3em; @@ -125,6 +126,7 @@ html.light #tt, html.light #toast { box-shadow: 0 .3em 1em rgba(0,0,0,0.4); } +#modalc code, html.light #tt code { background: #060; color: #fff; @@ -207,6 +209,8 @@ html.light #tt em { } #modali { display: block; + background: #fff; + color: #000; width: calc(100% - 1.25em); margin: 1em -.1em 0 -.1em; padding: .5em; diff --git a/copyparty/web/util.js b/copyparty/web/util.js index ecdfdaeb..4ded878f 100644 --- a/copyparty/web/util.js +++ b/copyparty/web/util.js @@ -892,3 +892,24 @@ function winpopup(txt) { body: 'msg=' + uricom_enc(Date.now() + ', ' + txt) }); } + + +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) { + if (!cmd) + return toast.inf(3, 'eval aborted'); + + if (cmd.startsWith(',')) + return modal.alert(esc(eval(cmd.slice(1)) + '')) + + try { + modal.alert(esc(eval(cmd) + '')); + } + catch (ex) { + modal.alert('
exception
' + esc(ex + '')); + } + }); +} +if (ebi('repl')) + ebi('repl').onclick = repl;