-
Notifications
You must be signed in to change notification settings - Fork 0
/
service-worker.js
30 lines (27 loc) · 996 Bytes
/
service-worker.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
function changeIcon() {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
if (tabs[0].url.includes("leetcode.com/problems/")) {
chrome.action.setIcon({ path: "img/icon128.png" });
} else {
chrome.action.setIcon({ path: "img/inactive.png" });
}
});
}
chrome.action.disable();
chrome.runtime.onInstalled.addListener(() => {
chrome.declarativeContent.onPageChanged.removeRules(() => {
chrome.declarativeContent.onPageChanged.addRules([
{
conditions: chrome.runtime.getManifest().host_permissions.map((h) => {
const [, sub, host] = h.match(/:\/\/(\*\.)?([^/]+)/);
return new chrome.declarativeContent.PageStateMatcher({
pageUrl: sub ? { hostSuffix: "." + host } : { hostEquals: host },
});
}),
actions: [new chrome.declarativeContent.ShowAction()],
},
]);
});
});
chrome.tabs.onActivated.addListener(changeIcon);
chrome.tabs.onUpdated.addListener(changeIcon);