aboutsummaryrefslogtreecommitdiffstats
path: root/js/craftmine.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/craftmine.js')
-rw-r--r--js/craftmine.js27
1 files changed, 15 insertions, 12 deletions
diff --git a/js/craftmine.js b/js/craftmine.js
index 4ccdf2f..9aaae5c 100644
--- a/js/craftmine.js
+++ b/js/craftmine.js
@@ -1,4 +1,4 @@
-datas = {
+data = {
gold: 0,
mine: 0,
miners: 0,
@@ -18,31 +18,34 @@ function sendRequest(url, params, callback) {
}
-function updateDatas(t) {
- document.getElementById(t).innerHTML = datas[t];
+function updateData() {
+ for (var i = 0; i < arguments.length; i++) {
+ document.getElementById(arguments[i]).innerHTML = data[arguments[i]];
+ }
}
function withdrawMine() {
- sendRequest("craftmine.php", "op=withdrawMine", function() {
- datas.gold += parseInt(datas.mine);
- datas.mine = 0;
- updateDatas("gold");
- updateDatas("mine");
+ sendRequest("craftmine.php", "op=withdrawMine&amount="+data.mine, function(xhr) {
+ var gold = parseInt(xhr.responseText); // Server's response is a string
+ if(isNaN(gold)) return;
+ data.gold = gold;
+ data.mine = 0;
+ updateData("gold", "mine");
})
}
function initCraftMine() {
sendRequest("craftmine.php", "op=getCraftMine", function(xhr) {
var ret = xhr.responseText;
- datas.gold = parseInt(ret);
- updateDatas("gold");
+ data.gold = parseInt(ret); // Server's response is a string
+ updateData("gold");
})
}
function updateMine() {
- datas.mine += (datas.miners+1);
- updateDatas("mine");
+ data.mine += (data.miners+1);
+ updateData("mine");
}
function init() {