Skip to content

Commit 39a1091

Browse files
authored
Merge pull request #365 from Mukulbaid63/bs_1
Battery status added
2 parents 8370aac + ccdb4a1 commit 39a1091

File tree

4 files changed

+85
-0
lines changed

4 files changed

+85
-0
lines changed

JavaScript/BatteryStatus/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## Battery Status app :
2+
- This script is made using HTML,CSS and JS.
3+
- It shows the battery level,charging status,battery charging time, battery discharging time on the screen.
4+
- It also updates the if any changes appear on the parameters.

JavaScript/BatteryStatus/app.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
var level=document.querySelector(".charging-level")
3+
var status=document.querySelector(".status")
4+
var charge=document.querySelector(".charge")
5+
var discharge=document.querySelector(".discharge")
6+
7+
if(navigator.getBattery()){
8+
navigator.getBattery()
9+
.then(function(battery) {
10+
level.innerHTML = battery.level*100;
11+
battery.onlevelchange=function()
12+
{
13+
level.innerHTML = battery.level*100;
14+
}
15+
charge.innerHTML=battery.chargingTime;
16+
battery.onchargingtimechange=function()
17+
{
18+
charge.innerHTML = battery.chargingTime;
19+
}
20+
discharge.innerHTML=battery.dischargingTime;
21+
battery.ondischargingtimechange=function()
22+
{
23+
discharge.innerHTML = battery.dischargingTime;
24+
}
25+
if(battery.charging==true) {status.innerHTML="Charging";
26+
battery.onchargingchange=function()
27+
{
28+
status.innerHTML="Not Charging";
29+
}}
30+
else {status.innerHTML="Not Charging";
31+
battery.onchargingchange=function()
32+
{
33+
status.innerHTML="Charging";
34+
}}
35+
})
36+
.catch(function(e) {
37+
console.error(e);
38+
});
39+
}
40+
else{
41+
status.innerHTML="Browser doesn't support ";
42+
}

JavaScript/BatteryStatus/index.html

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
3+
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
4+
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
5+
<!--[if gt IE 8]> <html class="no-js"> <!--<![endif]-->
6+
<html>
7+
<head>
8+
<meta charset="utf-8">
9+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
10+
<title></title>
11+
<meta name="description" content="">
12+
<meta name="viewport" content="width=device-width, initial-scale=1">
13+
<link rel="stylesheet" href="style.css">
14+
</head>
15+
<body>
16+
<div> Level: <span class="charging-level">
17+
unknown
18+
</span>%</div>
19+
<div> Status:<span class="status">
20+
unknown
21+
</span></div>
22+
<div>Charging Time:<span class="charge">unknown</span> seconds</div>
23+
<div>Charging Time:<span class="discharge">unknown</span> seconds</div>
24+
<script src="app.js"></script>
25+
</body>
26+
</html>

JavaScript/BatteryStatus/style.css

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
div{
2+
padding: 10px;
3+
margin: 10px;
4+
font-family: Georgia, 'Times New Roman', Times, serif;
5+
font-size: 20px;
6+
font-weight: 700;
7+
}
8+
body{
9+
display: flex;
10+
flex-direction: column;
11+
align-items: center;
12+
justify-content: center;
13+
}

0 commit comments

Comments
 (0)