-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsettings.js
75 lines (65 loc) · 2.02 KB
/
settings.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
var localSettings = [];
function getSetting(name) {
return localStorage.getItem(name);
}
function setSetting(name, value) {
console.log("Setting => " + name + "=" + value);
localStorage.setItem(name, value);
}
function settingExists(setting) {
/* IE11 doesn't support maps, so I think we need to do a linear time iteration of the entire array: */
for (var i = 0; i < localSettings.length; i++) {
var s = localSettings[i];
if (s.setting === setting) {
return true;
}
}
return false;
}
function getDefaultSetting(setting) {
/* IE11 doesn't support maps, so I think we need to do a linear time iteration of the entire array: */
for (var i = 0; i < localSettings.length; i++) {
var s = localSettings[i];
if (s.setting === setting) {
return s.defaultSetting;
}
}
console.error("No such setting: " + setting);
}
function getBoolSetting(name) {
var s = getSetting(name);
if (s === undefined || s == null) {
return getDefaultSetting(name);
}
return s === "true";
}
function setBoolSetting(name, value) {
setSetting(name, (value ? "true" : "false"));
}
function getArraySetting(name) {
var s = getSetting(name);
if (s === undefined || s == null) {
return [];
}
return JSON.parse(s);
}
function setArraySetting(name, value) {
var s = JSON.stringify(value);
setSetting(name, s);
}
function registerSetting(labelText, labelID, setting, defaultSetting) {
if (settingExists(setting)) {
console.error("Setting " + setting + " is already registered!");
return;
}
localSettings.push({
setting: setting,
labelText: labelText,
labelID: labelID,
defaultSetting: defaultSetting
});
}
/* Settings require page reload are marked with a '*' */
registerSetting("Display labels in top menu, not icons*", 'force-labels', 'forcelabels', false);
registerSetting("Automark read when deleting/junking a message", 'automark-seen', 'automarkseen', true);
registerSetting("Autoreconnect upon server/network disconnect", 'autoreconnect', 'autoreconnect', false);