-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackgroundScript.js
More file actions
53 lines (47 loc) · 1.49 KB
/
backgroundScript.js
File metadata and controls
53 lines (47 loc) · 1.49 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Listen for messages from the content script and popup
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.type === 'getApiKey') {
// Retrieve the API key from the Chrome storage
chrome.storage.sync.get('apiKey', (data) => {
const apiKey = data.apiKey;
sendResponse(apiKey);
});
// Return true to indicate that the response will be sent asynchronously
return true;
}
if (message.type === 'getBearerToken') {
// Retrieve the bearer token from the Chrome storage
chrome.storage.sync.get('bearerToken', (data) => {
const bearerToken = data.bearerToken;
sendResponse(bearerToken);
});
return true;
}
if (message.type === 'setApiKey') {
// Store the API key in Chrome storage
const apiKey = message.apiKey;
chrome.storage.sync.set({ apiKey }, () => {
sendResponse(true);
});
return true;
}
if (message.type === 'setBearerToken') {
// Store the bearer token in Chrome storage
const bearerToken = message.bearerToken;
chrome.storage.sync.set({ bearerToken }, () => {
sendResponse(true);
});
return true;
}
if (message.type === 'promptApiKey') {
// Open the extension's popup for API key input
chrome.runtime.openOptionsPage();
}
if (message.type === 'promptBearerToken') {
// Open the extension's popup for API key input
chrome.runtime.openOptionsPage();
}
chrome.storage.sync.remove('bearerToken', () => {
sendResponse(true);
});
});