-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
39 lines (35 loc) · 1.32 KB
/
background.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
chrome.commands.onCommand.addListener(function(command) {
if (command === 'save-note') {
chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, { action: 'getSelection' }, function(response) {
if (response && response.selection) {
var noteContent = response.selection.trim();
if (noteContent) {
chrome.storage.local.get(['notes'], function(result) {
var notes = result.notes || [];
var note = {
title: 'Quick Note',
content: noteContent,
tags: [],
timestamp: new Date().getTime()
};
var existingNoteIndex = notes.findIndex(function(existingNote) {
return existingNote.title === note.title;
});
if (existingNoteIndex !== -1) {
// Update the existing note
notes[existingNoteIndex] = note;
} else {
// Add a new note
notes.push(note);
}
chrome.storage.local.set({ notes: notes }, function() {
// Optional: You can show a success message or provide feedback to the user here.
});
});
}
}
});
});
}
});