-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpopup.js
106 lines (93 loc) · 3.66 KB
/
popup.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
function save() {
chrome.storage.local.set({"global_enable": (document.getElementById("global").checked) ? true : false}, function(){
console.log("test");
});
chrome.storage.local.set({"should_tax": (document.getElementById("tax").checked) ? true : false}, function(){
console.log("test");
});
chrome.storage.local.set({"should_budget": (document.getElementById("budget").checked) ? true : false}, function(){
console.log("test");
});
chrome.storage.local.set({"should_card": (document.getElementById("card").checked) ? true : false}, function(){
console.log("test");
});
chrome.storage.local.set({"should_hours": (document.getElementById("hours").checked) ? true : false}, function(){
console.log("test");
});
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.update(tabs[0].id, {url: tabs[0].url});
});
}
function global() {
console.log("test");
document.getElementById("tax").disabled = !document.getElementById("global").checked;
document.getElementById("budget").disabled = !document.getElementById("global").checked;
document.getElementById("card").disabled = !document.getElementById("global").checked;
document.getElementById("hours").disabled = !document.getElementById("global").checked;
}
function load() {
console.log("test");
$("#save-alert").hide();
chrome.storage.local.get(['global_enable'], function(result) {
if(result.global_enable == null){
chrome.storage.local.set({"global_enable": true}, function(){
document.getElementById("global").checked = true;
global();
});
}
else{
document.getElementById("global").checked = result.global_enable;
global();
}
});
chrome.storage.local.get(['should_tax'], function(result) {
if(result.should_tax == null){
chrome.storage.local.set({"should_tax": true}, function(){
document.getElementById("tax").checked = true;
});
}
else{
document.getElementById("tax").checked = result.should_tax;
}
});
chrome.storage.local.get(['should_budget'], function(result) {
if(result.should_budget == null){
chrome.storage.local.set({"should_budget": true}, function(){
document.getElementById("budget").checked = true;
});
}
else{
document.getElementById("budget").checked = result.should_budget;
}
});
chrome.storage.local.get(['should_card'], function(result) {
if(result.should_card == null){
chrome.storage.local.set({"should_card": true}, function(){
document.getElementById("card").checked = true;
});
}
else{
document.getElementById("card").checked = result.should_card;
}
});
chrome.storage.local.get(['should_hours'], function(result) {
if(result.should_hours == null){
chrome.storage.local.set({"should_hours": true}, function(){
document.getElementById("hours").checked = true;
});
}
else{
document.getElementById("hours").checked = result.should_hours;
}
});
global();
document.getElementById("save").addEventListener('click', function() {
console.log("Test");
save();
$("#save-alert").fadeIn().delay(1200).fadeOut();
});
document.getElementById("global").addEventListener('click', function() {
global();
});
}
document.addEventListener("DOMContentLoaded", function(){ load(); }, false);