mirror of
https://github.com/andwati/pwnforfunandprofit.xyz.git
synced 2026-11-18 23:55:12 +00:00
31 lines
1.0 KiB
JavaScript
31 lines
1.0 KiB
JavaScript
document.addEventListener('DOMContentLoaded', () => {
|
|
const themeToggleBtn = document.getElementById('theme-toggle');
|
|
const htmlElement = document.documentElement;
|
|
|
|
// Check local storage for theme preference
|
|
const currentTheme = localStorage.getItem('theme');
|
|
if (currentTheme) {
|
|
if (currentTheme === 'light') {
|
|
htmlElement.classList.remove('dark');
|
|
}
|
|
} else {
|
|
// Fallback to system preference
|
|
const prefersDarkScheme = window.matchMedia('(prefers-color-scheme: dark)');
|
|
if (!prefersDarkScheme.matches) {
|
|
htmlElement.classList.remove('dark');
|
|
}
|
|
}
|
|
|
|
// Toggle theme on click
|
|
if (themeToggleBtn) {
|
|
themeToggleBtn.addEventListener('click', () => {
|
|
htmlElement.classList.toggle('dark');
|
|
let theme = 'light';
|
|
if (htmlElement.classList.contains('dark')) {
|
|
theme = 'dark';
|
|
}
|
|
localStorage.setItem('theme', theme);
|
|
});
|
|
}
|
|
});
|