-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbackground.js
More file actions
36 lines (35 loc) · 1.17 KB
/
background.js
File metadata and controls
36 lines (35 loc) · 1.17 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
chrome.commands.onCommand.addListener((command) => {
if (command === "process-page-command") {
console.log("Command received: process-page-command");
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
if (tabs.length > 0 && tabs[0].id) {
const tabId = tabs[0].id;
chrome.storage.sync.get(["showAnswers"], (result) => {
let showAnswers = true;
if (typeof result.showAnswers === "boolean") {
showAnswers = result.showAnswers;
}
chrome.tabs.sendMessage(
tabId,
{ action: "processPage", showAnswers: showAnswers },
(response) => {
if (chrome.runtime.lastError) {
console.error(
"Background Error: Could not send message to tab.",
chrome.runtime.lastError.message,
);
} else {
console.log(
"Background: Message sent to tab, response:",
response,
);
}
},
);
});
} else {
console.warn("Background: No active tab found.");
}
});
}
});