mirror of
https://github.com/9001/copyparty.git
synced 2025-08-17 17:12:13 -06:00
js-repl presets
This commit is contained in:
parent
6aa7386138
commit
95014236ac
|
@ -239,3 +239,6 @@ html.light #tt em {
|
||||||
#modali:focus {
|
#modali:focus {
|
||||||
border-color: #06d;
|
border-color: #06d;
|
||||||
}
|
}
|
||||||
|
#repl_pre {
|
||||||
|
max-width: 24em;
|
||||||
|
}
|
|
@ -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 = '<option value=""></option>';
|
||||||
|
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) {
|
function repl(e) {
|
||||||
ev(e);
|
ev(e);
|
||||||
modal.prompt('js repl (prefix with <code>,</code> to allow raise)', 'var v=Object.keys(localStorage); v.sort(); JSON.stringify(v)', function (cmd) {
|
var html = [
|
||||||
|
'<p>js repl (prefix with <code>,</code> to allow raise)</p>',
|
||||||
|
'<p><select id="repl_pre"></select>',
|
||||||
|
' <button id="repl_pdel">❌ del</button>',
|
||||||
|
' <button id="repl_pnew">💾 SAVE</button></p>'
|
||||||
|
];
|
||||||
|
|
||||||
|
modal.prompt(html.join(''), '', function (cmd) {
|
||||||
if (!cmd)
|
if (!cmd)
|
||||||
return toast.inf(3, 'eval aborted');
|
return toast.inf(3, 'eval aborted');
|
||||||
|
|
||||||
|
@ -1038,7 +1096,7 @@ function repl(e) {
|
||||||
catch (ex) {
|
catch (ex) {
|
||||||
modal.alert('<h6>exception</h6>' + esc(ex + ''));
|
modal.alert('<h6>exception</h6>' + esc(ex + ''));
|
||||||
}
|
}
|
||||||
});
|
}, undefined, repl_load);
|
||||||
}
|
}
|
||||||
if (ebi('repl'))
|
if (ebi('repl'))
|
||||||
ebi('repl').onclick = repl;
|
ebi('repl').onclick = repl;
|
||||||
|
|
Loading…
Reference in a new issue