mirror of
https://github.com/AngelJumbo/gruvbox-wallpapers.git
synced 2026-10-20 16:16:18 +00:00
fix detection of prefers colors
This commit is contained in:
@@ -36,7 +36,6 @@ function activeSection(section) {
|
|||||||
function hideAll() {
|
function hideAll() {
|
||||||
document.querySelectorAll(".section").forEach((s) => {
|
document.querySelectorAll(".section").forEach((s) => {
|
||||||
s.classList.remove("selected");
|
s.classList.remove("selected");
|
||||||
// s.style.display = "none";
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const HIDDEN_CLASS = "hidden";
|
const HIDDEN_CLASS = "hidden";
|
||||||
@@ -50,26 +49,12 @@ function hideThemeSwitcher(currentTheme) {
|
|||||||
document.getElementById("dark-icon")?.classList.remove(HIDDEN_CLASS);
|
document.getElementById("dark-icon")?.classList.remove(HIDDEN_CLASS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function getCurrentTheme() {
|
|
||||||
const fromProperty = document.documentElement.style.getPropertyValue("color-scheme");
|
|
||||||
if (fromProperty) return fromProperty;
|
|
||||||
const prefersTheme = window.matchMedia("(prefers-color-scheme: dark)") ? "dark" : "light";
|
|
||||||
return prefersTheme;
|
|
||||||
}
|
|
||||||
|
|
||||||
function setTheme(newTheme) {
|
function setTheme(newTheme) {
|
||||||
document.documentElement.style.setProperty("color-scheme", newTheme);
|
document.documentElement.style.setProperty("color-scheme", newTheme);
|
||||||
hideThemeSwitcher(newTheme);
|
hideThemeSwitcher(newTheme);
|
||||||
}
|
}
|
||||||
|
|
||||||
function switchTheme() {
|
function switchTheme() {
|
||||||
let currentTheme = getCurrentTheme();
|
setTheme(document.documentElement.style.getPropertyValue("color-scheme")=="dark"?"light":"dark");
|
||||||
console.debug("Start theme switching to " + currentTheme + " theme");
|
|
||||||
setTheme(currentTheme == "dark" ? "light" : "dark");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function initColorTheme() {
|
|
||||||
const currentTheme = getCurrentTheme();
|
|
||||||
console.debug("Current theme is " + currentTheme + "");
|
|
||||||
setTheme(currentTheme);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -113,14 +113,18 @@ done
|
|||||||
echo "</main>" >> ./index.html
|
echo "</main>" >> ./index.html
|
||||||
echo "<script>
|
echo "<script>
|
||||||
window.onload = () => {" >> ./index.html
|
window.onload = () => {" >> ./index.html
|
||||||
echo "hideAll();" >> ./index.html
|
#echo "hideAll();" >> ./index.html
|
||||||
echo "initColorTheme();" >> ./index.html
|
|
||||||
for section in "${sections[@]}"; do
|
for section in "${sections[@]}"; do
|
||||||
echo " loadPage('$section', 1);" >> ./index.html
|
echo " loadPage('$section', 1);" >> ./index.html
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "
|
echo "
|
||||||
activeSection('${sections[0]}');
|
activeSection('${sections[0]}');
|
||||||
|
if (window.matchMedia('(prefers-color-scheme: dark)').matches){
|
||||||
|
setTheme('dark');
|
||||||
|
}else{
|
||||||
|
setTheme('light');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>" >> ./index.html
|
</script>" >> ./index.html
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user