tshm
7/28/2014 - 7:17 AM

pomodoro.hta

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
  <meta http-equiv="x-ua-compatible" content="ie=9" />
  <title>Timer</title>
  <HTA:APPLICATION
  APPLICATIONNAME="Timer"
  SCROLL="yes"
  WINDOWSTATE="minimize"
  SINGLEINSTANCE="yes" />
  <style>
#timer { font-size: 2em; }
  </style>
</head>
<body onload="run()">
  <div>
    <span id="timer"></span>
  </div>
<script type="text/javascript">
(function main( window, undefined ) {

  var el = document.querySelector('title');
  var el2 = document.querySelector('#timer');
  var M = 60;

  var fmt = function(sec) {
    var min = Math.floor( sec / M );
    var rem = sec % M;
    return min + ':' + ('0' + rem).substr( -2 );
  };
  var countDown = function( cnt, cb ) {
    var id = window.setInterval(function() {
      cnt = cnt - 1;
      el.innerHTML = fmt( cnt );
      el2.innerHTML = fmt( cnt );
      if ( cnt < 1 ) {
        window.clearInterval( id );
        cb();
      }
    }, 1000);
  };
  var showAlert = function( msg ) {
    //window.focus();
    var sh = new ActiveXObject("WScript.Shell");
    //sh.Popup( msg );
    //sh.Run('mshta javascript:alert("' + msg + '");close();');
    sh.Run('cmd /c echo ' + msg + '&& pause', 1, true);
  };

  function run() {
    countDown( 25 * M, function() {
      showAlert('work timer elapsed.');
      countDown( 5 * M, function() {
        showAlert('recess timer elapsed.');
        window.close();
      });
    });
  };

  window.run = run;

})( window );
</script>
</body>
</html>