diff options
Diffstat (limited to 'js/colors.js')
| -rw-r--r-- | js/colors.js | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/js/colors.js b/js/colors.js new file mode 100644 index 0000000..158ad52 --- /dev/null +++ b/js/colors.js @@ -0,0 +1,16 @@ +// @license http://www.wtfpl.net/txt/copying/" WTFPL + +if ( localStorage.getItem("color-mode") === "dark" || + ( !localStorage.getItem("color-mode") && window.matchMedia('(prefers-color-scheme: dark)').matches ) +) { + document.documentElement.setAttribute("color-mode", "dark"); +}; + +function toggleColorMode() { + var doc = document.documentElement; + var color = doc.getAttribute("color-mode") == "dark" ? "light" : "dark"; + doc.setAttribute("color-mode", color); + localStorage.setItem("color-mode", color); +}; + +// @license-end |
