-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
71 lines (69 loc) · 1.87 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
65
66
67
68
69
70
71
// Saves options to chrome.storage
function save_options() {
let savedClass = document.getElementById("inputClass").value;
chrome.storage.sync.set(
{
savedClass: savedClass
},
function() {
// Update status to let user know options were saved.
let status = document.getElementById("status");
status.textContent = "Options saved.";
setTimeout(function() {
status.textContent = "";
}, 750);
}
);
}
function save_dark_mode(mode) {
chrome.storage.sync.set(
{
darkMode: mode
},
function() {
// Update status to let user know options were saved.
let status = document.getElementById("status");
status.textContent = "Options saved.";
setTimeout(function() {
status.textContent = "";
}, 750);
}
);
}
$("#nightModeToggle").mouseup(e => {
if ($("body").css("background-color") === "rgb(0, 0, 0)") {
$("body").css("background-color", "rgb(245, 245, 245)");
$("body").css("color", "black");
save_dark_mode(false);
} else {
$("body").css("background-color", "black");
$("body").css("color", "rgb(245, 245, 245)");
save_dark_mode(true);
}
});
// Restores select box and checkbox state using the preferences
// stored in chrome.storage.
function restore_options() {
chrome.storage.sync.get(
{
darkMode: false
},
function(items) {
if (items.darkMode) {
$("#nightModeCheckbox").attr("checked", "");
$("body").css("background-color", "black");
$("body").css("color", "rgb(245, 245, 245)");
}
}
);
chrome.storage.sync.get(
{
savedClass: "TE17E"
},
function(items) {
document.getElementById("inputClass").value = items.savedClass;
}
);
}
document.addEventListener("DOMContentLoaded", restore_options);
document.getElementById("save").addEventListener("click", save_options);