From 60b5f74e94834fb3599d9120d305b7d201ce8881 Mon Sep 17 00:00:00 2001 From: adrien Date: Fri, 31 Mar 2023 02:22:07 +0200 Subject: [PATCH] restart on no hash --- js/sudoku.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/js/sudoku.js b/js/sudoku.js index b9484f0..3083765 100755 --- a/js/sudoku.js +++ b/js/sudoku.js @@ -80,14 +80,14 @@ window.onload = function() { else if (node.label) node.label.title += shortcut } - onhashchange() + loadSavedGame() if ("serviceWorker" in navigator) { navigator.serviceWorker.register(`service-worker.php?location=${location.pathname}`) } } -onhashchange = function(event) { +function loadSavedGame() { const savedGame = location.hash.slice(1) if (savedGame.match(/[1-9.]{81}/)) { boxes.forEach((box, i) => { @@ -103,6 +103,11 @@ onhashchange = function(event) { refreshUI() } +onhashchange = function(event) { + if (location.hash.slice(1)) loadSavedGame() + else restart() +} + function searchCandidatesOf(box) { box.candidates = new Set(VALUES) box.neighbourhood.forEach(neighbour => box.candidates.delete(neighbour.value))