03 February 2015

Know the Battery Status of your Visitor’s Mobile Phone



When someone visits your website, you can easily retrieve information about the charge level of their mobile or laptop’s battery through the Battery Status API (live demo). This is currently supported on Google Chrome, Opera & Firefox on the desktop and Chrome for Android.


The Battery API can be implemented with few lines of JavaScript code and reveals all the required details about the device’s battery charge level. You’ll get to know:



  1. Whether or not the visitor’s battery is currently being charged.

  2. How much is the battery charged?

  3. If charging, how many seconds until the battery is fully charged.

  4. The remaining time in seconds until the battery is completely discharged.

    Battery Status Demo


    You can attach event listeners so the battery data is updated as soon as the charge level of the hardware’s battery is changed while the visitor is still on your page. You can go one step further and even integrate this with Google Analytics and store the battery charge level of your visitor’s devices using Events in Analytics.



    <script>

    if (navigator.getBattery) {
    navigator.getBattery().then(function(battery) {
    display(battery);
    });
    } else if (navigator.battery) {
    display(navigator.battery);
    } else {
    console.log("Sorry, Battery Status API is not supported");
    }

    function display(battery) {
    console.log('Charge level? ' + battery.level);
    console.log('Battery charging? ' + battery.charging);
    console.log('Time to charge? ' + battery.chargingTime);
    console.log('Time to discarge? ' + battery.dischargingTime);
    }

    </script>

    This can have several use cases. For instance, when the visitor’s device is running low on battery and not plugged-in, the web developer can choose to automatically save the changes – like the form entries – in localStorage before the battery is completely drained.


    Here’s a complete list of browsers that currently support the Batter Status API as found on caniuse.com. To know more, refer to the documentation on Mozilla and W3.


    HTML5 Battery Status




    The story, Know the Battery Status of your Visitor’s Mobile Phone , was originally published at Digital Inspiration by Amit Agarwal on 03/02/2015 under JavaScript, Internet.


Save your YouTube Videos to Google Drive



You have been uploading videos to the YouTube website all this time but you are now looking to explore additional channels. Maybe you can put them on other video hosting websites like Vimeo or your Facebook page to reach an even wider audience. You can bundle the YouTube video files as an iTunes podcast that people can download and watch offline.


The important point is how do you get your original video files from YouTube for uploading to other websites? If you have been diligently storing a backup of every single video file that you have ever uploaded to YouTube, please skip reading this, else there are two “official” options.


If you head over to the creator dashboard on the YouTube website, you can download any of your website with a simple click (read how-to). The only downside with the option is that YouTube downsizes your HD videos to 480p.


Also see: Save Web Files to Google Drive


There’s another option available inside Google Takeout that will not only let you download your YouTube videos in their original high-resolution but also saves the files directly to your Google Drive. Thus, you can start the download process and it will save all your files, big and small, to Google Drive in the background. Once the files are in Drive, they’ll automatically sync to your desktop that you can later upload to other video websites.


To get started, go to this custom link, click the Next button and choose Add to Drive as your delivery method. That’s it. All you YouTube videos will be zipped and added to the Takeout folder in Drive in few hours. If the total size of your videos exceeds 2GB, it will create multiple files of 2 GB each.


An in addition to original videos, the zipped files from take will also include the video descriptions as well as all your playlists in JSON format.


Download YouTube Videos to Google Drive




The story, Save your YouTube Videos to Google Drive , was originally published at Digital Inspiration by Amit Agarwal on 03/02/2015 under Google Drive, YouTube, Internet.