summaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
Diffstat (limited to 'web')
-rw-r--r--web/index.html16
1 files changed, 16 insertions, 0 deletions
diff --git a/web/index.html b/web/index.html
index 677fe14..404b367 100644
--- a/web/index.html
+++ b/web/index.html
@@ -46,6 +46,9 @@
/* sentence alternates black-on-white and white-on-black; Backspace = red retake */
body.invert { background: #000; color: #fff; }
body.cut { background: #d10d0d; color: #fff; }
+ /* Enter: the sentence was kept and written to the session log */
+ body.keep { color: #0a7d3a; }
+ body.invert.keep { color: #4ade80; }
@keyframes pop {
from { opacity: .5; transform: scale(.955); }
to { opacity: 1; transform: scale(1); }
@@ -110,6 +113,11 @@
if (reserve) en.textContent = '';
}
+ function keep() {
+ body.classList.add('keep'); // instant feedback, server confirms it
+ fetch('/keep', { method: 'POST', keepalive: true }).catch(function () {});
+ }
+
function cut() {
body.classList.add('cut'); // instant feedback, server confirms it
curZh = ''; curEn = '';
@@ -154,6 +162,11 @@
addEventListener('resize', function () { measurePad(); fit(); });
addEventListener('keydown', function (e) {
+ if (e.key === 'Enter') {
+ e.preventDefault();
+ keep();
+ return;
+ }
if (e.key === 'Backspace' || e.key === 'Delete' || e.key === 'c') {
// "that was wrong, say it again": red screen, then straight back to work
e.preventDefault();
@@ -169,6 +182,7 @@
measurePad();
if (q.has('invert')) body.classList.add('invert');
+ if (q.has('keep')) body.classList.add('keep');
if (q.has('cut')) { body.classList.add('cut'); return; }
if (q.has('text')) { // design preview: index.html?en=1&text=你好&t=hello
@@ -182,7 +196,9 @@
const s = JSON.parse(e.data);
body.classList.toggle('invert', !!s.invert);
body.classList.toggle('cut', !!s.cut);
+ body.classList.toggle('keep', !!s.keep);
if (s.cut) { curZh = ''; curEn = ''; zh.textContent = ''; en.textContent = ''; return; }
+ if (s.keep && s.text === curZh) return; // only the colour changed
render(s.text, s.en, s.cap);
} catch (_) {}
};