From 0aae2d0678e2d651eef74cf155278c3f9a79111f Mon Sep 17 00:00:00 2001 From: BalintCsala Date: Tue, 1 Nov 2022 15:12:04 +0100 Subject: [PATCH] Fixes issue when localStorage is disabled --- layouts/partials/theme-switcher.html | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/layouts/partials/theme-switcher.html b/layouts/partials/theme-switcher.html index ab97e84..dd24831 100644 --- a/layouts/partials/theme-switcher.html +++ b/layouts/partials/theme-switcher.html @@ -43,7 +43,7 @@ document.addEventListener('DOMContentLoaded', function() { }) function detectCurrentScheme() { - if (localStorage.getItem(STORAGE_KEY)) { + if (localStorage !== null && localStorage.getItem(STORAGE_KEY)) { return localStorage.getItem(STORAGE_KEY) } if (defaultTheme) { @@ -67,11 +67,13 @@ function changeButtonText() function switchTheme(e) { if (currentTheme == 'dark') { - localStorage.setItem(STORAGE_KEY, 'light') + if (localStorage !== null) + localStorage.setItem(STORAGE_KEY, 'light') document.documentElement.setAttribute('data-theme', 'light') currentTheme = 'light' } else { - localStorage.setItem(STORAGE_KEY, 'dark') + if (localStorage !== null) + localStorage.setItem(STORAGE_KEY, 'dark') document.documentElement.setAttribute('data-theme', 'dark') currentTheme = 'dark' }