-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
42 lines (40 loc) · 1.02 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
40
41
42
chrome.runtime.onInstalled.addListener(() => {
chrome.contextMenus.create({
id: "addHighlight",
title: "Highlight",
contexts: ["selection"],
});
});
chrome.contextMenus.onClicked.addListener((item, tab) => {
const text = item.selectionText;
if (item.menuItemId === "addHighlight") {
chrome.tabs.sendMessage(tab.id, {
type: "ADD_HIGHLIGHT",
text,
});
}
// else if (item.menuItemId === "addNote") {
// chrome.tabs.sendMessage(tab.id, {
// type: "ADD_NOTE",
// text,
// });
// }
});
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (tab.url) {
chrome.tabs.sendMessage(
tabId,
{
type: "NEW",
webUrl: tab.url,
tabId,
},
function (response) {
//On response alert the response
console.log(
"The response from the content script: " + response.response
); //You have to choose which part of the response you want to display ie. response.response
}
);
}
});