-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
54 lines (51 loc) · 1.45 KB
/
background.js
File metadata and controls
54 lines (51 loc) · 1.45 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
chrome.runtime.onInstalled.addListener((details) => {
if (details.reason === "install") {
chrome.runtime.openOptionsPage();
}
chrome.contextMenus.create({
id: "notey-ao-add",
title: "Add to NoteyAO",
contexts: ["selection"]
});
});
chrome.contextMenus.onClicked.addListener((info, tab) => {
if (info.menuItemId === "notey-ao-add") {
const note = {
content: info.selectionText,
url: tab.url,
title: tab.title,
timestamp: new Date().getTime(),
};
chrome.storage.local.get({ notes: [] }, (result) => {
const notes = result.notes;
notes.push(note);
chrome.storage.local.set({ notes: notes }, () => {
if (chrome.runtime.lastError) {
console.error("Error saving note:", chrome.runtime.lastError);
chrome.notifications.create({
type: "basic",
iconUrl: "images/icon48.svg",
title: "Error",
message: "Failed to save note."
});
} else {
console.log("Note saved successfully.");
chrome.notifications.create({
type: "basic",
iconUrl: "images/icon48.svg",
title: "Note Saved!",
message: "Your note has been saved locally."
});
}
});
});
}
});
chrome.action.onClicked.addListener((tab) => {
chrome.windows.create({
url: chrome.runtime.getURL("dashboard.html"),
type: "popup",
width: 800,
height: 600
});
});