-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathscript.js
119 lines (107 loc) · 4.36 KB
/
script.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
document.getElementById('add-task-btn').addEventListener('click', function() {
const taskInput = document.getElementById('task-input');
const taskList = document.getElementById('task-list');
if (taskInput.value.trim() !== "") {
const newTask =document.createElement('li');
newTask.innerHTML = `
<span>${taskInput.value}</span>
<button class="editbtn">Edit</button>
<button class="deletebtn">Delete</button>
`;
deletebtn(newTask);
editbtn(newTask);
// newTask.textContent = taskInput.value; not needed now
taskList.appendChild(newTask);
taskInput.value = '';
}
});
document.getElementById('save-note-btn').addEventListener('click', function() {
const noteInput = document.getElementById('note-input');
const noteList = document.getElementById('note-list');
if (noteInput.value.trim() !== "") {
const newNote =document.createElement('li');
newNote.innerHTML = `
<span>${noteInput.value}</span>
<button class="editbtn">Edit</button>
<button class="deletebtn">Delete</button>
`;
deletebtn(newNote);
editbtn(newNote);
// newNote.textContent = noteInput.value; not needed now
noteList.appendChild(newNote);
noteInput.value = '';
}
});
document.getElementById('add-goal-btn').addEventListener('click', function() {
const goalInput = document.getElementById('goal-input');
const goalList = document.getElementById('goal-list');
if (goalInput.value.trim() !== "") {
const newGoal =document.createElement('li');
newGoal.innerHTML = `
<span>${goalInput.value}</span>
<button class="editbtn">Edit</button>
<button class="deletebtn">Delete</button>
`;
deletebtn(newGoal);
editbtn(newGoal);
// newGoal.textContent = goalInput.value; not needed now
goalList.appendChild(newGoal);
goalInput.value = '';
}
});
document.getElementById('add-password-btn').addEventListener('click', function() {
const websiteInput = document.getElementById('website-input');
const usernameInput = document.getElementById('username-input');
const passwordInput = document.getElementById('password-input');
const passwordList = document.getElementById('password-list');
if (websiteInput.value.trim() !== "" && usernameInput.value.trim() !== "" && passwordInput.value.trim() !== "") {
const newPasswordItem = document.createElement('li');
newPasswordItem.textContent = `Website: ${websiteInput.value}, Username: ${usernameInput.value}, Password: ${passwordInput.value}`;
passwordList.appendChild(newPasswordItem);
websiteInput.value = '';
usernameInput.value = '';
passwordInput.value = '';
}
});
// You can later add functionality for fetching weather from an API, etc.
// delete button functionality
function deletebtn(element) {
const deleteBtn =element.querySelector('.deletebtn');
deleteBtn.addEventListener('click', function () {
if (confirm("Are you sure you want to delete this item?")) {
element.remove();
}
});
}
// edit button functionality
function editbtn(element) {
const editBtn =element.querySelector('.editbtn');
editBtn.addEventListener('click', function () {
const textSpan =element.querySelector('span:nth-child(2)') || element.querySelector('span');
const editedText =prompt("Edit your item:", textSpan.textContent);
if (editedText !==null&&editedText.trim() !== "") {
textSpan.textContent =editedText;
}
});
}
const passwordInput = document.getElementById('password-input');
const togglePasswordVisibilityIcon = document.querySelector('[data-toggle-password]');
togglePasswordVisibilityIcon.addEventListener('click', function () {
if (passwordInput.type === 'password') {
passwordInput.type = 'text';
togglePasswordVisibilityIcon.classList.remove('fa-eye');
togglePasswordVisibilityIcon.classList.add('fa-eye-slash');
} else {
passwordInput.type = 'password';
togglePasswordVisibilityIcon.classList.remove('fa-eye-slash');
togglePasswordVisibilityIcon.classList.add('fa-eye');
}
});
darkBtn.onclick=function(){
document.body.classList.toggle('darkTheme');
if (document.body.classList.contains('darkTheme')) {
darkBtn.textContent = 'Light Mode';
} else {
darkBtn.textContent = 'Dark Mode';
}
}