-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
32 lines (29 loc) · 1.02 KB
/
background.js
File metadata and controls
32 lines (29 loc) · 1.02 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
// Added Event Listeners for Content.js and popup.js using onMessage() and onConnect() Listeners
var selectedText;
var database = null;
let databaseName = "dictionaryDb";
let fstore = "dictionaryTable";
//event listener from popup js
chrome.runtime.onConnect.addListener(function (port) {
port.onMessage.addListener(async function (message) {
if (message == "Request Modified Value") {
port.postMessage(selectedText);
} else if (message.method == "searchWord") {
var param = {
method: "wordMeaning",
data: "infos",
};
//send data back to popup js
port.postMessage(param);
}
});
});
//on extension install listener
chrome.runtime.onInstalled.addListener(async function (details) {
if (details.reason == "install") {
//call a function to handle a first install
console.log("install for first time");
} else if (details.reason == "update") {
//call a function to handle an update
}
});