-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
218 lines (187 loc) · 8.41 KB
/
script.js
File metadata and controls
218 lines (187 loc) · 8.41 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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
document.addEventListener('DOMContentLoaded', function () {
const addButton = document.getElementById('addButton');
const colors = document.querySelector('.colors ul');
const colorOptions = colors.querySelectorAll('li');
let selectedColor = '';
const darkModeSwitch = document.getElementById('darkModeSwitch');
const darkModeIcon = darkModeSwitch.querySelector('.dark-mode-icon');
const brightnessModeIcon = darkModeSwitch.querySelector('.brightness-mode-icon');
// Load mode from localStorage
const darkModeEnabled = JSON.parse(localStorage.getItem('darkModeEnabled'));
if (darkModeEnabled) {
document.body.classList.add('dark-mode');
// document.body.classList.add('dark-gradient');
document.body.classList.add('thiscolor');
darkModeIcon.classList.add('hidden');
brightnessModeIcon.classList.remove('hidden');
}
darkModeSwitch.addEventListener('click', () => {
document.body.classList.toggle('dark-mode');
// document.body.classList.toggle('dark-gradient');
document.body.classList.toggle('thiscolor');
darkModeIcon.classList.toggle('hidden');
brightnessModeIcon.classList.toggle('hidden');
localStorage.setItem('darkModeEnabled', document.body.classList.contains('dark-mode'));
});
addButton.addEventListener('click', () => {
colors.classList.toggle('visible');
});
colorOptions.forEach(option => {
option.addEventListener('click', () => {
selectedColor = option.style.backgroundColor;
colors.classList.remove('visible');
createNote();
});
});
let noteIdCounter = 0;
function createNote(content = 'Click here to edit your note...', color = selectedColor, date = new Date().toLocaleDateString(), isStarred = false, id = null) {
if (!color) return;
const notesContainer = document.getElementById('notesContainer');
const note = document.createElement('div');
note.classList.add('note', 'border', 'w-64', 'flex', 'flex-col', 'align-middle', 'h-48', 'p-2', 'rounded-xl', 'm-2');
note.style.backgroundColor = color;
if (!id) {
id = noteIdCounter++;
}
note.dataset.id = id;
note.innerHTML = `
<div class="star flex align-middle relative p-0 right-1 rounded-full items-center">
<span class="material-symbols-outlined absolute cursor-pointer right-0 pt-5 z-10" style="font-size:x-larger; color: ${isStarred ? 'gold' : 'initial'};">
star
</span>
</div>
<div class="info w-full flex relative overflow-wrap-anywhere whitespace-normal overflow-scroll" contenteditable="true">
${content}
</div>
<div class="contentss flex flex-row relative bottom-0 w-full">
<div class="date p-2 text-xs">
<p>${date}</p>
</div>
<div class="export flex align-middle absolute right-10 cursor-pointer pt-1.5 p-1 rounded-full items-center">
<span class="material-symbols-outlined" style="font-size:large">
ios_share
</span>
</div>
<div class="pencil flex align-middle absolute right-0 bg-white cursor-pointer p-1 rounded-full items-center">
<span class="material-symbols-outlined">
delete
</span>
</div>
</div>
`;
if (isStarred) {
notesContainer.insertBefore(note, notesContainer.firstChild);
} else {
const starredNotes = Array.from(notesContainer.querySelectorAll('.note .star span[style*="gold"]')).map(el => el.closest('.note'));
if (starredNotes.length > 0) {
notesContainer.insertBefore(note, starredNotes[starredNotes.length - 1].nextSibling);
} else {
notesContainer.insertBefore(note, notesContainer.firstChild);
}
}
const infoDiv = note.querySelector('.info');
const deleteIcon = note.querySelector('.pencil span');
const exportIcon = note.querySelector('.export span');
const starIcon = note.querySelector('.star span');
deleteIcon.addEventListener('click', function () {
note.remove();
saveNotes();
});
exportIcon.addEventListener('click', function () {
const notesContent = infoDiv.innerHTML.trim();
downloadAsText(notesContent, date);
});
starIcon.addEventListener('click', function () {
const starredNotes = document.querySelectorAll('.note .star span[style*="gold"]').length;
if (!isStarred && starredNotes >= 5) {
alert('You can only star up to 5 notes.');
return;
}
isStarred = !isStarred;
starIcon.style.color = isStarred ? 'gold' : 'initial';
note.remove();
if (isStarred) {
notesContainer.insertBefore(note, notesContainer.firstChild);
} else {
const starredNotes = Array.from(notesContainer.querySelectorAll('.note .star span[style*="gold"]')).map(el => el.closest('.note'));
if (starredNotes.length > 0) {
notesContainer.insertBefore(note, starredNotes[starredNotes.length - 1].nextSibling);
} else {
notesContainer.insertBefore(note, notesContainer.firstChild);
}
}
saveNotes();
});
infoDiv.addEventListener('focus', function () {
if (this.textContent.trim() === 'Click here to edit your note...') {
this.textContent = '';
}
});
infoDiv.addEventListener('blur', function () {
if (this.textContent.trim() === '') {
this.textContent = 'Click here to edit your note...';
}
saveNotes();
});
infoDiv.addEventListener('input', function () {
saveNotes();
});
saveNotes();
}
function saveNotes() {
const notes = [];
document.querySelectorAll('.note').forEach(note => {
const content = note.querySelector('.info').innerHTML.trim();
const color = note.style.backgroundColor;
const date = note.querySelector('.date p').textContent;
const isStarred = note.querySelector('.star span').style.color === 'yellow';
const id = note.dataset.id;
notes.push({ content, color, date, isStarred, id });
});
localStorage.setItem('notes', JSON.stringify(notes));
}
function loadNotes() {
const notes = JSON.parse(localStorage.getItem('notes')) || [];
notes.sort((a, b) => {
if (a.isStarred && !b.isStarred) return -1;
if (!a.isStarred && b.isStarred) return 1;
return b.id - a.id; // Newest first
});
notes.forEach(note => {
createNote(note.content, note.color, note.date, note.isStarred, note.id);
});
}
function downloadAsText(content, date) {
const blob = new Blob([content], { type: 'text/plain' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `note_${date}.txt`;
a.click();
URL.revokeObjectURL(url);
}
// Dynamic text for the heading
const texts = [
"Welcome to NoteFlow!",
"Hello and Welcome to Your Notes!",
"Glad to Have You at NoteFlow!",
"Hey There, Note Taker!",
"Hello, Ready to Jot Down Some Ideas?",
"Hi! Thanks for Choosing NotesApp!",
"Hello! Ready to Capture Your Thoughts?",
"Welcome! What Will You Note Today?",
"Hi! Need to Organize Your Ideas? Let's Get Started!",
"Join Our Note-Taking Community!",
"Capture and Organize with NotesApp!",
"Hello! Let's Turn Ideas into Notes!",
"Your Ideas, Perfectly Organized!",
"Capture Every Thought with NotesApp!",
"Unlock Your Creativity with NotesApp!"
];
function getRandomText(arr) {
return arr[Math.floor(Math.random() * arr.length)];
}
document.getElementById('dynamicText').innerText = getRandomText(texts);
// Load notes from localStorage on page load
loadNotes();
});