-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathoptions.js
More file actions
61 lines (54 loc) · 1.48 KB
/
options.js
File metadata and controls
61 lines (54 loc) · 1.48 KB
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
window.onload = function(){
function init(){
chrome.storage.sync.get(whvutil.getEmptyContext(), function(context){
for(var name in context){
var input = document.getElementById(name);
if(input.getAttribute('data-type') === 'date'){
var d = new Date(context[name]);
if(isNaN(d.getTime())){
input.value = '';
}else{
input.value = [d.getFullYear(), d.getMonth() + 1, d.getDate()].join('/');
}
}else{
input.value = context[name];
}
}
});
}
window.saveContext = function(){
var context = whvutil.getContext();
for(var name in context){
var input = document.getElementById(name);
var v = input.value;
if(input.getAttribute('data-type') === 'date'){
var d = new Date(v);
if(isNaN(d.getTime())){
context[name] = '';
}else{
context[name] = [d.getFullYear(), d.getMonth() + 1, d.getDate()].join('/');
}
}else{
context[name] = v || '';
}
}
chrome.storage.sync.set(context, function(){
init();
alert('saved');
});
};
window.showSample = function(){
chrome.storage.sync.set(whvutil.getContext(), function(){
init();
});
};
window.clearContext = function(){
chrome.storage.sync.set(whvutil.getEmptyContext(), function(){
init();
});
};
document.getElementById('savebtn').addEventListener('click', saveContext);
document.getElementById('clearbtn').addEventListener('click', clearContext);
document.getElementById('samplebtn').addEventListener('click', showSample);
init();
};