add dark mode synchronization script and update image source conditions

This commit is contained in:
Eduardo Silva
2026-03-17 20:08:02 -03:00
parent 25ed71ce57
commit 0bd4136b5f
7 changed files with 28 additions and 3 deletions

View File

@@ -0,0 +1,21 @@
<script>
(function () {
function setCookie(name, value, days) {
var d = new Date();
d.setTime(d.getTime() + days * 24 * 60 * 60 * 1000);
document.cookie = name + '=' + value + ';path=/;expires=' + d.toUTCString();
}
function getCookie(name) {
var m = document.cookie.match(new RegExp('(?:^|; )' + name + '=([^;]*)'));
return m ? m[1] : null;
}
var userPref = getCookie('darkMode');
var isDark;
if (userPref) {
isDark = userPref === 'dark';
} else {
isDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
}
setCookie('darkModeActive', isDark ? '1' : '0', 365);
})();
</script>