Skip to content

Commit f63b78b

Browse files
committed
toggle fix
1 parent 937cb80 commit f63b78b

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

_includes/scripts.html

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
11
<script type="module" src="{{ base_path }}/assets/js/_main.js"></script>
2-
2+
<script>
3+
document.addEventListener('DOMContentLoaded', function () {
4+
const toggleBtn = document.getElementById('theme-toggle');
5+
const themeIcon = document.getElementById('theme-icon');
6+
const themes = ['default', 'dark', 'cyberpunk'];
7+
let current = localStorage.getItem('theme') || 'default';
8+
9+
const setTheme = (theme) => {
10+
document.documentElement.setAttribute('data-theme', theme);
11+
localStorage.setItem('theme', theme);
12+
themeIcon.className = 'fa-solid ' + (theme === 'dark' ? 'fa-moon' : theme === 'cyberpunk' ? 'fa-vial' : 'fa-sun');
13+
};
14+
15+
setTheme(current);
16+
17+
toggleBtn.addEventListener('click', () => {
18+
let index = (themes.indexOf(current) + 1) % themes.length;
19+
current = themes[index];
20+
setTheme(current);
21+
});
22+
});
23+
</script>
324
{% include analytics.html %}

0 commit comments

Comments
 (0)