From 833f2a73dcbd91be5be431e8a7ea80a9efcaba30 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 8 Oct 2026 06:41:27 +0000 Subject: [PATCH] Grid script pages: version the scripts so a cached old copy can't break the slider On a phone that still had the v7 app/script.js and lib/glyph.js cached, the new page's COUNT.4.171 example threw in the old parser, which stopped the explainer before the number slider was wired up. The pages now load app/script.js?v=8 (and it loads lib/glyph.js and the vocab with the same version), and each example is drawn on its own so one failure can't take down the rest of the page. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01QgskKyin9t8k9F6KcUj5o7 --- app/script.js | 20 +++++++++++++------- script/convert/en/index.html | 2 +- script/convert/index.html | 2 +- script/dictionary/en/index.html | 2 +- script/dictionary/index.html | 2 +- script/en/index.html | 2 +- script/index.html | 2 +- 7 files changed, 19 insertions(+), 13 deletions(-) diff --git a/app/script.js b/app/script.js index 2a0f439..74cc174 100644 --- a/app/script.js +++ b/app/script.js @@ -5,13 +5,14 @@ import { Vocabulary, GlyphError, parsePage, formatPage, render, renderSvg, rowsSvg, decode, readGraph, bandRows, pageSymbols, wordStr, isEmpty, structure, ink, numberShape, positions, toDigits, hiddenZeros, EMPTY_CELL, BACKGROUND, GRID, BASE, -} from '../lib/glyph.js'; +} from '../lib/glyph.js?v=8'; // bump ?v= (here, in the pages and in GLYPH_DATA) whenever the script changes const zh = document.documentElement.lang.toLowerCase().startsWith('zh'); const $ = (s, el = document) => el.querySelector(s); const $$ = (s, el = document) => [...el.querySelectorAll(s)]; const esc = (s) => String(s ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c]); const LIB = new URL('../lib/', import.meta.url); +const GLYPH_DATA = '?v=8'; // a phone holding an older cached copy must not mix it with new data const HERE = new URL('./', location.href); // the section's pages: CN at script/…/, EN at script/…/en/ const SECTION = new URL('../script/', import.meta.url); @@ -66,7 +67,7 @@ const message = (err) => { // ------------------------------------------------------------------ data async function loadVocab() { - const get = (f) => fetch(new URL(f, LIB)).then((r) => { if (!r.ok) throw new Error(`${f}: ${r.status}`); return r.json(); }); + const get = (f) => fetch(new URL(f + GLYPH_DATA, LIB)).then((r) => { if (!r.ok) throw new Error(`${f}: ${r.status}`); return r.json(); }); const [data, z] = await Promise.all([get('glyph-vocab.json'), get('glyph-zh.json')]); const en = new Vocabulary(data); if (!zh) return { en, voc: en, z: null }; @@ -121,11 +122,16 @@ function explainer({ en, voc }) { }).join(''); } for (const el of $$('[data-gs-example]')) { - const source = el.dataset.gsExample.replaceAll('\\n', '\n'); - const page = parsePage(source, en); - el.innerHTML = `
${renderSvg(en, page, { cell: 14 })}
-
${esc(formatPage(page).trim())}
${graphHtml(voc, readGraph(voc, page), pageSymbols(page))} - ${zh ? '在转换器里打开 →' : 'Open in the converter →'}
`; + // one example that can't be read must not stop the rest of the page (the number slider comes after them) + try { + const source = el.dataset.gsExample.replaceAll('\\n', '\n'); + const page = parsePage(source, en); + el.innerHTML = `
${renderSvg(en, page, { cell: 14 })}
+
${esc(formatPage(page).trim())}
${graphHtml(voc, readGraph(voc, page), pageSymbols(page))} + ${zh ? '在转换器里打开 →' : 'Open in the converter →'}
`; + } catch (err) { + console.error(err); + } } for (const el of $$('[data-gs-number]')) { const input = $('input[type=range]', el), num = $('input[type=number]', el), out = $('.gs-draw', el), bits = $('.gs-bits', el); diff --git a/script/convert/en/index.html b/script/convert/en/index.html index a0090f8..d0ce248 100644 --- a/script/convert/en/index.html +++ b/script/convert/en/index.html @@ -12,7 +12,7 @@ - + diff --git a/script/convert/index.html b/script/convert/index.html index 3124a26..963c33a 100644 --- a/script/convert/index.html +++ b/script/convert/index.html @@ -12,7 +12,7 @@ - + diff --git a/script/dictionary/en/index.html b/script/dictionary/en/index.html index c575436..51838a0 100644 --- a/script/dictionary/en/index.html +++ b/script/dictionary/en/index.html @@ -12,7 +12,7 @@ - + diff --git a/script/dictionary/index.html b/script/dictionary/index.html index 59374fe..07e07e4 100644 --- a/script/dictionary/index.html +++ b/script/dictionary/index.html @@ -12,7 +12,7 @@ - + diff --git a/script/en/index.html b/script/en/index.html index f64407d..a7e1f11 100644 --- a/script/en/index.html +++ b/script/en/index.html @@ -12,7 +12,7 @@ - + diff --git a/script/index.html b/script/index.html index f5372d7..276fb77 100644 --- a/script/index.html +++ b/script/index.html @@ -12,7 +12,7 @@ - +