generated from trim21/webpack-userscript-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add OS-independent dark-mode setting (#47)
* Add OS-independent dark-mode setting
- Loading branch information
1 parent
a8b99b9
commit 24a54da
Showing
7 changed files
with
113 additions
and
24 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import {OptionKey, stringOptions} from "../settings/general"; | ||
import {Theme} from "../dataTypes"; | ||
|
||
export function setTheme() { | ||
|
||
const osSetting = window.matchMedia("(prefers-color-scheme: dark)"); | ||
|
||
function toggleDarkMode(state: boolean | undefined) { | ||
document.documentElement.classList.toggle("stashChecker-dark-mode", state); | ||
} | ||
|
||
switch (stringOptions.get(OptionKey.theme)) { | ||
case Theme.Light: | ||
toggleDarkMode(false) | ||
break; | ||
case Theme.Dark: | ||
toggleDarkMode(true) | ||
break; | ||
case Theme.Device: | ||
default: | ||
toggleDarkMode(osSetting.matches); | ||
break; | ||
} | ||
} |
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