forked from freakitties/axieExt
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpopup.js
More file actions
75 lines (71 loc) · 2.42 KB
/
popup.js
File metadata and controls
75 lines (71 loc) · 2.42 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const optionsMapping = {
enableOption: ENABLE_OPTION,
minimalOption: MINIMAL_OPTION,
japanCount: JAPAN_COUNT,
showBreedsStats: SHOW_BREEDS_STATS_OPTION,
showAuction: SHOW_AUCTION,
eggParentOption: SHOW_EGG_PARENTS,
usePost: USE_POST,
postAddress: POST_ADDRESS,
fireThreshold: FIRE_THRESHOLD
};
const optionIsValue = {
japanCount: true,
fireThreshold: true,
postAddress: true
}
$(document).ready(function(){
let options = Object.keys(optionsMapping);
console.log("Got options...", optionsMapping);
getOptions(function(response) {
let storedOpts = response;
if (Object.keys(storedOpts).length != options.length) {
storedOpts = resetOptions();
}
for (let opt in optionsMapping) {
//set UI
if (storedOpts[optionsMapping[opt]]) {
$("#" + opt).prop('checked', true);
if (optionIsValue[opt]) {
$("#" + opt).val(storedOpts[optionsMapping[opt]]);
}
} else {
$("#" + opt).prop('checked', false);
}
if (!storedOpts[ENABLE_OPTION] && opt != "enableOption") {
$("#" + opt).prop('disabled', true);
}
//handle future changes
if (opt == "enableOption") {
$("#" + opt).click(function() {
if( $(this).is(':checked') ) {
putOption(optionsMapping[opt], true);
for (let opt in optionsMapping) {
$("#" + opt).prop('disabled', false);
}
} else {
putOption(optionsMapping[opt], false);
for (let opt in optionsMapping) {
$("#" + opt).prop('disabled', true);
}
}
});
} else {
$("#" + opt).click(function() {
if (!optionIsValue[opt]) {
if( $(this).is(':checked') ) {
putOption(optionsMapping[opt], true);
} else {
putOption(optionsMapping[opt], false);
}
}
});
$("#" + opt).change(function() {
if (optionIsValue[opt]) {
putOption(optionsMapping[opt], $(this).val());
}
});
}
}
});
});