Skip to content

Commit

Permalink
馃敡Fixed #23 & improved checking for setting theme
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaismma committed Nov 1, 2020
1 parent 942236f commit c14c3de
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
36 changes: 26 additions & 10 deletions Source/cubfan135/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,39 @@ <h1>DRAG A FILE HERE</h1>
</div>

<script>
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
darken('dark', false);
}

// Set Theme If Exists
if (localStorage.getItem("theme")) {
if (localStorage.getItem("theme") == "dark") {
if (localStorage.getItem("HTCC-theme")) {
if (localStorage.getItem("HTCC-theme") === "dark") {
darken();
} else {
darken('light');
}
} else {
// Set Theme To Default
localStorage.setItem("theme", "light");
// Set Theme To Current theme
document.classList.contains('dark') ? darken() : darken('light')
}

function darken() {
document.body.classList.toggle('dark')
// Check Theme and Save in Local Storage
if (document.body.classList.contains("dark")) {
localStorage.setItem("theme", "dark")
function darken(state = "dark", setLocalStorage = true) {
if (state === 'dark') {
if (!document.body.classList.contains('dark')) {
document.body.classList.toggle('dark')
}
} else {
localStorage.setItem("theme", "light")
if (document.body.classList.contains('dark')) {
document.body.classList.toggle('dark')
}
}
// Check Theme and Save in Local Storage
if (setLocalStorage) {
if (document.body.classList.contains("dark")) {
localStorage.setItem("HTCC-theme", "dark")
} else {
localStorage.setItem("HTCC-theme", "light")
}
}
}
</script>
Expand Down
2 changes: 1 addition & 1 deletion Source/cubfan135/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,6 @@ document.onkeydown = (e) => {
oldTime = newTime;

keyCheat.push(e.key.toLowerCase())
keyCheat.join('') === "invert" ? (darken(), keyCheat = []) : null
keyCheat.join('') === "invert" ? (darken(document.body.classList.contains("dark") ? "light" : "dark"), keyCheat = []) : null
}
}

0 comments on commit c14c3de

Please sign in to comment.