From 6066aac6aa16a39a8afd81fb355ca4ef6dff1108 Mon Sep 17 00:00:00 2001 From: Eric Bell Date: Tue, 24 Nov 2026 12:36:25 -0500 Subject: [PATCH] Show and copy referenced credentials in steps, view, player and print (Refs #24) Co-Authored-By: Claude Sonnet 5.5 --- OVERVIEW.md | 1 + README.md | 9 ++++++++ src/app.js | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/style.css | 1 + src/version.js | 2 +- 5 files changed, 70 insertions(+), 1 deletion(-) diff --git a/OVERVIEW.md b/OVERVIEW.md index 21bfa0c..3405458 100644 --- a/OVERVIEW.md +++ b/OVERVIEW.md @@ -66,6 +66,7 @@ A **visual sequence** (`kind: 'sequence'`, numbered `frames` of image + text wit - **Images:** drag and drop, clipboard paste and file picker all feed `importFiles()`. Files are sniffed by their first bytes, downscaled to at most 1600 px and re-encoded, which strips metadata, and stored as data URLs with a limit of about 3 MB each. - **Walkthroughs (issue #23):** a sequence frame may carry `ifStuck` text and a `stop` flag, and a sequence a `captured` date. In Edit, "Capture from screen…" uses `getDisplayMedia` (`startScreenCapture`, `grabScreenFrame`, `stopScreenCapture` in `images.js`; the stream lives in a closure variable in `app.js`, ended when leaving edit mode) and adds frames via `addCapture()` in `ops.js`. In view mode `state.walk` (`{id, k}`, not saved) shows a sequence one step at a time (`walkSequence`). +- **Credential references (issue #24):** a frame's `uses: [{record, field}]` points at record fields by id. A field gets an `id` the first time it is referenced (`ensureFieldId`, `addUse`, `findFieldRef`, `allRecordsIn` in `ops.js`). A dangling reference is shown as removed, never a validation error. `viewUses` and `copyValue` (30 s clipboard wipe) are in `app.js`; `usesView` in `print.js` does the masked/included print text. - **Reset (`?reset=1`):** opening the file with `?reset=1` or `#reset=1` shows a banner after unlock offering to erase every secret-flagged field value and secret frame (`clearSecrets()` in `ops.js`, count from `countSecrets`). Labels, structure and flags stay. It is read live (`resetRequested()`), with a `hashchange` listener to re-offer, and `state.resetOffered` dismisses it. Nothing is written until Save, so make a Backup copy first. It's meant for working on layout on a less safe machine. **Save.** Uses the File System Access API (`showSaveFilePicker`, handle reused) where available, otherwise a Blob download. `assemble()` rebuilds the full HTML from the page's own CSS and JS plus a fresh encrypted payload. "Backup copy" downloads `final-wishes-YYYYMMDD.html`. diff --git a/README.md b/README.md index 26c8080..9e49fe6 100644 --- a/README.md +++ b/README.md @@ -173,6 +173,15 @@ not part of a record or item, so it sits exactly where you put it. say). Tick **Stop here** to tell the reader not to go further without help. Both show in the list, the walkthrough and print, and are hidden with a secret step. +- **Credentials a step needs:** in Edit, each step has **+ Use a field from a + record…**. Pick the login fields (say Santander's username and password) and + the step shows them beside the picture, live from the record, so there is one + copy to keep current. A secret stays masked until **Show**; **Copy** puts the + value on the clipboard without showing it (the clipboard is wiped after 30 + seconds, which also replaces anything else copied in that time). Print shows + them too, masked unless you choose "Include secrets". If the record or field is + later deleted the step says the credential was removed. Renaming or + reordering fields is safe: the link is to the field itself. - **Walkthrough:** in view mode, **Walk through, one step at a time** shows one step with Back / Next. A sequence made from captures shows its capture date and a reminder that the site may have changed since. diff --git a/src/app.js b/src/app.js index 0a0e315..aa3149a 100644 --- a/src/app.js +++ b/src/app.js @@ -158,6 +158,20 @@ const allRecords = () => state.doc.sections.flatMap((s) => (s.records || []).filter((r) => !isSequence(r))); const addFrameFrom = (seq) => (name, url) => addFrame(seq, url); + // Copy a credential for the reader, then wipe the clipboard after 30 seconds + // (this overwrites whatever is on the clipboard by then, whether or not it is ours). + let clipTimer = null; + async function copyValue(fld) { + try { + await navigator.clipboard.writeText(fld.value); + clearTimeout(clipTimer); + clipTimer = setTimeout(() => { navigator.clipboard.writeText('').catch(() => {}); }, 30000); + setStatus('Copied ' + fld.label + '. The clipboard is cleared in 30 seconds.'); + } catch { + setStatus('Could not copy ' + fld.label + '. Show it and copy it by hand.'); + } + } + // Screen capture while editing a visual sequence. The stream lives here, not in // the DOM, so it survives render(). { stream, video, seqId } or null. let capture = null; @@ -338,12 +352,30 @@ onclick: () => openLightbox(label, f.image), onkeydown: (e) => { if (e.key === 'Enter') openLightbox(label, f.image); } }) : h('span', { class: 'muted' }, '(no image)'), layout !== 'none' ? h('p', { class: 'ftext' }, f.text) : null, + viewUses(f), f.stop || String(f.ifStuck || '').trim() ? h('div', { class: 'fnotes' }, f.stop ? h('p', { class: 'fstop' }, h('strong', {}, 'Stop here. Do not go further.')) : null, String(f.ifStuck || '').trim() ? h('p', { class: 'fstuck' }, h('strong', {}, 'If it looks different or fails: '), f.ifStuck) : null) : null, f.secret ? btn('Hide', toggle, 'link', { 'aria-label': 'Hide ' + label }) : null]); } + // The credentials a step needs, live from their records: secrets stay masked until shown. + function viewUses(f) { + if (!f.uses || !f.uses.length) return null; + return h('div', { class: 'fuses' }, h('strong', {}, 'You will need:'), f.uses.map((u) => { + const hit = findFieldRef(state.doc, u); + if (!hit) return h('p', { class: 'muted' }, '(a credential this step used has been removed)'); + const fld = hit.field; + const shown = !fld.secret || state.revealed.has(fld); + const toggle = () => { state.revealed[shown ? 'delete' : 'add'](fld); render(); }; + return h('div', { class: 'row fuse' }, + h('span', {}, hit.record.title + ' \u203A ' + fld.label + ': '), + h('span', { class: fld.secret ? 'secret' : '' }, !fld.value ? '(not set)' : shown ? fld.value : '\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022'), + fld.secret ? btn(shown ? 'Hide' : 'Show', toggle, 'link', { 'aria-label': (shown ? 'Hide ' : 'Show ') + fld.label }) : null, + fld.value ? btn('Copy', () => copyValue(fld), 'small', { 'aria-label': 'Copy ' + fld.label }) : null); + })); + } + const capturedNote = (q) => (q.captured ? ' Captured ' + q.captured + '. The site may have changed since.' : ''); // One step at a time, with Back/Next. A secret step stays hidden until shown, as in the list. @@ -517,6 +549,29 @@ const LAYOUT_LABELS = [['right', 'Text right of image'], ['under', 'Text under image'], ['none', 'No text']]; + // Pick the record fields this step needs; the reader sees them beside the step. + function useEditor(q, f, k) { + const recs = allRecords().filter((r) => r.fields.some((x) => x.kind !== 'image')); + const pick = h('select', { 'aria-label': 'Add a credential to step ' + (k + 1), onchange: () => { + if (!pick.value) return; + const [rid, idx] = pick.value.split('|'); + const rec = recs.find((r) => r.id === rid); + if (rec && addUse(f, rec, rec.fields[Number(idx)])) { changed(q); render(); } + } }, + h('option', { value: '' }, '+ Use a field from a record\u2026'), + recs.map((r) => h('optgroup', { label: r.title }, r.fields.map((x, i) => (x.kind === 'image' ? null + : h('option', { value: r.id + '|' + i }, x.label + (x.secret ? ' (secret)' : ''))))))); + return h('div', {}, + h('strong', {}, 'Credentials this step needs'), + (f.uses || []).map((u, i) => { + const hit = findFieldRef(state.doc, u); + return h('div', { class: 'row' }, + h('span', {}, hit ? hit.record.title + ' \u203A ' + hit.field.label : '(removed)'), + btn('\u2715', () => { removeUse(f, i); changed(q); render(); }, 'icon danger', { 'aria-label': 'Remove credential from step ' + (k + 1) })); + }), + pick); + } + function editFrame(q, f, k) { const secret = h('input', { type: 'checkbox', checked: !!f.secret, 'aria-label': 'Secret step', onchange: () => { f.secret = secret.checked || undefined; if (!f.secret) delete f.secret; changed(q); } }); @@ -529,6 +584,7 @@ imageZone(f, 'image', q.title + ', step ' + (k + 1), { 'data-frame': String(k) }, (files) => importFiles(q, files, { key: 'image', replace: f, add: addFrameFrom(q) }), () => changed(q)), f.layout === 'none' ? null : h('label', {}, 'Text', input(f, 'text', { multiline: true, label: 'Text for step ' + (k + 1) }, q)), + useEditor(q, f, k), h('label', {}, 'If it looks different or fails', input(f, 'ifStuck', { multiline: true, label: 'If step ' + (k + 1) + ' looks different or fails' }, q)), h('label', { class: 'check' }, stop, ' Stop here: the reader must not go further without help')); } @@ -633,6 +689,8 @@ : v.image ? h('img', { class: 'pimg', src: v.image, alt: 'Step ' + (k + 1) }) : h('p', {}, '(no image)'), v.layout !== 'none' ? h('p', { class: 'pftext' }, v.text) : null, + v.withheld ? null : usesView(state.doc, f, includeSecrets).map((u) => h('p', { class: 'pftext' }, + u.missing ? '(a credential this step used has been removed)' : 'You will need: ' + u.record + ' \u203A ' + u.label + ': ' + u.value)), v.stop ? h('p', { class: 'pstop' }, h('strong', {}, 'STOP HERE. Do not go further.')) : null, v.ifStuck ? h('p', { class: 'pftext' }, h('strong', {}, 'If it looks different or fails: '), v.ifStuck) : null); } diff --git a/src/style.css b/src/style.css index 672b67e..58daebc 100644 --- a/src/style.css +++ b/src/style.css @@ -59,6 +59,7 @@ textarea { width: 100%; display: block; } label { display: block; margin-top: .5 .fnum { font-weight: 700; color: var(--accent); } .ftext { white-space: pre-wrap; margin: 0; } li.seqitem { display: block; list-style: none; margin-left: -1.4rem; } .frameedit { border-top: 1px dashed var(--line); padding-top: .5rem; } .fnotes { grid-column: 1 / -1; display: grid; gap: .35rem; } .fnotes p { margin: 0; } +.fuses { grid-column: 1 / -1; } .fuse { align-items: center; margin: .25rem 0; } .fstop { border: 2px solid var(--danger); color: var(--danger); border-radius: .35rem; padding: .35rem .6rem; } .fstuck { background: var(--warn-bg); color: var(--warn-fg); border-radius: .35rem; padding: .35rem .6rem; white-space: pre-wrap; } .walk .fimg { max-height: 28rem; } .walknav { align-items: center; margin-top: .75rem; } diff --git a/src/version.js b/src/version.js index cf25fd1..2ab639c 100644 --- a/src/version.js +++ b/src/version.js @@ -2,7 +2,7 @@ // YYMMDD is the date, X the iteration that day (A first, B second, ...). // Bump with `npm run bump` (see bump-version.js). build.js strips `export`. -export const APP_VERSION = '261124C'; +export const APP_VERSION = '261124D'; const VERSION_RE = /^(\d{6})([A-Z])$/; export const isVersion = (v) => typeof v === 'string' && VERSION_RE.test(v);