-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup.js
36 lines (31 loc) · 1.19 KB
/
signup.js
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
30
31
32
33
34
35
36
document.addEventListener('DOMContentLoaded', () => {
initTheme();
const toggleCheckbox = document.getElementById('dark-mode-checkbox');
// Check for saved theme preference
const savedTheme = localStorage.getItem('theme');
if (savedTheme === 'dark') {
document.body.classList.add('dark-mode');
if (toggleCheckbox) toggleCheckbox.checked = true;
}
// Listen for changes
if (toggleCheckbox) {
toggleCheckbox.addEventListener('change', () => {
document.body.classList.toggle('dark-mode');
localStorage.setItem('theme', document.body.classList.contains('dark-mode') ? 'dark' : 'light');
});
}
});
function handleSignup(event) {
event.preventDefault();
const username = document.getElementById('newUsername').value;
const password = document.getElementById('newPassword').value;
const users = JSON.parse(localStorage.getItem('users') || '{}');
if (users[username]) {
alert('Username already exists!');
return;
}
users[username] = password;
localStorage.setItem('users', JSON.stringify(users));
alert('Signup successful!');
window.location.href = 'login.html';
}