mirror of
https://github.com/eduardogsilva/wireguard_webadmin.git
synced 2026-03-22 00:16:18 +00:00
add dark mode synchronization script and update image source conditions
This commit is contained in:
@@ -136,9 +136,11 @@
|
||||
if ($('body').hasClass('dark-mode')) {
|
||||
$('body').removeClass('dark-mode');
|
||||
setCookie('darkMode', 'light', 365);
|
||||
setCookie('darkModeActive', '0', 365);
|
||||
} else {
|
||||
$('body').addClass('dark-mode');
|
||||
setCookie('darkMode', 'dark', 365);
|
||||
setCookie('darkModeActive', '1', 365);
|
||||
}
|
||||
syncDarkModeUI();
|
||||
});
|
||||
|
||||
21
templates/template_parts/dark_mode_active_sync.html
Normal file
21
templates/template_parts/dark_mode_active_sync.html
Normal 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>
|
||||
Reference in New Issue
Block a user