forked from chucknthem/Simple-Usage-Meter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
aaNet.js
59 lines (56 loc) · 1.79 KB
/
aaNet.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
function aaNet_getConfig() {
var cfg = new Object();
cfg.url = "https://www.aanet.com.au/usage3.php?{USERNAME},{PASSWORD}";
cfg.requestType = "GET";
cfg.requestParams = null;
return cfg;
}
/*
* aaNet ISP
* usage3.php contains: "\n70024936,25816905581,2010-02-28 08:17:20,18,76800,ADSL2+,ADSL2 150G";
* upload,downloads (bytes),current date,billing day,limit(megabytes),plan type,plan name
*/
function aaNet_parseXML(text) {
if(!text) {
return mkError("Nothing to parse");
} else {
// Strip that line break
text = text.replace(/^\s+|\s+$/g,"");
// Split the CSV data into an array called 'v'
v = new Array();
v = text.split(",");
// aaNet quota is clearly defined
var limitmb = v[4];
// aaNet usage is the greater of downloads or uploads
var gbformat = 1024;
gbformat = localStorage['gbformat'];
var upload = Math.round(v[0]/gbformat/gbformat);
var download = Math.round(v[1]/gbformat/gbformat);
var usagemb = 0;
if ((download > upload) || (upload == 0) || (download == upload)) {
usagemb = download;
} else {
usagemb = upload;
}
// Determine how many days are left in the billing cycle
var today = new Date();
var date = today.getDate();
var year = today.getFullYear();
if (date < v[3]) { var month = today.getMonth(); }
else { var month = today.getMonth()+1; }
/* year, month, day */
var enddate = new Date(year, month, v[3]);
var daysleft = (enddate.getTime() - today.getTime())/(1000*60*60*24);
// Store the results and return them
var i = 0;
var results = new Array();
results[i] = new Object();
results[i]['name'] = "aaNet " + v[6];
results[i]['usagemb'] = usagemb;
results[i]['limit'] = limitmb;
results[i]['daysleft'] = Math.ceil(daysleft);
results[i]['lastupdate'] = v[2];
results[i]['custom'] = false;
return results;
}
}