Last active
December 17, 2021 19:56
-
-
Save CuzImBisonratte/fcbd77deb08f7f5f5d5aa8e083b64481 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//themes.js von CuzImBisonratte | |
//https://github.com/CuzImBisonratte/themes.js | |
// Hier kannst du die Farbcodes umstellen | |
ThemeColorBackLight = "#f1f1f1"; | |
ThemeColorBackDark = "#282C36"; | |
ThemeColorTextLight = "#282C36"; | |
ThemeColorTextDark = "#818181"; | |
ThemeButtonNameLight = "Hell"; | |
ThemeButtonNameDark = "Dunkel"; | |
// Initialize the Themes-variable | |
var theme; | |
// Funktion, die die Farbänderungen auführt | |
function changeToTheme(backgroundColor, textColor, themeName) { | |
document.body.style.backgroundColor = backgroundColor; | |
document.body.style.color = textColor; | |
document.getElementById("themeToggleButton").innerHTML = themeName; | |
} | |
// Die funktion, die beim aufrufen der Website automatisch gestartet wird | |
function initializeTheme() { | |
// Aktuelles Theme abrufen | |
try { | |
theme = localStorage.getItem("theme"); | |
} catch (e) { | |
if (e.name == "NS_ERROR_FILE_CORRUPTED") { | |
localStorage.clear(); | |
theme = localStorage.getItem("theme"); | |
} | |
} | |
//Theme auf gespeichertes Theme setzen | |
if (theme == "light") { | |
// Theme ändern | |
changeToTheme(ThemeColorBackLight, ThemeColorTextLight, ThemeButtonNameLight); | |
} else { | |
// Theme ändern | |
changeToTheme(ThemeColorBackDark, ThemeColorTextDark, ThemeButtonNameDark); | |
} | |
} | |
// Funktion einmal zum Start ausführen | |
initializeTheme(); | |
// Funktion, die bei Knopfdruck ausgeführt wird | |
function toggleTheme(theme) { | |
// Theme basierend auf Aktuellem theme ändern | |
if (theme == "dark") { | |
// Theme ändern | |
changeToTheme(ThemeColorBackLight, ThemeColorTextLight, ThemeButtonNameLight); | |
// Theme-Speicher auf "Hell" setzen | |
localStorage.setItem("theme", "light"); | |
} else { | |
// Theme ändern | |
changeToTheme(ThemeColorBackDark, ThemeColorTextDark, ThemeButtonNameDark); | |
// Theme-Speicher auf "Dunkel" setzen | |
localStorage.setItem("theme", "dark"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Theme switch */ | |
#themeToggleButton { | |
color: var(--font-color); | |
background: var(--color-primary); | |
padding: 10px 20px; | |
border-radius: 5px; | |
} | |
#themeButton { | |
position: fixed; | |
top: 10px; | |
right: 10px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment