-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.js
36 lines (28 loc) · 1002 Bytes
/
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
/**
* Store the values for each input in localStorage
*/
function saveOptions() {
var inputs = document.getElementsByTagName('input');
var status = document.getElementById("status");
for (var i = 0; i < inputs.length; i++) {
var key = inputs[i].id;
var value = inputs[i].value;
localStorage[key] = value;
status.innerHTML = "Options Saved!";
setTimeout(function() {
status.innerHTML = "";
}, 750);
}
}
/**
*Restore the options saved in localStorage or use the data-default value if none is available
*/
function restoreOptions() {
var inputs = document.getElementsByTagName('input');
for (var i = 0; i < inputs.length; i++) {
var key = inputs[i].id;
inputs[i].value = ( ! localStorage[key] ? inputs[i].dataset.default : localStorage[key]);
}
}
document.addEventListener('DOMContentLoaded', restoreOptions);
document.querySelector('#save').addEventListener('click', saveOptions);