-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathoptions.js
More file actions
75 lines (65 loc) · 2.42 KB
/
options.js
File metadata and controls
75 lines (65 loc) · 2.42 KB
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
function saveOptions(e)
{
var v = document.querySelector("#local_zone_str_checkbox").checked;
var r = document.querySelector('input[name="time_format"]:checked');
var tv = r ? r.value : "browser";
var f1 = document.querySelector("#feature_annotations_checkbox").checked;
var f2 = document.querySelector("#feature_tooltips_checkbox").checked;
var settings = {
"local_zone_str_enabled": v,
"time_format": tv,
"feature_annotations": f1,
"feature_tooltips": f2
};
console.log("Saving Settings: "+JSON.stringify(settings));
browser.storage.local.set({settings}).then(savedOption);
}
function savedOption()
{
console.log("Settings Saved.");
}
function updatePage(settings)
{
document.querySelector("#local_zone_str_checkbox").checked = settings.local_zone_str_enabled;
document.querySelector("#feature_annotations_checkbox").checked = settings.feature_annotations;
document.querySelector("#feature_tooltips_checkbox").checked = settings.feature_tooltips;
var node = document.querySelector('#time_format_'+settings.time_format);
if (node)
{
node.checked = true;
}
else
{
console.log("time_format setting not recognised: "+settings.time_format);
}
}
function onError(error)
{
console.log("Error Loading Setting: "+error);
}
function restoreOptions()
{
var localZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
document.querySelector("#local_zone_str").innerText = localZone;
var currentdate = new Date();
var h = currentdate.getHours();
var m = currentdate.getMinutes();
document.getElementById("time_format_hhmm24h_example").innerText = hhmm24h(h,m);
if (toLocaleTimeStringSupportsLocales()==false)
{
document.getElementById("time_format_browser").disabled = true;
document.getElementById("time_format_browser_example").innerText = "unavailable";
}
else
{
document.getElementById("time_format_browser_example").innerText = browserLocalizedTime(h,m);
}
browser.storage.local.get('settings')
.then(gotOptions)
.then(updatePage);
}
document.addEventListener('DOMContentLoaded', restoreOptions);
document.querySelectorAll('input[type=checkbox]')
.forEach(checkbox => checkbox.addEventListener('change', saveOptions));
document.querySelectorAll('input[type=radio]')
.forEach(radio => radio.addEventListener('change', saveOptions));