-
Notifications
You must be signed in to change notification settings - Fork 0
/
event.js
42 lines (35 loc) · 1.09 KB
/
event.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
// creating context object for contextMenus
var context = {
id:"smiles",
title:"Analyze molecule",
contexts:["selection"]
};
// creating contextMenus object
chrome.contextMenus.create(context);
// smiles variable
var smiles_data = null;
// Receving data from context menu
chrome.contextMenus.onClicked.addListener((info, tab) =>
{
// update smiles_data received from context menu
smiles_data = info.selectionText;
chrome.storage.sync.set({'smi': `${smiles_data}`});
// Adding badge just after clicking the icon on context menu
chrome.storage.onChanged.addListener((change,storageName)=>
{
chrome.browserAction.setBadgeText({text:' '})
chrome.browserAction.setBadgeBackgroundColor({
color:"#228B22"
})
})
})
// communicate with popup.js for handling the badge icon
chrome.runtime.onMessage.addListener((request,sender,sendResponse)=>
{
if (request.method === "changeBadge"){
chrome.browserAction.setBadgeText({text:""})
chrome.browserAction.setBadgeBackgroundColor({
color:"#FF0000"
})
}
})