-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.ts
33 lines (29 loc) · 839 Bytes
/
index.ts
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
const BASE_URL = import.meta.env.VITE_BASE_URL;
chrome.runtime.setUninstallURL(BASE_URL + "/uninstall");
chrome.runtime.onMessageExternal.addListener(
(message, sender, sendResponse) => {
if (!isExternalMessage(message)) return;
if (message.action === "store-token") {
chrome.storage.local.set({ token: message.token });
return;
}
if (message.action === "delete-token") {
chrome.storage.local.remove("token");
return;
}
}
);
type ExternalMessage =
| {
action: "store-token";
token: string;
}
| {
action: "delete-token";
};
function isExternalMessage(message: any): message is ExternalMessage {
if (typeof message !== "object" || message === null) return false;
return (
message?.action === "store-token" || message?.action === "delete-token"
);
}