-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackground.js
More file actions
26 lines (24 loc) · 753 Bytes
/
background.js
File metadata and controls
26 lines (24 loc) · 753 Bytes
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
function createContextMenu() {
chrome.contextMenus.removeAll(() => {
chrome.contextMenus.create({
id: "addAnnotation",
title: "Create new annotation",
contexts: ["selection"]
});
});
};
chrome.runtime.onInstalled.addListener(createContextMenu);
chrome.runtime.onStartup.addListener(createContextMenu);
chrome.contextMenus.onClicked.addListener((info, tab) => {
if (info.menuItemId === "addAnnotation" && info.selectionText && info.selectionText.trim().length > 0) {
chrome.scripting.executeScript({
target: { tabId: tab.id },
files: ['content.js']
}, () => {
chrome.tabs.sendMessage(tab.id, {
action: "addAnnotation",
selectedText: info.selectionText
});
});
}
});