-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
43 lines (40 loc) · 1.69 KB
/
popup.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
// Save the note when the "save-button" is clicked
document.getElementById('save-button').addEventListener('click', function () {
const saveButton = document.getElementById('save-button');
saveButton.disabled = true;
const textarea = document.getElementById('note-textarea');
const text = textarea.value;
chrome.storage.sync.set({ 'savedNote': text }, () => {
console.log('Text saved to storage');
});
});
// Enable the "save-button" when the "note-textarea" is modified
document.getElementById('note-textarea').addEventListener('input', () => {
const saveButton = document.getElementById('save-button');
saveButton.disabled = false;
});
// "Copy to clipboard" feature
document.getElementById('copy-button').addEventListener('click', () => {
chrome.storage.sync.get(['savedNote'], (result) => {
const text = result.savedNote;
navigator.clipboard.writeText(text)
.then(() => {
console.log('Text copied to clipboard!');
const copyToClipboardButton = document.getElementById('copy-button');
copyToClipboardButton.innerHTML = 'Copied!';
copyToClipboardButton.disabled = true;
setTimeout(() => {
copyToClipboardButton.innerHTML = 'Copy to clipboard';
copyToClipboardButton.disabled = false;
}, 2000);
})
.catch(err => {
console.error('Failed to copy text: ', err);
});
});
});
// Load the saved note
chrome.storage.sync.get(['savedNote'], (result) => {
const textarea = document.getElementById('note-textarea');
textarea.value = result.savedNote || '';
});