-
Notifications
You must be signed in to change notification settings - Fork 3
/
options.js
44 lines (35 loc) · 1.36 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
function saveOptions() {
var open = $('input:radio[name=open]:checked').val();
localStorage["open"] = open;
var chatAtStartup = $('#chatAtStartup').is(':checked');
localStorage["chatAtStartup"] = chatAtStartup;
var chatAtGamesOpen = $('#chatAtGamesOpen').is(':checked');
localStorage["chatAtGamesOpen"] = chatAtGamesOpen;
$('#status').fadeIn().fadeOut('slow');
}
function restoreOptions() {
var open = getFromStorage("open", "summary");
$('#'+open).prop('checked', 'checked');
var chatAtStartup = getFromStorage("chatAtStartup", "false");
setCheckboxValue("chatAtStartup", chatAtStartup);
var chatAtGamesOpen = getFromStorage("chatAtGamesOpen", "false");
setCheckboxValue("chatAtGamesOpen", chatAtGamesOpen);
}
function getFromStorage(key, defaultValue) {
var value = localStorage[key];
var result = value == null ? defaultValue : value;
console.debug("value taken from local storage: " + key + " = " + result);
return result;
}
function setCheckboxValue(id, checked) {
var e = $("#" + id);
if(checked == "true") { // stupid js!
console.log('checkbox ' + id + ' is checked');
e.prop('checked', true);
} else {
console.log('checkbox ' + id + ' is unchecked');
e.removeAttr('checked');
}
}
document.addEventListener('DOMContentLoaded', restoreOptions);
document.querySelector('#save').addEventListener('click', saveOptions);