This repository has been archived by the owner on Aug 21, 2023. It is now read-only.
/
popup.js
63 lines (53 loc) · 1.49 KB
/
popup.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
var isDark;
function save(setDark) {
chrome.storage.local.set({ isDark: setDark });
isDark = setDark;
}
function darkTheme(theme) {
if (theme) {
isDark = false;
chrome.tabs.insertCSS(null, { file: "dark-theme.css", allFrames:false, runAt:"document_start" });
}
else {
isDark = true;
chrome.tabs.insertCSS(null, { file: "light-theme.css", allFrames:false, runAt:"document_start" });
}
save(theme);
}
function load() {
chrome.storage.local.get(function(result) {
if (result.isDark == null) {
save(false);
try {
document.getElementById("themeSwitch").checked = false;
} catch (TypeError) {}
isDark = false;
}
else {
try {
document.getElementById("themeSwitch").checked = result.isDark;
} catch (TypeError) {}
isDark = result.isDark;
darkTheme(isDark);
}
});
}
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if (tab.url.startsWith("https://mavicpilots.com")) {
load();
}
});
if (document.querySelector(".popup")) {
load();
const button = document.querySelector(".button");
button.addEventListener("click", () => {
if (document.getElementById("themeSwitch").checked) {
darkTheme(true);
isDark = true;
}
else {
darkTheme(false);
isDark = false;
}
})
}