Corrige l'ouverture de la page chrono
This commit is contained in:
70
app.js
70
app.js
@@ -1,6 +1,7 @@
|
|||||||
const PAGE = document.body.dataset.page;
|
const PAGE = document.body.dataset.page;
|
||||||
|
|
||||||
const STORAGE_KEY = "chesscubing-arena-state-v2";
|
const STORAGE_KEY = "chesscubing-arena-state-v2";
|
||||||
|
const WINDOW_NAME_KEY = "chesscubing-arena-state-v2:";
|
||||||
const BLOCK_DURATION_MS = 180000;
|
const BLOCK_DURATION_MS = 180000;
|
||||||
const MOVE_LIMIT_MS = 20000;
|
const MOVE_LIMIT_MS = 20000;
|
||||||
const TIME_MODE_INITIAL_CLOCK_MS = 600000;
|
const TIME_MODE_INITIAL_CLOCK_MS = 600000;
|
||||||
@@ -149,15 +150,16 @@ function initSetupPage() {
|
|||||||
|
|
||||||
form.addEventListener("submit", (event) => {
|
form.addEventListener("submit", (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
const data = new FormData(form);
|
||||||
const config = {
|
const config = {
|
||||||
matchLabel: sanitizeText(form.elements.matchLabel.value) || "Rencontre ChessCubing",
|
matchLabel: sanitizeText(data.get("matchLabel")) || "Rencontre ChessCubing",
|
||||||
mode: getRadioValue(form, "mode") || "twice",
|
mode: getRadioValue(form, "mode") || "twice",
|
||||||
preset: getRadioValue(form, "preset") || "fast",
|
preset: getRadioValue(form, "preset") || "fast",
|
||||||
whiteName: sanitizeText(form.elements.whiteName.value) || "Blanc",
|
whiteName: sanitizeText(data.get("whiteName")) || "Blanc",
|
||||||
blackName: sanitizeText(form.elements.blackName.value) || "Noir",
|
blackName: sanitizeText(data.get("blackName")) || "Noir",
|
||||||
arbiterName: sanitizeText(form.elements.arbiterName.value),
|
arbiterName: sanitizeText(data.get("arbiterName")),
|
||||||
eventName: sanitizeText(form.elements.eventName.value),
|
eventName: sanitizeText(data.get("eventName")),
|
||||||
notes: sanitizeText(form.elements.notes.value),
|
notes: sanitizeText(data.get("notes")),
|
||||||
};
|
};
|
||||||
|
|
||||||
match = createMatch(config);
|
match = createMatch(config);
|
||||||
@@ -834,20 +836,22 @@ function createMatch(config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function readStoredMatch() {
|
function readStoredMatch() {
|
||||||
|
const fromWindowName = readWindowNameState();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const raw = localStorage.getItem(STORAGE_KEY);
|
const raw = localStorage.getItem(STORAGE_KEY);
|
||||||
if (!raw) {
|
if (!raw) {
|
||||||
return null;
|
return fromWindowName;
|
||||||
}
|
}
|
||||||
|
|
||||||
const parsed = JSON.parse(raw);
|
const parsed = JSON.parse(raw);
|
||||||
if (!parsed || parsed.schemaVersion !== 2) {
|
if (!parsed || parsed.schemaVersion !== 2) {
|
||||||
return null;
|
return fromWindowName;
|
||||||
}
|
}
|
||||||
|
|
||||||
return parsed;
|
return parsed;
|
||||||
} catch {
|
} catch {
|
||||||
return null;
|
return fromWindowName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1342,12 +1346,25 @@ function replaceTo(target) {
|
|||||||
|
|
||||||
function persistMatch() {
|
function persistMatch() {
|
||||||
if (!match) {
|
if (!match) {
|
||||||
|
try {
|
||||||
localStorage.removeItem(STORAGE_KEY);
|
localStorage.removeItem(STORAGE_KEY);
|
||||||
|
} catch {
|
||||||
|
// Ignore storage errors and still clear the window-level fallback.
|
||||||
|
}
|
||||||
|
window.name = "";
|
||||||
dirty = false;
|
dirty = false;
|
||||||
return;
|
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;
|
dirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1376,17 +1393,24 @@ function toggleModal(element, open) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function loadDemo(form, onRender) {
|
function loadDemo(form, onRender) {
|
||||||
form.elements.matchLabel.value = "Demo officielle ChessCubing";
|
setInputValue(form, "matchLabel", "Demo officielle ChessCubing");
|
||||||
setRadioValue(form, "mode", "twice");
|
setRadioValue(form, "mode", "twice");
|
||||||
setRadioValue(form, "preset", "freeze");
|
setRadioValue(form, "preset", "freeze");
|
||||||
form.elements.whiteName.value = "Nora";
|
setInputValue(form, "whiteName", "Nora");
|
||||||
form.elements.blackName.value = "Leo";
|
setInputValue(form, "blackName", "Leo");
|
||||||
form.elements.arbiterName.value = "Arbitre demo";
|
setInputValue(form, "arbiterName", "Arbitre demo");
|
||||||
form.elements.eventName.value = "Session telephone";
|
setInputValue(form, "eventName", "Session telephone");
|
||||||
form.elements.notes.value = "8 cubes verifies, variante prete, tirage au sort effectue.";
|
setInputValue(form, "notes", "8 cubes verifies, variante prete, tirage au sort effectue.");
|
||||||
onRender();
|
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) {
|
function getRadioValue(form, name) {
|
||||||
const selected = form.querySelector(`input[name="${name}"]:checked`);
|
const selected = form.querySelector(`input[name="${name}"]:checked`);
|
||||||
return selected ? selected.value : "";
|
return selected ? selected.value : "";
|
||||||
@@ -1464,3 +1488,17 @@ function escapeHtml(value) {
|
|||||||
.replace(/"/g, """)
|
.replace(/"/g, """)
|
||||||
.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -120,12 +120,12 @@
|
|||||||
|
|
||||||
<label class="field">
|
<label class="field">
|
||||||
<span>Joueur blanc</span>
|
<span>Joueur blanc</span>
|
||||||
<input name="whiteName" type="text" maxlength="40" placeholder="Blanc" required />
|
<input name="whiteName" type="text" maxlength="40" placeholder="Blanc" value="Blanc" />
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<label class="field">
|
<label class="field">
|
||||||
<span>Joueur noir</span>
|
<span>Joueur noir</span>
|
||||||
<input name="blackName" type="text" maxlength="40" placeholder="Noir" required />
|
<input name="blackName" type="text" maxlength="40" placeholder="Noir" value="Noir" />
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<label class="field">
|
<label class="field">
|
||||||
|
|||||||
Reference in New Issue
Block a user