Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matsuyoshi30/harbor.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'assets/js/theme.js')
-rw-r--r--assets/js/theme.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/assets/js/theme.js b/assets/js/theme.js
new file mode 100644
index 0000000..3bd7466
--- /dev/null
+++ b/assets/js/theme.js
@@ -0,0 +1,29 @@
+window.onload = function () {
+ var toggle = document.getElementById('dark-mode-toggle')
+ var darkTheme = document.getElementById('dark-mode-theme')
+
+ if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
+ setTheme(localStorage.getItem('dark-mode-storage') || 'dark')
+ } else {
+ setTheme(localStorage.getItem('dark-mode-storage') || 'light')
+ }
+
+ toggle.addEventListener('click', () => {
+ if (toggle.className === 'fas fa-moon') {
+ setTheme('dark')
+ } else if (toggle.className === 'fas fa-sun') {
+ setTheme('light')
+ }
+ })
+
+ function setTheme(mode) {
+ localStorage.setItem('dark-mode-storage', mode)
+ if (mode === 'dark') {
+ darkTheme.disabled = false
+ toggle.className = 'fas fa-sun'
+ } else if (mode === 'light') {
+ darkTheme.disabled = true
+ toggle.className = 'fas fa-moon'
+ }
+ }
+}