restart on no hash

This commit is contained in:
Adrien MALINGREY 2023-03-31 02:22:07 +02:00
parent c47cd498c0
commit 60b5f74e94

View File

@ -80,14 +80,14 @@ window.onload = function() {
else if (node.label) node.label.title += shortcut else if (node.label) node.label.title += shortcut
} }
onhashchange() loadSavedGame()
if ("serviceWorker" in navigator) { if ("serviceWorker" in navigator) {
navigator.serviceWorker.register(`service-worker.php?location=${location.pathname}`) navigator.serviceWorker.register(`service-worker.php?location=${location.pathname}`)
} }
} }
onhashchange = function(event) { function loadSavedGame() {
const savedGame = location.hash.slice(1) const savedGame = location.hash.slice(1)
if (savedGame.match(/[1-9.]{81}/)) { if (savedGame.match(/[1-9.]{81}/)) {
boxes.forEach((box, i) => { boxes.forEach((box, i) => {
@ -103,6 +103,11 @@ onhashchange = function(event) {
refreshUI() refreshUI()
} }
onhashchange = function(event) {
if (location.hash.slice(1)) loadSavedGame()
else restart()
}
function searchCandidatesOf(box) { function searchCandidatesOf(box) {
box.candidates = new Set(VALUES) box.candidates = new Set(VALUES)
box.neighbourhood.forEach(neighbour => box.candidates.delete(neighbour.value)) box.neighbourhood.forEach(neighbour => box.candidates.delete(neighbour.value))