diff options
author | Gwyneth Morgan <gwymor@tilde.club> | 2021-09-27 07:47:44 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-27 15:47:44 +0100 |
commit | 4e0cca3f7d9dd227df161e3548cc374c169d3dc6 (patch) | |
tree | a21ca6ae0f8ecab4de9f805771f3b7e453e73b2c /web_src/js | |
parent | 868e937a5354d4d8d9fd754fc80be26a5f345ba6 (diff) | |
download | gitea-4e0cca3f7d9dd227df161e3548cc374c169d3dc6.tar.gz gitea-4e0cca3f7d9dd227df161e3548cc374c169d3dc6.zip |
Use light/dark theme based on system preference (#17051)
Add a new default theme `auto`, which will automatically switch between
`gitea` (light) and `arc-green` (dark) themes depending on the user's
operating system settings.
Closes: #8183
Diffstat (limited to 'web_src/js')
-rw-r--r-- | web_src/js/utils.js | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/web_src/js/utils.js b/web_src/js/utils.js index 58d0d6b39e..b555650bc5 100644 --- a/web_src/js/utils.js +++ b/web_src/js/utils.js @@ -26,7 +26,13 @@ export function isObject(obj) { // returns whether a dark theme is enabled export function isDarkTheme() { - return document.documentElement.classList.contains('theme-arc-green'); + if (document.documentElement.classList.contains('theme-auto')) { + return window.matchMedia('(prefers-color-scheme: dark)').matches; + } + if (document.documentElement.classList.contains('theme-arc-green')) { + return true; + } + return false; } // removes duplicate elements in an array |