-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
executable file
·127 lines (105 loc) · 3.27 KB
/
app.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
const themes = {
"dark": {
colors: {
accentcolor: "#424242",
textcolor: "#8f8f8f",
frame: "#424242",
tab_background_separator: "#424242",
toolbar: "#363636",
tab_background_text: "#8f8f8f",
tab_line: "transparent",
tab_loading: "#424242",
toolbar_top_separator: "#333333",
toolbar_vertical_separator: "#474747",
toolbar_bottom_separator: "#333333",
toolbar_field: "#363636",
toolbar_field_text: "#8f8f8f",
toolbar_field_border: "#333333",
toolbar_field_separator: "#474747",
toolbar_field_focus: "#363636",
toolbar_field_text_focus: "#8f8f8f",
toolbar_field_border_focus: "rgba(255, 255, 255, .07)",
button_background_active: "rgba(255, 255, 255, .07)",
button_background_hover: "rgba(255, 255, 255, .07)",
icons_attention: "#a98e5c",
ntp_background: "#363636",
ntp_text: "#8f8f8f",
popup: "#363636",
popup_text: "#8f8f8f",
popup_border: "#333333",
popup_highlight: "rgba(255, 255, 255, .07)",
popup_highlight_text: "#8f8f8f",
sidebar: "#363636",
sidebar_text: "#8f8f8f",
sidebar_border: "#333333",
sidebar_highlight: "rgba(255, 255, 255, .07)",
sidebar_highlight_text: "#8f8f8f",
}
},
"light": {
colors: {
accentcolor: "#e6e8e3",
textcolor: "#8e8e8c",
frame: "#e6e8e3",
tab_background_separator: "#e6e8e3",
toolbar: "#fcfbf9",
tab_background_text: "#8e8e8c",
tab_line: "transparent",
tab_text: "#545351",
tab_loading: "#e6e8e3",
toolbar_top_separator: "#e6e8e3",
toolbar_vertical_separator: "#e6e8e3",
toolbar_bottom_separator: "#e6e8e3",
toolbar_field: "#fcfbf9",
toolbar_field_text: "#8e8e8c",
toolbar_field_border: "#fcfbf9",
toolbar_field_separator: "#e6e8e3",
toolbar_field_focus: "#fcfbf9",
toolbar_field_text_focus: "#8e8e8c",
toolbar_field_border_focus: "rgba(30, 32, 28, .08)",
button_background_active: "rgba(30, 32, 28, .08)",
button_background_hover: "rgba(30, 32, 28, .08)",
ntp_background: "#fcfbf9",
ntp_text: "#545351",
popup: "#fcfbf9",
popup_text: "#545351",
popup_border: "#e6e8e3",
popup_highlight: "rgba(30, 32, 28, .08)",
popup_highlight_text: "#545351",
sidebar: "#fcfbf9",
sidebar_text: "#545351",
sidebar_border: "#e6e8e3",
sidebar_highlight: "rgba(30, 32, 28, .08)",
sidebar_highlight_text: "#545351",
}
}
};
let currentTheme;
function updateTheme(theme) {
if (!theme) {
theme = "dark";
}
currentTheme = theme;
browser.storage.local.set({"theme": theme});
browser.theme.update(themes[theme]);
browser.browserAction.setIcon({
path: "icons/" + theme + "-mode.svg"
});
browser.browserAction.setTitle({
title: theme == "dark" ? 'Enable light theme ☀️' : 'Enable dark theme 🌑',
});
}
function toggleTheme() {
if (currentTheme === "dark") {
updateTheme("light");
} else {
updateTheme("dark");
}
}
browser.browserAction.onClicked.addListener(toggleTheme);
const setting = browser.storage.local.get();
setting.then(onGot);
function onGot(setting) {
setting.theme ? updateTheme(setting.theme) : updateTheme()
}
storedSettings.then(onGot);