-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
35 lines (30 loc) · 1.12 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
function updateIcon(enabled) {
const iconPath = enabled ? "images/icon-48.png" : "images/icon-48-disabled.png";
chrome.action.setIcon({ path: iconPath });
}
function getUserSelectEnabled(callback) {
chrome.storage.sync.get("userSelectEnabled", (data) => {
const enabled = data.userSelectEnabled !== false; // Default to enabled
callback(enabled);
});
}
function handleTabActivation(tabId) {
chrome.tabs.get(tabId, (tab) => {
if (tab && tab.url && tab.url.startsWith("http")) {
getUserSelectEnabled((enabled) => {
updateIcon(enabled);
chrome.tabs.sendMessage(tabId, { userSelectEnabled: enabled }, (response) => {
if (chrome.runtime.lastError) {
console.warn("Message not delivered to tab:", chrome.runtime.lastError.message);
}
});
});
} else {
console.log("Skipped unsupported tab:", tab?.url);
}
});
}
getUserSelectEnabled(updateIcon);
chrome.tabs.onActivated.addListener(({ tabId }) => {
handleTabActivation(tabId);
});