-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
98 lines (86 loc) · 3.35 KB
/
Copy pathscript.js
File metadata and controls
98 lines (86 loc) · 3.35 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
document.addEventListener('DOMContentLoaded', function() {
const notesList = document.getElementById('notesList');
const newNote = document.getElementById('newNote');
const saveNote = document.getElementById('saveNote');
// Load existing notes
chrome.storage.sync.get(['notes'], function(result) {
const notes = result.notes || [];
notes.forEach(function(note) {
addNoteToList(note);
});
});
// Save new note
function saveNewNote() {
const noteText = newNote.value.trim();
if (noteText) {
chrome.storage.sync.get(['notes'], function(result) {
const notes = result.notes || [];
notes.unshift(noteText); // Add new note to the beginning
chrome.storage.sync.set({notes: notes}, function() {
addNoteToList(noteText, true);
newNote.value = '';
});
});
}
}
saveNote.addEventListener('click', saveNewNote);
newNote.addEventListener('keydown', function(event) {
if (event.key === 'Enter' && !event.shiftKey) {
event.preventDefault();
saveNewNote();
}
});
// Function to add a note to the list
function addNoteToList(noteText, isNew = false) {
const noteElement = document.createElement('div');
noteElement.className = 'note';
const noteContent = document.createElement('span');
noteContent.textContent = noteText;
const deleteButton = document.createElement('button');
deleteButton.className = 'delete-button';
deleteButton.innerHTML = '×';
deleteButton.addEventListener('click', function(event) {
event.stopPropagation();
chrome.storage.sync.get(['notes'], function(result) {
let notes = result.notes || [];
notes = notes.filter(note => note !== noteText);
chrome.storage.sync.set({notes: notes}, function() {
noteElement.remove();
});
});
});
noteElement.appendChild(noteContent);
noteElement.appendChild(deleteButton);
noteElement.addEventListener('click', function() {
navigator.clipboard.writeText(noteText).then(function() {
noteElement.style.backgroundColor = '#1f6feb';
setTimeout(function() {
noteElement.style.backgroundColor = '';
}, 200);
}).catch(function(err) {
console.error('Could not copy text: ', err);
});
});
if (isNew) {
noteElement.style.opacity = '0';
noteElement.style.transform = 'translateY(-20px)';
}
if (isNew) {
notesList.insertBefore(noteElement, notesList.firstChild);
setTimeout(() => {
noteElement.style.opacity = '1';
noteElement.style.transform = 'translateY(0)';
}, 10);
} else {
notesList.appendChild(noteElement);
}
}
// Add transition styles for new notes
const style = document.createElement('style');
style.textContent = `
.note {
transition: opacity 0.3s ease, transform 0.3s ease, background-color 0.2s ease;
}
`;
document.head.appendChild(style);
});