Skip to content

anssiko/battery.js

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Battery.js

A tiny JavaScript wrapper for the HTML5 Battery Status API.

Usage

if(Battery.isSupported()) {
	// Get the battery status
	var status = Battery.getStatus();
	console.log('Level: ' + Math.floor(status.level * 100) + '%'); // 30%
	console.log('Charging: ' + status.charging);                   // true
	console.log('Time until charged: ' + status.chargingTime);     // 3600 (seconds) or Infinity
	console.log('Battery time left: ' + status.dischargingTime);   // 3600 (seconds) or Infinity

	// Register a handler to get notified when battery status changes
	Battery.onUpdate = function(status) {
		console.log(status); // {level, charging, chargingTime, dischargingTime}
	};
}

Demo

koeniglich.ch/battery.js

As of January 2013 the Battery Status API is supported by

  • Firefox 11+ on Windows/Linux
  • Firefox 18+ on MacOSX.

About

A tiny wrapper for the HTML5 Battery Status API.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors