-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathoptions.js
74 lines (56 loc) · 1.87 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
// Saves options to localStorage.
function save_options() {
var select = document.getElementById("output1");
var output1 = select.children[select.selectedIndex].value;
localStorage["output_choice1"] = output1;
var select = document.getElementById("output2");
var output2 = select.children[select.selectedIndex].value;
localStorage["output_choice2"] = output2;
// Update status to let user know options were saved.
var status = document.getElementById("status");
status.innerHTML = "Options Saved.";
setTimeout(function() {
status.innerHTML = "";
}, 750);
}
function save_options2() {
var text = document.getElementById("emailadded");
var emailadd = text.value;
localStorage["output_emailadd"] = emailadd;
// Update status to let user know options were saved.
var status = document.getElementById("status2");
status.innerHTML = "Options Saved.";
setTimeout(function() {
status.innerHTML = "";
}, 750);
}
// Restores select box state to saved value from localStorage.
function restore_options() {
var favorite1 = localStorage["output_choice1"];
if (!favorite1) {
return;
}
var select = document.getElementById("output1");
for (var i = 0; i < select.children.length; i++) {
var child = select.children[i];
if (child.value == favorite1) {
child.selected = "true";
break;
}
}
var favorite2 = localStorage["output_choice2"];
if (!favorite2) {
return;
}
var select = document.getElementById("output2");
for (var i = 0; i < select.children.length; i++) {
var child = select.children[i];
if (child.value == favorite2) {
child.selected = "true";
break;
}
}
}
document.addEventListener('DOMContentLoaded', restore_options);
document.querySelector('#save').addEventListener('click', save_options);
document.querySelector('#save2').addEventListener('click', save_options2);