This repository has been archived by the owner on May 18, 2021. It is now read-only.
/
main.js
84 lines (65 loc) · 1.7 KB
/
main.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
function getMonthBack(d) {
return new Date(d.getTime() - 30 * 24 * 60 * 60 * 1000);
}
function login(id,pin) {
getBalance(id,pin);
var date = new Date();
var dd = date.getDate();
var mm = date.getMonth() + 1; //January is 0!
var yyyy = date.getFullYear();
endTime = Date.parse(mm+"/"+dd+"/"+yyyy);
var today = mm+'/'+dd+'/'+yyyy;
date = getMonthBack(date);
dd = date.getDate();
mm = date.getMonth() + 1; //January is 0!
yyyy = date.getFullYear();
startTime = Date.parse(mm+"/"+dd+"/"+yyyy);
getSpendings(id,pin,mm+'/'+dd+'/'+yyyy,today);
}
function performLogin() {
var id = $("#uid").val();
var pin = $("#pin").val();
if (id.length != 8 || pin.length < 4 || pin.length > 6) {
return;
}
if ($('#remember').prop('checked')) {
chrome.storage.sync.set({login: {"uid" : id, "pin": pin}});
}
return login(id,pin);
}
$("body").on('click', '#login_button', function() {
performLogin();
});
$("body").on('click', '#back_button', function() {
loadOverview();
});
$("body").on('keypress', '#uid,#pin,#remember', function(e) {
if(e.which == 13) {
performLogin();;
}
});
$("body").on('click', '#daily_spending_button', function(){
currentGraph = "interval";
loadGraphs();
});
$("body").on('click', '#balance_over_time_button', function() {
currentGraph = "net";
loadGraphs();
})
$("body").on('click', '#logout_button', function(){
chrome.storage.sync.clear();
resetVariables();
loadLogin();
});
$(document).ready(function() {
currentClass = "loading";
chrome.storage.sync.get("login", function(obj) {
var id, pin;
if (obj.login == null) {
loadLogin();
}
else {
return login(obj.login.uid,obj.login.pin);
}
});
});