-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd-code.js
More file actions
42 lines (34 loc) · 1.22 KB
/
Copy pathadd-code.js
File metadata and controls
42 lines (34 loc) · 1.22 KB
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
37
38
39
40
41
42
document.getElementById("add-form").addEventListener("submit", (e) => {
e.preventDefault();
const nicknameInput = document.getElementById("nickname");
const secretInput = document.getElementById("secret");
const errorDiv = document.getElementById("error-message");
const nickname = nicknameInput.value.trim();
const secret = secretInput.value.trim();
errorDiv.textContent = "";
nicknameInput.style.borderColor = "";
secretInput.style.borderColor = "";
if (!nickname) {
errorDiv.textContent = "Please enter a nickname.";
nicknameInput.style.borderColor = "#ff5555";
return;
}
if (!secret) {
errorDiv.textContent = "Please enter secret code.";
secretInput.style.borderColor = "#ff5555";
return;
}
const secrets = window.api.loadSecrets();
const exists = secrets.some((entry) => entry.nickname === nickname);
if (exists) {
errorDiv.textContent = "Nickname already in use. Please choose another.";
nicknameInput.style.borderColor = "#ff5555";
return;
}
secrets.push({ nickname, secret });
window.api.saveSecrets(secrets);
window.location.href = "index.html";
});
document.getElementById("close-btn").addEventListener("click", () => {
window.api.closeWindow();
});