forked from diwash007/PDF-Dark-Mode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworker.js
37 lines (31 loc) · 1.04 KB
/
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
31
32
33
34
35
36
37
/*
* This script is always running in background and don't have access to the curent tab
* so it's a listener. It triggers event with sendMessage and executeScript
*/
// set status to active initially
chrome.storage.sync.get("active", ({ active }) => {
if (typeof active === "undefined") chrome.storage.sync.set({ active: true });
});
// set strength to max initially
chrome.storage.sync.get("strength", ({ strength }) => {
if (!strength) chrome.storage.sync.set({ strength: 255 });
});
// set contrast to max initially
chrome.storage.sync.get("contrast", ({ contrast }) => {
if (!contrast) chrome.storage.sync.set({ contrast: 100 });
});
// tab update listener
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (!changeInfo.status === "complete") {
return;
}
const extension = tab.url.slice(-4);
if (tab.url && (extension === ".pdf" || extension === ".PDF")) {
if (tabId)
chrome.scripting.executeScript({
target: { tabId: tabId },
files: ["scripts/invert.js"],
});
}
return;
});