-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbackground.js
61 lines (58 loc) · 1.46 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const fields = {
name: "Nikhil",
phone: "1234567890",
email: "nikhil@gmail.com",
location: "Overland Park,KS",
};
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
console.log(message);
if (message.action === "fetchToken") {
chrome.storage.local.get("token", (data) => {
const token = data.token;
if (token) {
sendResponse(token);
} else {
sendResponse(null);
}
});
}
if (message.action === "AddToken") {
chrome.storage.local.set({ token: message.token }, () => {
console.log("Token is set");
});
}
if (message.action === "closeTab") {
chrome.tabs.remove(sender.tab.id);
}
if (message.action === "newTab") {
chrome.tabs.create({
url: message.url,
active: true,
});
}
if (message.action === "getTabUrl") {
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
sendResponse(tabs[0].url);
});
}
return true;
});
chrome.runtime.onMessageExternal.addListener(
(message, sender, sendResponse) => {
if (message.action === "AddToken") {
chrome.storage.local.set({ token: message.token }, () => {
console.log("Token is set");
});
}
if (message.action === "fetchToken") {
chrome.storage.local.get("token", (data) => {
const token = data.token;
if (token) {
sendResponse(token);
} else {
sendResponse(null);
}
});
}
}
);