Skip to content

Commit 633e785

Browse files
author
CuzImBisonratte
authored
Update themes.js
Added an error-protection
1 parent 2d12dc9 commit 633e785

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

themes.js

+21-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ ThemeColorTextDark = "#818181";
99
ThemeButtonNameLight = "Hell";
1010
ThemeButtonNameDark = "Dunkel";
1111

12-
12+
// Initialize the Themes-variable
13+
var theme;
1314

1415
// Funktion, die die Farbänderungen auführt
1516
function changeToTheme(backgroundColor,textColor,themeName){
@@ -24,8 +25,16 @@ function changeToTheme(backgroundColor,textColor,themeName){
2425
function initializeTheme(){
2526

2627
// Aktuelles Theme abrufen
27-
theme = localStorage.getItem("theme");
28-
28+
try{
29+
theme = localStorage.getItem("theme");
30+
}
31+
catch(e) {
32+
if(e.name == "NS_ERROR_FILE_CORRUPTED") {
33+
localStorage.clear();
34+
theme = localStorage.getItem("theme");
35+
}
36+
}
37+
2938
//Theme auf gespeichertes Theme setzen
3039
if(theme=="light"){
3140

@@ -48,7 +57,15 @@ initializeTheme();
4857
function toggleTheme(){
4958

5059
// Aktuelles Theme abrufen
51-
theme = localStorage.getItem("theme");
60+
try{
61+
theme = localStorage.getItem("theme");
62+
}
63+
catch(e) {
64+
if(e.name == "NS_ERROR_FILE_CORRUPTED") {
65+
localStorage.clear();
66+
theme = localStorage.getItem("theme");
67+
}
68+
}
5269

5370
// Theme basierend auf Aktuellem theme ändern
5471
if(theme=="dark"){

0 commit comments

Comments
 (0)