Compare commits

..

No commits in common. "3974c9faabbd8714f8529e68762e0eb97eaefdb2" and "233ecb97c0f8d5f9f9e82995454167d43003d218" have entirely different histories.

3 changed files with 9 additions and 60 deletions

View File

@ -347,7 +347,7 @@
try { try {
parsed = ChessPressure.parsePgn(g.pgn); parsed = ChessPressure.parsePgn(g.pgn);
} catch (e) { } catch (e) {
modalAlert("That saved game could not be loaded (corrupted PGN).", "Couldn't load game"); alert("That saved game could not be loaded (corrupted PGN).");
return; return;
} }
applyParsed(parsed, savedId, true); applyParsed(parsed, savedId, true);
@ -360,7 +360,7 @@
try { try {
parsed = ChessPressure.parsePgn(pgn); parsed = ChessPressure.parsePgn(pgn);
} catch (e) { } catch (e) {
modalAlert("Could not parse PGN — please check the format and try again.", "Couldn't parse PGN"); alert("Could not parse PGN — please check the format and try again.");
return; return;
} }
applyParsed(parsed, null, isReference); applyParsed(parsed, null, isReference);
@ -458,28 +458,6 @@
}); });
} }
// Yes/no confirmation via the in-app dialog. Resolves true (OK) / false (cancel).
function modalConfirm(message, title) {
const dlg = document.getElementById("confirm-dialog");
document.getElementById("confirm-title").textContent = title || "Please confirm";
document.getElementById("confirm-msg").textContent = message;
dlg.querySelector("[data-cancel]").style.display = "";
return openModal(dlg);
}
// Single-button notice via the in-app dialog (replaces native alert()).
function modalAlert(message, title) {
const dlg = document.getElementById("confirm-dialog");
document.getElementById("confirm-title").textContent = title || "Notice";
document.getElementById("confirm-msg").textContent = message;
const cancel = dlg.querySelector("[data-cancel]");
cancel.style.display = "none";
return openModal(dlg).then((v) => {
cancel.style.display = "";
return v;
});
}
async function saveCurrentGame() { async function saveCurrentGame() {
if (!gameData) return; if (!gameData) return;
const dlg = document.getElementById("save-dialog"); const dlg = document.getElementById("save-dialog");
@ -524,7 +502,8 @@
if (!currentSavedId) return; if (!currentSavedId) return;
const g = getSavedGames().find((x) => x.id === currentSavedId); const g = getSavedGames().find((x) => x.id === currentSavedId);
if (!g) return; if (!g) return;
const ok = await modalConfirm(`Delete saved game "${g.name}"?`, "Delete game"); document.getElementById("confirm-msg").textContent = `Delete saved game "${g.name}"?`;
const ok = await openModal(document.getElementById("confirm-dialog"));
if (!ok) return; if (!ok) return;
setSavedGames(getSavedGames().filter((x) => x.id !== currentSavedId)); setSavedGames(getSavedGames().filter((x) => x.id !== currentSavedId));
currentSavedId = null; currentSavedId = null;
@ -532,26 +511,8 @@
updateSavedControls(); updateSavedControls();
} }
async function exportPGN() { function exportPGN() {
if (!gameData) return; if (!gameData) return;
// Let the user set player names before download; pre-fill from headers,
// treating placeholders ("?") as blank. Names are written back so they show
// on screen and persist on Save too.
const whiteEl = document.getElementById("pgn-white");
const blackEl = document.getElementById("pgn-black");
const real = (v) => (v && v !== "?" && v !== "????.??.??" ? v : "");
whiteEl.value = real(gameData.headers.White);
blackEl.value = real(gameData.headers.Black);
setTimeout(() => { whiteEl.focus(); whiteEl.select(); }, 0);
const ok = await openModal(document.getElementById("export-pgn-dialog"));
if (!ok) return;
gameData.headers.White = whiteEl.value.trim() || "White";
gameData.headers.Black = blackEl.value.trim() || "Black";
updateGameInfo();
const pgn = ChessPressure.toPgn(gameData.headers, gameData.moves); const pgn = ChessPressure.toPgn(gameData.headers, gameData.moves);
const slug = (defaultGameName() || "game") const slug = (defaultGameName() || "game")
.toLowerCase() .toLowerCase()

View File

@ -4,7 +4,7 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chess Pressure</title> <title>Chess Pressure</title>
<link rel="stylesheet" href="/style.css?v=31"> <link rel="stylesheet" href="/style.css?v=29">
<link rel="stylesheet" href="https://unpkg.com/@chrisoakman/chessboardjs@1.0.0/dist/chessboard-1.0.0.min.css"> <link rel="stylesheet" href="https://unpkg.com/@chrisoakman/chessboardjs@1.0.0/dist/chessboard-1.0.0.min.css">
<link rel="manifest" href="/manifest.json"> <link rel="manifest" href="/manifest.json">
</head> </head>
@ -135,21 +135,9 @@
</form> </form>
</dialog> </dialog>
<dialog id="export-pgn-dialog">
<form method="dialog">
<h2>Export PGN</h2>
<label>White: <input type="text" id="pgn-white" autocomplete="off" placeholder="White player"></label>
<label>Black: <input type="text" id="pgn-black" autocomplete="off" placeholder="Black player"></label>
<div class="dialog-buttons">
<button type="button" data-ok>Download</button>
<button type="button" data-cancel>Cancel</button>
</div>
</form>
</dialog>
<dialog id="confirm-dialog"> <dialog id="confirm-dialog">
<form method="dialog"> <form method="dialog">
<h2 id="confirm-title">Please confirm</h2> <h2>Please confirm</h2>
<p id="confirm-msg" class="export-info"></p> <p id="confirm-msg" class="export-info"></p>
<div class="dialog-buttons"> <div class="dialog-buttons">
<button type="button" data-ok>OK</button> <button type="button" data-ok>OK</button>
@ -176,6 +164,6 @@
<script src="/chess.min.js"></script> <script src="/chess.min.js"></script>
<script src="/gif.js"></script> <script src="/gif.js"></script>
<script src="/engine.js"></script> <script src="/engine.js"></script>
<script src="/app.js?v=31"></script> <script src="/app.js?v=29"></script>
</body> </body>
</html> </html>

View File

@ -7,7 +7,7 @@
* *
* Bump CACHE on every deploy so clients pick up new assets. * Bump CACHE on every deploy so clients pick up new assets.
*/ */
const CACHE = "chess-pressure-v31"; const CACHE = "chess-pressure-v29";
// Same-origin app shell. Cached by canonical path; the fetch handler matches // Same-origin app shell. Cached by canonical path; the fetch handler matches
// with ignoreSearch so cache-busting query strings (?v=NN) still hit. // with ignoreSearch so cache-busting query strings (?v=NN) still hit.