-
Notifications
You must be signed in to change notification settings - Fork 0
/
denchi.html
71 lines (58 loc) · 2.01 KB
/
denchi.html
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
<!DOCTYPE html>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0">
<title>バッテリー情報</title>
<h1>バッテリー情報</h1>
<ul>
<li>バッテリー残量:<span id="level"></span>%
<li>状態:<span id="charging"></span>
</ul>
<script>
function update(){
myTbl = new Array("日","月","火","水","木","金","土");
myD = new Date();
year = myD.getFullYear();
month = myD.getMonth() + 1;
date = myD.getDate();
day = myD.getDay();
hours = myD.getHours();
minutes = myD.getMinutes();
seconds = myD.getSeconds();
var update = false;
navigator.getBattery().then(function(battery) {
if(battery.charging){
var nowbattery = "充電中(true)";
}else{
var nowbattery = "放電中(false)";
}
var oldlevel = document.getElementById('level').innerHTML;
if(Number(Math.round(battery.level*100)) != Number(oldlevel)){
document.getElementById('level').innerHTML = Math.round(battery.level*100);
update = true;
}
var oldbattery = document.getElementById('charging').innerHTML;
if(nowbattery != oldbattery){
document.getElementById('charging').innerHTML = nowbattery;
update = true;
}
if(update){
var table = document.getElementById("status_table");
var newtr = table.insertRow( table.rows.length );
var newtd = newtr.insertCell( newtr.cells.length );
newtd.appendChild( document.createTextNode(year + "/" + ("0"+month).slice(-2) + "/" + ("0"+date).slice(-2) + " (" + myTbl[day] + ") " + ("0"+hours).slice(-2) + ":" + ("0"+minutes).slice(-2) + ":" + ("0"+seconds).slice(-2)));
var newtd = newtr.insertCell( newtr.cells.length );
newtd.appendChild( document.createTextNode(Math.round(battery.level*100)) );
var newtd = newtr.insertCell( newtr.cells.length );
newtd.appendChild( document.createTextNode(nowbattery) );
}
});
}
setInterval("update();", 1000);
</script>
<table id="status_table" border="1">
<tr>
<td>時間</td>
<td>残量</td>
<td>状態</td>
</tr>
</table>