diff options
Diffstat (limited to 'js')
-rw-r--r-- | js/getTheme.ts | 13 | ||||
-rw-r--r-- | js/toggleTheme.ts | 3 |
2 files changed, 15 insertions, 1 deletions
diff --git a/js/getTheme.ts b/js/getTheme.ts new file mode 100644 index 0000000..769ea3c --- /dev/null +++ b/js/getTheme.ts @@ -0,0 +1,13 @@ +/// <reference path="setTheme.ts" /> + +function getTheme(): Theme { + let theme = Theme.Dark; + + try { + theme = JSON.parse(localStorage.getItem("theme")!); + } catch (e: any) { + console.log("invalid theme, using dark"); + } + + return theme; +} diff --git a/js/toggleTheme.ts b/js/toggleTheme.ts index 733a0f3..b5514d2 100644 --- a/js/toggleTheme.ts +++ b/js/toggleTheme.ts @@ -1,7 +1,8 @@ +/// <reference path="getTheme.ts" /> /// <reference path="setTheme.ts" /> function toggleTheme() { - let theme: Theme = JSON.parse(localStorage.getItem("theme")!); + let theme = getTheme(); if (theme == Theme.Light) { theme = Theme.Dark; |