-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
57 lines (48 loc) · 1.65 KB
/
app.js
File metadata and controls
57 lines (48 loc) · 1.65 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
function app() {
return {
noteHeading: '',
noteText: '',
notes: [],
loadNotes() {
const storedNotes = localStorage.getItem('notes');
if (storedNotes) {
this.notes = JSON.parse(storedNotes);
}
},
addNote() {
if (this.noteText.trim() !== '') {
const currentYear = new Date().getFullYear().toString().slice(-2);
const timestamp = currentYear + new Date().toLocaleString('en-US', { timeZone: 'Europe/Berlin', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' }).replace(/[^0-9]/g, '');
const note = {
id: uuidv4().substring(0, 8),
heading: this.noteHeading,
text: this.noteText,
timestamp: timestamp
};
this.notes.push(note);
this.noteText = '';
this.noteHeading = '';
this.saveNotes();
}
},
updateNoteText(note) {
this.saveNotes();
},
deleteNote(noteId) {
this.notes = this.notes.filter(note => note.id !== noteId);
this.saveNotes();
},
deleteAllNotes() {
this.notes = [];
this.saveNotes();
},
saveNotes() {
localStorage.setItem('notes', JSON.stringify(this.notes));
},
copyNotes() {
const notesCopy = JSON.stringify(this.notes);
navigator.clipboard.writeText(notesCopy);
alert('Notes copied to clipboard!');
},
};
}