feat: dynamically lock dark reader

This commit is contained in:
JovannMC 2025-02-13 23:57:35 +03:00
parent be2a248db0
commit 8437a9857d
No known key found for this signature in database
2 changed files with 17 additions and 0 deletions

View File

@ -44,6 +44,13 @@
console.log(`Applying theme: ${theme}`);
document.documentElement.classList.add(theme);
// Lock dark reader if it's set to dark mode
if (theme === "dark") {
const lock = document.createElement('meta');
lock.name = 'darkreader-lock';
document.head.appendChild(lock);
}
})();
</script>
</head>

View File

@ -215,6 +215,16 @@ export function setTheme(themeTo: "light" | "dark") {
});
log(["theme"], `set to ${themeTo}`);
theme.set(themeTo);
// Lock dark reader if it's set to dark mode
if (themeTo === "dark") {
const lock = document.createElement('meta');
lock.name = 'darkreader-lock';
document.head.appendChild(lock);
} else {
const lock = document.querySelector('meta[name="darkreader-lock"]');
if (lock) lock.remove();
}
}
export function setEffects(effectsEnabled: boolean) {