fga/js/bootstrap-auto-dark-mode.js
2024-12-31 07:47:20 +01:00

18 lines
No EOL
609 B
JavaScript

/**
* Author and copyright: Stefan Haack (https://shaack.com)
* Repository: https://github.com/shaack/bootstrap-auto-dark-mode
* License: MIT, see file 'LICENSE'
*/
(function () {
const htmlElement = document.querySelector("html")
if (htmlElement.getAttribute("data-bs-theme") === 'auto') {
function updateTheme() {
document.querySelector("html").setAttribute("data-bs-theme",
window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light")
}
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', updateTheme)
updateTheme()
}
})()