From 12a4ce8b9774b2accced95de1f255bd1659f0f5d Mon Sep 17 00:00:00 2001 From: Christophe Date: Sun, 12 Apr 2026 11:56:29 +0200 Subject: [PATCH] Corrige l'ouverture de la page chrono --- app.js | 72 +++++++++++++++++++++++++++++++++++++++++------------- index.html | 4 +-- 2 files changed, 57 insertions(+), 19 deletions(-) diff --git a/app.js b/app.js index e2c63b6..bb5db86 100644 --- a/app.js +++ b/app.js @@ -1,6 +1,7 @@ const PAGE = document.body.dataset.page; const STORAGE_KEY = "chesscubing-arena-state-v2"; +const WINDOW_NAME_KEY = "chesscubing-arena-state-v2:"; const BLOCK_DURATION_MS = 180000; const MOVE_LIMIT_MS = 20000; const TIME_MODE_INITIAL_CLOCK_MS = 600000; @@ -149,15 +150,16 @@ function initSetupPage() { form.addEventListener("submit", (event) => { event.preventDefault(); + const data = new FormData(form); const config = { - matchLabel: sanitizeText(form.elements.matchLabel.value) || "Rencontre ChessCubing", + matchLabel: sanitizeText(data.get("matchLabel")) || "Rencontre ChessCubing", mode: getRadioValue(form, "mode") || "twice", preset: getRadioValue(form, "preset") || "fast", - whiteName: sanitizeText(form.elements.whiteName.value) || "Blanc", - blackName: sanitizeText(form.elements.blackName.value) || "Noir", - arbiterName: sanitizeText(form.elements.arbiterName.value), - eventName: sanitizeText(form.elements.eventName.value), - notes: sanitizeText(form.elements.notes.value), + whiteName: sanitizeText(data.get("whiteName")) || "Blanc", + blackName: sanitizeText(data.get("blackName")) || "Noir", + arbiterName: sanitizeText(data.get("arbiterName")), + eventName: sanitizeText(data.get("eventName")), + notes: sanitizeText(data.get("notes")), }; match = createMatch(config); @@ -834,20 +836,22 @@ function createMatch(config) { } function readStoredMatch() { + const fromWindowName = readWindowNameState(); + try { const raw = localStorage.getItem(STORAGE_KEY); if (!raw) { - return null; + return fromWindowName; } const parsed = JSON.parse(raw); if (!parsed || parsed.schemaVersion !== 2) { - return null; + return fromWindowName; } return parsed; } catch { - return null; + return fromWindowName; } } @@ -1342,12 +1346,25 @@ function replaceTo(target) { function persistMatch() { if (!match) { - localStorage.removeItem(STORAGE_KEY); + try { + localStorage.removeItem(STORAGE_KEY); + } catch { + // Ignore storage errors and still clear the window-level fallback. + } + window.name = ""; dirty = false; return; } - localStorage.setItem(STORAGE_KEY, JSON.stringify(match)); + const serialized = JSON.stringify(match); + window.name = `${WINDOW_NAME_KEY}${serialized}`; + + try { + localStorage.setItem(STORAGE_KEY, serialized); + } catch { + // Keep the window.name fallback so cross-page navigation still works. + } + dirty = false; } @@ -1376,17 +1393,24 @@ function toggleModal(element, open) { } function loadDemo(form, onRender) { - form.elements.matchLabel.value = "Demo officielle ChessCubing"; + setInputValue(form, "matchLabel", "Demo officielle ChessCubing"); setRadioValue(form, "mode", "twice"); setRadioValue(form, "preset", "freeze"); - form.elements.whiteName.value = "Nora"; - form.elements.blackName.value = "Leo"; - form.elements.arbiterName.value = "Arbitre demo"; - form.elements.eventName.value = "Session telephone"; - form.elements.notes.value = "8 cubes verifies, variante prete, tirage au sort effectue."; + setInputValue(form, "whiteName", "Nora"); + setInputValue(form, "blackName", "Leo"); + setInputValue(form, "arbiterName", "Arbitre demo"); + setInputValue(form, "eventName", "Session telephone"); + setInputValue(form, "notes", "8 cubes verifies, variante prete, tirage au sort effectue."); onRender(); } +function setInputValue(form, name, value) { + const input = form.querySelector(`[name="${name}"]`); + if (input instanceof HTMLInputElement || input instanceof HTMLTextAreaElement) { + input.value = value; + } +} + function getRadioValue(form, name) { const selected = form.querySelector(`input[name="${name}"]:checked`); return selected ? selected.value : ""; @@ -1464,3 +1488,17 @@ function escapeHtml(value) { .replace(/"/g, """) .replace(/'/g, "'"); } + +function readWindowNameState() { + try { + if (!window.name || !window.name.startsWith(WINDOW_NAME_KEY)) { + return null; + } + + const raw = window.name.slice(WINDOW_NAME_KEY.length); + const parsed = JSON.parse(raw); + return parsed && parsed.schemaVersion === 2 ? parsed : null; + } catch { + return null; + } +} diff --git a/index.html b/index.html index f5aff09..67845de 100644 --- a/index.html +++ b/index.html @@ -120,12 +120,12 @@