Giter Club home page Giter Club logo

browserapi's Introduction

browserapi

A wrapper tool for next generation browser apis like vibration, fullscreen, and etc.

Supported APIs

  • Geolocation
  • fetch
  • Fullscreen API
  • Battery
  • ServiceWorker
  • DeviceOrientation
  • Vibrate
  • AudioContext
  • caches

Geolocation

browserapi.get('geolocation')((geolocation) => {
  geolocation.getCurrentPosition(function (data) {
    console.dir(data); //successfully get the Geoposition data
  }, function (err) {
    console.dir(err); // logs the error stack
  }, {
    enableHighAccuracy: true,
    timeout: 5000,
    maximumAge: 0
  }); //options while getting geolocation data
});

fetch

browserapi.get('fetch')((fetch) => {
  fetch(new Request('<URL>')).then(function (data) {
    console.dir(data);
  });
});
Fullscreen API
browserapi.get('fullScreen')(document.querySelector('body'), (fullScreen) => {
  console.dir(fullScreen);
});
Note : This method invocation prints "Failed to execute 'requestFullScreen' on 'Element': API can only be initiated by a user gesture.". Since the security concerns, it only can be triggered by a user event like click or etc.

Battery

browserapi.get('battery')((battery) => console.log(battery.level));
//logs 0.97

Service Worker

browserapi.get('serviceWorker')((serviceWorker) => {
  console.dir(instance);
});

Local Storage

browserapi.get('localStorage')((localStorage) => {
   localStorage.setItem('some_data', '{some_data : "yes, cool..."}');
   console.dir(localStorage.getItem('some_data'));
});

Device Orientation

browserapi.get('deviceOrientation')((deviceOrientation) => {
   console.dir(deviceOrientation);
});

vibrate

browserapi.get('vibrate')((vibrate) => {
   navigator['vibrate'](1000);
});

audioContext

browserapi.get('audioContext')((audioContext) => {
   console.dir(audioContext);
});

Caches API

browserapi.get('caches')((caches) => {
   console.dir(caches);
})

browserapi's People

Contributors

hwclass avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

browserapi's Issues

Error: fullScreen is read-only

fullScreen cannot be modified since it is a constant.

const fullScreen = null;
if (element.requestFullscreen) {
  fullScreen = element.requestFullscreen();
} else if (element.mozRequestFullScreen) {
  fullScreen = element.mozRequestFullScreen();
} else if (element.webkitRequestFullscreen) {
  fullScreen = element.webkitRequestFullscreen();
} else if (element.msRequestFullscreen) {
  fullScreen = element.msRequestFullscreen();
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.