forked from penge/my-notes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.js
64 lines (55 loc) · 1.62 KB
/
options.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
/* global document, chrome */
import { renderCommonFonts } from "./options/render.js";
renderCommonFonts();
import { attachEvents } from "./options/events.js";
attachEvents();
/* State */
import {
setFont,
setSize,
setTheme,
setNewtab,
setTab,
setSync,
setChange,
setVersion,
} from "./options/state.js";
chrome.storage.local.get(["font", "size", "theme", "customTheme", "newtab", "tab", "sync"], local => {
const { font, size, theme, customTheme, newtab, tab, sync } = local;
setFont(font);
setSize(size);
setTheme(theme, customTheme);
setNewtab(newtab);
setTab(tab);
setSync(sync);
});
// Apply the changes in other Options pages to keep them in sync
chrome.storage.onChanged.addListener((changes, areaName) => {
if (areaName === "local") {
setChange(changes["font"], setFont);
setChange(changes["size"], setSize);
setChange(changes["theme"], (theme) => {
if (theme === "light" || theme === "dark") {
setTheme(theme);
} else {
chrome.storage.local.get(["customTheme"], local => {
setTheme("custom", local.customTheme);
});
}
});
setChange(changes["customTheme"], (customTheme) => {
if (document.body.id === "custom") {
setTheme("custom", customTheme);
}
});
setChange(changes["newtab"], setNewtab);
setChange(changes["tab"], setTab);
setChange(changes["sync"], setSync);
}
});
chrome.runtime.getPlatformInfo((platformInfo) => {
const os = platformInfo.os === "mac" ? "mac" : "other";
document.body.classList.add(`os-${os}`);
});
const version = chrome.runtime.getManifest().version;
setVersion(version);