-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
76 lines (68 loc) · 2.8 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
72
73
74
75
76
window.onload = (event) => {
load_settings().then(settings => {
let form = document.forms.options;
let cohort_id_range_input = document.getElementById("cohort_id_range");
let cohort_id_update_interval_input = document.getElementById("cohort_id_update_interval");
let cohort_id_update_interval_type_input = form.elements.cohort_id_update_interval_type;
let cohort_id_update_interval_type_style = document.getElementById("cohort_id_update_interval_type")
let cohort_version_input = document.getElementById("cohort_version");
let form_submit = document.getElementById("form_submit");
function save_settings(event) {
event.preventDefault();
settings = {
cohort_id_range: cohort_id_range_input.value,
cohort_id_update_interval: cohort_id_update_interval_input.value,
cohort_id_update_interval_type: cohort_id_update_interval_type_input.value,
cohort_version: cohort_version_input.value
};
browser.storage.local.set(settings);
input_show_updated();
}
function display_settings(settings) {
cohort_id_range_input.value = settings.cohort_id_range;
cohort_id_update_interval_input.value = settings.cohort_id_update_interval;
cohort_id_update_interval_type_input.value = settings.cohort_id_update_interval_type;
cohort_version_input.value = settings.cohort_version;
}
function input_show_updated() {
let changed = false;
if (settings.cohort_id_range != cohort_id_range_input.value) {
changed = true;
cohort_id_range_input.style.color = 'orange';
} else {
cohort_id_range_input.style.color = '';
}
if (settings.cohort_id_update_interval != cohort_id_update_interval_input.value) {
changed = true;
cohort_id_update_interval_input.style.color = 'orange';
} else {
cohort_id_update_interval_input.style.color = '';
}
if (settings.cohort_id_update_interval_type != cohort_id_update_interval_type_input.value) {
changed = true;
cohort_id_update_interval_type_style.style.color = "orange";
} else {
cohort_id_update_interval_type_style.style.color = "";
}
if (settings.cohort_version != cohort_version_input.value) {
changed = true;
cohort_version_input.style.color = 'orange';
} else {
cohort_version_input.style.color = '';
}
if (changed) {
form_submit.style.color = 'orange';
} else {
form_submit.style.color = '';
}
}
display_settings(settings);
form.addEventListener("submit", save_settings);
form.addEventListener("change", input_show_updated);
form.addEventListener("reset", (event) => {
event.preventDefault();
display_settings(DEFAULT_SETTINGS);
input_show_updated();
});
});
}