-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththeme-toggle.html
More file actions
29 lines (29 loc) · 990 Bytes
/
theme-toggle.html
File metadata and controls
29 lines (29 loc) · 990 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<script>
document.addEventListener('DOMContentLoaded', function() {
// Theme logic only
const input = document.getElementById('theme-toggle');
const icon = document.getElementById('theme-icon');
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
const saved = localStorage.getItem('ailo-theme');
if (saved === 'dark' || (!saved && prefersDark)) {
document.body.classList.add('dark-mode');
input.checked = true;
icon.textContent = '🌚';
} else {
document.body.classList.remove('dark-mode');
input.checked = false;
icon.textContent = '🌞';
}
input.addEventListener('change', function() {
if (input.checked) {
document.body.classList.add('dark-mode');
localStorage.setItem('ailo-theme', 'dark');
icon.textContent = '🌚';
} else {
document.body.classList.remove('dark-mode');
localStorage.setItem('ailo-theme', 'light');
icon.textContent = '🌞';
}
});
});
</script>