<!DOCTYPE html>
<html>
  <body>

    <h1>Sit Up Straight!</h1>

    <script   src="https://code.jquery.com/jquery-2.2.4.min.js"   integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="   crossorigin="anonymous"></script>

    <script type="text/javascript">

      function requestPermission(){
        Notification.requestPermission();
      }

      function checkPermission(){
        if (Notification.permission){
          // Firefox
          console.log(Notification.permission);
        } else {
          // Chrome
          console.log((new Notification("check")).permission);
        }
      }

      function showAlert(){
        var notification = new Notification('Sit up straight!', {
              tag: 'sit-up-straight',
              body: 'Hey bro, sit up straight!!',
              iconUrl: 'http://raphaelgmelo.github.io/sit-up-straight/approves.jpg', // Firefox
              icon: 'http://raphaelgmelo.github.io/sit-up-straight/approves.jpg', // Chrome
            });

        notification.onclick(function(){
          notification.close();
          // chrome only
          // If the window is minimized, restore the size of the window
          window.open().close();
          window.focus();
        });

      }


      $(function() {

        if (window.Notification){

          requestPermission();

          var interval = 60 * 5000;

          setInterval(function() {
            checkPermission();
            showAlert();
          }, interval);

        }

      });

    </script>

  </body>
</html>
