-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
executable file
·64 lines (52 loc) · 1.65 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
// Saves options to localStorage.
function save_options() {
/*
var select = document.getElementById("color");
var color = select.children[select.selectedIndex].value;
localStorage["favorite_color"] = color;
*/
localStorage["enable_popup"] = $('#enable_popup').is(':checked');
//alert($('#enable_popup').is(':checked'));
// Update status to let user know options were saved.
var status = document.getElementById("status");
status.innerHTML = "options saved";
setTimeout(function() {
status.innerHTML = "";
}, 750);
update_debug();
}
// Restores select box state to saved value from localStorage.
function restore_options() {
var favorite = localStorage["favorite_color"];
if (favorite) {
var select = document.getElementById("color");
for (var i = 0; i < select.children.length; i++) {
var child = select.children[i];
if (child.value == favorite) {
child.selected = "true";
break;
}
}
}
if (localStorage["enable_popup"] == 'true') {
$('#enable_popup').attr('checked', 'on');
}
update_debug();
}
function update_debug() {/*
for (var i = 0; i < localStorage.length; i++){
$('#debug').append('<dt>' + localStorage.key(i) + '</dt><dd>' + localStorage.getItem(localStorage.key(i)) + '</dd>');
}
*/}
function updateTTX() {
var ttx = Math.round((new Date(new Date().getFullYear(), 12-1, 25) - new Date()) / (1000 * 60 * 60 * 24) + 0.5);
//document.querySelector('#ttx').innerHTML = ttx;
$('#ttx').append(ttx);
}
$(document).ready(function() {
restore_options();
updateTTX();
});
document.addEventListener('DOMContentLoaded', function() {
document.querySelector('input[type=button]').addEventListener('click', save_options);
});