diff options
Diffstat (limited to 'web')
| -rw-r--r-- | web/index.html | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/web/index.html b/web/index.html index 5179370..677fe14 100644 --- a/web/index.html +++ b/web/index.html @@ -8,6 +8,7 @@ html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; background: #fff; color: #000; cursor: none; + transition: background-color 90ms linear, color 90ms linear; -webkit-user-select: none; user-select: none; font-family: "Noto Sans CJK SC Black", "Noto Sans SC Black", "Source Han Sans SC", "Noto Sans CJK JP Black", "PingFang SC", sans-serif; @@ -42,6 +43,9 @@ display: none; } body.en #en { display: block; } + /* sentence alternates black-on-white and white-on-black; Backspace = red retake */ + body.invert { background: #000; color: #fff; } + body.cut { background: #d10d0d; color: #fff; } @keyframes pop { from { opacity: .5; transform: scale(.955); } to { opacity: 1; transform: scale(1); } @@ -63,6 +67,7 @@ const zh = document.getElementById('zh'); const en = document.getElementById('en'); const d = document.getElementById('d'); + const body = document.body; const q = new URLSearchParams(location.search); const debug = q.has('debug'); const wantEN = q.has('en'); @@ -105,6 +110,13 @@ if (reserve) en.textContent = ''; } + function cut() { + body.classList.add('cut'); // instant feedback, server confirms it + curZh = ''; curEn = ''; + zh.textContent = ''; en.textContent = ''; + fetch('/cut', { method: 'POST', keepalive: true }).catch(function () {}); + } + function render(text, translation, cap) { if (!text) return; const newPhrase = text !== curZh; @@ -142,6 +154,12 @@ addEventListener('resize', function () { measurePad(); fit(); }); addEventListener('keydown', function (e) { + 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(); + cut(); + return; + } if (e.key === 'f' || e.key === 'F') { if (document.fullscreenElement) document.exitFullscreen(); else document.documentElement.requestFullscreen(); @@ -150,6 +168,9 @@ measurePad(); + if (q.has('invert')) body.classList.add('invert'); + if (q.has('cut')) { body.classList.add('cut'); return; } + if (q.has('text')) { // design preview: index.html?en=1&text=你好&t=hello render(q.get('text'), q.get('t') || '', 0); return; @@ -159,6 +180,9 @@ es.onmessage = function (e) { try { const s = JSON.parse(e.data); + body.classList.toggle('invert', !!s.invert); + body.classList.toggle('cut', !!s.cut); + if (s.cut) { curZh = ''; curEn = ''; zh.textContent = ''; en.textContent = ''; return; } render(s.text, s.en, s.cap); } catch (_) {} }; |
