-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
58 lines (53 loc) · 1.55 KB
/
script.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
var cell = document.getElementById('cell');
var indicator = document.getElementById('indicator');
navigator.getBattery().then(function(battery) {
function updateAllBatteryInfo(){
updateChargeInfo();
updateLevelInfo();
updateChargingInfo();
updateDischargingInfo();
}
updateAllBatteryInfo();
battery.addEventListener('chargingchange', function(){
updateChargeInfo();
});
function updateChargeInfo(){
if(battery.charging){
cell.style.background="#06eeb0";
indicator.style.display="block";
}
else{
indicator.style.display="none";
if(battery.level<0.25){
cell.style.background="#e0821f";
}
else{
cell.style.background="#08c66b";
}
}
}
battery.addEventListener('levelchange', function(){
updateLevelInfo();
});
function updateLevelInfo(){
cell.style.height = battery.level * 100 + "%";
cell.innerHTML = "<br/>"+Math.round(battery.level * 100) + "%";
if(battery.level<0.15){
cell.style.background="#e0821f";
}
}
battery.addEventListener('chargingtimechange', function(){
updateChargingInfo();
});
function updateChargingInfo(){
console.log("Battery charging time: "
+ battery.chargingTime + " seconds");
}
battery.addEventListener('dischargingtimechange', function(){
updateDischargingInfo();
});
function updateDischargingInfo(){
console.log("Battery discharging time: "
+ battery.dischargingTime + " seconds");
}
});