Created
February 16, 2015 14:29
-
-
Save kheniparth/ba7c0c534520ea00404a to your computer and use it in GitHub Desktop.
Get battery status of your website visitors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
if (navigator.getBattery) { | |
navigator.getBattery().then(function(battery) { | |
display(battery); | |
}); | |
} else if (navigator.battery) { | |
display(navigator.battery); | |
} else { | |
console.log("Sorry, Battery Status API is not supported"); | |
} | |
function display(battery) { | |
console.log('Charge level? ' + battery.level); | |
console.log('Battery charging? ' + battery.charging); | |
console.log('Time to charge? ' + battery.chargingTime); | |
console.log('Time to discarge? ' + battery.dischargingTime); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment