From 48ccb99492d576825ebb2a64676328d18de32e45 Mon Sep 17 00:00:00 2001 From: Michiel Scholten Date: Sat, 23 Nov 2024 21:38:42 +0100 Subject: [PATCH] Restored accidentally removed test-for-localStorage functions --- src/alfagok/static/game.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/alfagok/static/game.js b/src/alfagok/static/game.js index 829b06c..a95236a 100644 --- a/src/alfagok/static/game.js +++ b/src/alfagok/static/game.js @@ -120,7 +120,7 @@ document.addEventListener('alpine:init', () => { const savedGameJson = localStorage.getItem('saveGame'); try { - return savedGameJSON && JSON.parse(savedGameJSON); + return savedGameJson && JSON.parse(savedGameJson); } catch (e) { localStorage.removeItem('saveGame'); } @@ -162,6 +162,21 @@ document.addEventListener('alpine:init', () => { if (gaveUpTime || this.winTime) { this.guessValue = guessValue; } + }, + resetSavedGames() { + localStorage.removeItem('saveGame'); + }, + testLocalStorage() { + // stolen from https://stackoverflow.com/questions/16427636/check-if-localstorage-is-available + const test = 'test'; + try { + localStorage.setItem(test, test); + localStorage.removeItem(test); + this.isLocalStorageAvailable = true; + } catch (e) { + this.isLocalStorageAvailable = false; + } + console.log('Local storage is available? ' + this.isLocalStorageAvailable); }, getFormattedTime(milliseconds) { if (!Number.isInteger(milliseconds)) {