var battery = navigator.battery || navigator.webkitBattery || navigator.mozBattery;

function log(message){
  document.querySelector("#data").innerHTML += message + "<br />";
}

if (battery) {
	log("Battery level: " + battery.level);
	log("Battery charging: " + battery.charging);
	log("Battery discharging time: ", battery.dischargingTime);
	battery.addEventListener("chargingchange", function(e) {
	  log("Battery chargingchange event: " + battery.charging);
	}, false);
} else {
	log("Shame! The Battery API is not supported on this platform.")
}

var battery = navigator.battery || navigator.webkitBattery || navigator.mozBattery;

function log(message){
  document.querySelector("#data").innerHTML += message + "<br />";
}

function logBattery(battery) {
	log("Battery level: " + battery.level);
	log("Battery charging: " + battery.charging);
	log("Battery discharging time: ", battery.dischargingTime);
	battery.addEventListener("chargingchange", function(e) {
	  log("Battery chargingchange event: " + battery.charging);
	}, false);
}

if(navigator.getBattery) {
	navigator.getBattery().then(logBattery, function() {
		log("There was an error while getting the battery state.");
	});
} else if (battery) {
	logBattery(battery);
} else {
	log("Shame! The Battery API is not supported on this platform.")
}

Update the battery example to match the spec
Update the battery example to match the spec

Uses the `navigator.getBattery()` promise when available instead of the deprecated `navigator.battery`