Last active
January 9, 2017 13:04
-
-
Save JustinDFuller/602e16f9cb147fecc441af9827238b3a to your computer and use it in GitHub Desktop.
Battery status API
This file contains 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
if ('getBattery' in navigator) { | |
navigator.getBattery().then(battery => { | |
console.log('Initial', battery); | |
battery.onchargingchange = onchange; | |
battery.onchargingtimechange = onchange; | |
battery.ondischargingtimechange = onchange; | |
battery.onlevelchange = onchange; | |
function onchange (event) { | |
console.log('On change, type: %s', event.type, battery); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment