• Stars
    star
    118
  • Rank 289,855 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 11 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A tiny wrapper for the HTML5 Battery Status API.

Battery.js NPM version NPM downloads MIT License

A tiny JavaScript wrapper for the HTML5 Battery Status API.

As of October 2015 the Battery Status API is supported by Firefox, Chrome, Opera, Android Browser and Chrome for Android: http://caniuse.com/battery-status

Due to privacy concerns, support for the Battery Status API has been dropped from most browsers. See: https://caniuse.com/#feat=battery-status.

Install

$ npm install battery.js

Usage

var Battery = require('battery.js'); // or similar

function logBatteryStatus(status) {
  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
}

// Get battery status as soon as it's available
Battery.getStatus(function(status, error) {
  if(error) {
    console.error('Battery status is not supported');
    return;
  }

  logBatteryStatus(status);
});

// Register a handler to get notified when battery status changes
Battery.onUpdate(logBatteryStatus);

Demo

pstadler.dev/battery.js

More Repositories

1

keybase-gpg-github

Step-by-step guide on how to create a GPG key on keybase.io, adding it to a local GPG setup and using it with Git and GitHub.
2,609
star
2

flightplan

Run sequences of shell commands against local and remote hosts.
JavaScript
1,815
star
3

ticker.sh

Real-time stock tickers from the command-line.
Shell
502
star
4

metrics.sh

Collect and forward metrics using portable shell scripts
Shell
132
star
5

octofolders

The missing GitHub folder icons for Mac OS X.
97
star
6

dotfiles

For my very own convenience.
Vim Script
62
star
7

alfred-screensharing

Connect to a host in Alfred with automatic network discovery.
53
star
8

alfred-cask

Manage Homebrew Casks with Alfred.
Shell
46
star
9

alfred-mount

Use Alfred to connect to your network shares with ease.
Makefile
41
star
10

non-terminating-bash-processes

Taming non-terminating Bash processes.
Shell
40
star
11

optometrist

Your optometrists favorite color theme for Terminal.app and iTerm2.
34
star
12

alfred-top

Process management in Alfred with top and kill.
Shell
20
star
13

candy-node

Deploy Candy as a node.js application
JavaScript
20
star
14

plex-duplicates

Find duplicate movie files in Plex Media Server.
Ruby
17
star
15

dtox

Extensible data transfer objects in JavaScript.
JavaScript
11
star
16

pagerank-service

A web service providing Google PageRank results.
Ruby
10
star
17

the-cube

The Cube is an experiment with CSS3 transitions.
HTML
10
star
18

alfred-play

Intelligent global hotkeys for Music.app and Spotify with Alfred.
Makefile
9
star
19

rethinkdb-udp-charts

Real-time charts using RethinkDB changefeeds.
JavaScript
5
star
20

ff-pagerank-client

A simple Firefox extension for displaying the Google PageRank of the websites you're visiting.
JavaScript
5
star
21

octoprowl

GitHub + Prowl = Octoprowl
Ruby
4
star
22

ticker-rs

Real-time stock tickers from the command-line. Written in Rust.
Rust
4
star
23

cloudflare-webfinger

Bring your own domain to Mastodon using Cloudflare Workers.
JavaScript
4
star
24

redirectcheck-service

A web service to check the HTTP status code behind a URL.
Ruby
3
star
25

candy-go

Deploy Candy as a Go application.
Go
3
star
26

candy-gae

Candy on Google App Engine (experimental)
Python
1
star
27

pfsense-traffic

Command-line tool for displaying traffic data from pfSense
Shell
1
star
28

candy-rack

Deploy Candy as a Rack application.
Ruby
1
star
29

rancheros-uefi

UEFI bootable RancherOS image.
1
star
30

ff-redirectcheck-client

A simple Firefox extension for retrieving and displaying the HTTP status code right beside the link on a page.
JavaScript
1
star