mirror of
https://github.com/hyzendust/hyzendust.github.io.git
synced 2026-04-16 21:58:33 +02:00
36 lines
1003 B
HTML
36 lines
1003 B
HTML
<script>
|
|
(function () {
|
|
var btn = document.getElementById('theme-toggle');
|
|
if (!btn) return;
|
|
|
|
function getTheme() {
|
|
var stored = localStorage.getItem('theme');
|
|
if (stored) return stored;
|
|
return window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark';
|
|
}
|
|
|
|
function applyTheme(theme) {
|
|
document.documentElement.setAttribute('data-theme', theme);
|
|
localStorage.setItem('theme', theme);
|
|
}
|
|
|
|
applyTheme(getTheme());
|
|
|
|
btn.addEventListener('click', function () {
|
|
var current = document.documentElement.getAttribute('data-theme') || getTheme();
|
|
applyTheme(current === 'dark' ? 'light' : 'dark');
|
|
});
|
|
})();
|
|
</script>
|
|
<script>
|
|
(function () {
|
|
var check = document.getElementById('mobile-menu-check');
|
|
if (!check) return;
|
|
document.addEventListener('click', function (e) {
|
|
if (!check.checked) return;
|
|
var menu = check.closest('.brand__mobile-menu');
|
|
if (menu && !menu.contains(e.target)) check.checked = false;
|
|
});
|
|
})();
|
|
</script>
|