-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
29 lines (26 loc) · 1.07 KB
/
main.js
File metadata and controls
29 lines (26 loc) · 1.07 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
document.addEventListener('DOMContentLoaded', function () {
const noteTextarea = document.getElementById('noteTextarea');
const downloadBtn = document.getElementById('downloadBtn');
const deleteBtn = document.getElementById('deleteBtn');
downloadBtn.addEventListener('click', function () {
const noteContent = noteTextarea.value;
if (noteContent.trim() !== '') {
const blob = new Blob([noteContent], { type: 'text/plain' });
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'note.txt';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
alert('Note downloaded!');
} else {
alert('Note is empty. Fill the note before downloading.');
}
});
deleteBtn.addEventListener('click', function () {
noteTextarea.value = '';
alert('Note deleted!');
});
});