@@ -0,0 +1,64 @@
|
||||
function togglePassword() {
|
||||
const passwordInput = document.getElementById('password');
|
||||
const toggleBtn = document.querySelector('.password-toggle');
|
||||
|
||||
if (passwordInput.type === 'password') {
|
||||
passwordInput.type = 'text';
|
||||
toggleBtn.textContent = '👀';
|
||||
} else {
|
||||
passwordInput.type = 'password';
|
||||
toggleBtn.textContent = '🙈';
|
||||
}
|
||||
}
|
||||
|
||||
function setTheme(theme) {
|
||||
const isLight = theme === 'light';
|
||||
const isDark = theme === 'dark';
|
||||
|
||||
if (isDark) {
|
||||
document.body.classList.remove('light-mode');
|
||||
} else if (isLight) {
|
||||
document.body.classList.add('light-mode');
|
||||
} else {
|
||||
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||
if (prefersDark) {
|
||||
document.body.classList.remove('light-mode');
|
||||
} else {
|
||||
document.body.classList.add('light-mode');
|
||||
}
|
||||
}
|
||||
|
||||
localStorage.setItem('theme', theme);
|
||||
updateSegmentedControl(theme);
|
||||
}
|
||||
|
||||
function updateSegmentedControl(activeTheme) {
|
||||
const dots = document.querySelectorAll('.theme-dot');
|
||||
dots.forEach(dot => {
|
||||
if (dot.dataset.value === activeTheme) {
|
||||
dot.classList.add('active');
|
||||
} else {
|
||||
dot.classList.remove('active');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Update indicator position on window resize
|
||||
window.addEventListener('resize', function() {
|
||||
updateSegmentedControl(localStorage.getItem('theme') || 'dark');
|
||||
});
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const savedTheme = localStorage.getItem('theme') || 'dark';
|
||||
setTheme(savedTheme);
|
||||
|
||||
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', function(e) {
|
||||
if (localStorage.getItem('theme') === 'system') {
|
||||
if (e.matches) {
|
||||
document.body.classList.remove('light-mode');
|
||||
} else {
|
||||
document.body.classList.add('light-mode');
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user