-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
150 lines (114 loc) · 3.89 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
let titleText = document.getElementById('noteTitle');
let noteText = document.getElementById('noteText');
let savebtn = document.getElementById('save');
let notes = JSON.parse(localStorage.getItem('notes')) || []
window.addEventListener('load', () => {
displayNotes();
});
function displayNotes(){
const noteList = document.getElementById('noteList')
noteList.innerHTML = ''
for(let i=0; i<notes.length; i++){
const note = notes[i];
const noteItem = document.createElement('li')
noteItem.className = 'note-item';
const noteTitle = document.createElement('h2')
noteTitle.className = 'note-title';
const noteText = document.createElement('p')
const deleteBtn = document.createElement('button');
deleteBtn.className = 'delete-btn';
noteTitle.innerHTML = note.title;
noteText.innerHTML = note.text;
deleteBtn.innerHTML = 'Delete';
noteItem.appendChild(noteTitle);
noteItem.appendChild(noteText);
noteItem.appendChild(deleteBtn);
noteList.appendChild(noteItem);
deleteBtn.addEventListener('click', () => {
deleteNote(i); // Call deleteNote() with the index of the note
});
}
}
function deleteNote(index) {
notes.splice(index, 1); // Remove the note from the notes array
localStorage.setItem('notes', JSON.stringify(notes)); // Update the notes in local storage
displayNotes(); // Refresh the displayed notes
}
savebtn.addEventListener("click", ()=>{
let title = titleText.value.trim();
let text = noteText.value.trim();
if(titleText.value !== '' && noteText.value !== ''){
const note = {
title: title,
text: text
}
notes.push(note);
localStorage.setItem('notes', JSON.stringify(notes))
titleText.value = ''
noteText.value = ''
displayNotes();
}
})
let notebtn = document.getElementById('display');
notebtn.addEventListener("click", ()=>{
let x = document.getElementById("displayNotes")
// x.style.display = "block"
if(x.style.display === "none"){
x.style.display = "block"
} else {
x.style.display = "none"
}
})
document.getElementById("clearbtn").addEventListener("click", ()=>{
titleText.value = '';
noteText.value = '';
})
document.getElementById('clearNotes').addEventListener("click", () => {
localStorage.removeItem('notes');
notes = [];
displayNotes();
})
const nameInput = document.getElementById('nameInput');
nameInput.addEventListener('input', () => {
const editedName = nameInput.innerText;
localStorage.setItem('name', editedName);
});
// Check if the name exists in localStorage and update the displayed name
const savedName = localStorage.getItem('name');
if (savedName) {
nameInput.innerText = savedName;
}
const imageContainer = document.getElementById('imageContainer');
const image = document.getElementById('image');
const imageUrls = [
'image1.jpeg',
'image2.jpeg',
'image3.jpeg',
'image4.jpeg',
'image5.jpeg',
// Add more image URLs as needed
];
let currentIndex = 0;
// Check if there's a saved image index in localStorage
if (localStorage.getItem('currentIndex')) {
currentIndex = parseInt(localStorage.getItem('currentIndex'));
image.src = imageUrls[currentIndex];
} else {
image.src = imageUrls[currentIndex];
}
imageContainer.addEventListener('click', (event) => {
if (event.target === image) {
currentIndex = (currentIndex + 1) % imageUrls.length;
const nextImageUrl = imageUrls[currentIndex];
image.src = nextImageUrl;
// Save the current index in localStorage
localStorage.setItem('currentIndex', currentIndex.toString());
}
});
window.addEventListener('load', () => {
// Check if there's a saved image index in localStorage
if (localStorage.getItem('currentIndex')) {
currentIndex = parseInt(localStorage.getItem('currentIndex'));
image.src = imageUrls[currentIndex];
}
})