-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
36 lines (33 loc) · 1.15 KB
/
Copy pathbackground.js
File metadata and controls
36 lines (33 loc) · 1.15 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
chrome.action.onClicked.addListener(async (tab) => { ///runs when you click the extension's icon in the Chrome toolbar
const [{ result: isDark }] = await chrome.scripting.executeScript({
target: { tabId: tab.id },
func: () => !!document.getElementById('dark-mode-style') //converts the value to a boolean(true if it exists and false if not)
});
if (isDark) {
await chrome.scripting.executeScript({
target: { tabId: tab.id },
func: () => {
const styleEl = document.getElementById('dark-mode-style');
if (styleEl) styleEl.remove();
}
});
} else {
await chrome.scripting.executeScript({ ///runs a small function inside the current webpage
target: { tabId: tab.id },
func: () => {
const styleEl = document.createElement('style');
styleEl.id = 'dark-mode-style';
styleEl.textContent = `
html {
filter: invert(99%) hue-rotate(180deg);
background-color: #fefefe;
}
img, video, iframe {
filter: invert(99%) hue-rotate(180deg);
}
`;
document.head.appendChild(styleEl);
}
});
}
});