Pomodoro Clock

In this example below you will see how to do a Pomodoro Clock with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by 19920612, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright 19920612 ©

Technologies

  • HTML
  • CSS
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>Pomodoro Clock</title>
  
  
  
      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  <body ng-app="myApp" ng-controller="myCtrl">
    <h1>Pomodoro Clock</h1>
    <div id="time-setter">
        <div id="break-setter" class="setter">
            <p>BREAK LENGTH</p>
            <span class="sub" ng-click="changeBreakPeriod($event)" >-</span>
            <span>{{breakPeriod}}</span>
            <span class="add" ng-click="changeBreakPeriod($event)">+</span>            
        </div>
        
        <div id="session-setter" class="setter">
            <p>SESSION LENGTH</p>
            <span class="sub" ng-click="changeSessionPeriod($event)">-</span>
            <span>{{sessionPeriod}}</span>
            <span class="add" ng-click="changeSessionPeriod($event)">+</span>            
        </div>
    </div>
    
    <div id="time-panel" ng-click="timerBegin()">
        <p>{{currentPriod}}</p>
        <p><span>{{remainTime.min}}</span><span>:{{remainTime.sec}}</span></p>
        <div id="current-status"></div>
    </div>
    
    <button ng-click="resetPomodoro()">Reset Pomodoro</button>
</body>
  <script src='https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.min.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/19920612/pomodoro-clock-gLrXMz */
* {
  margin: 0;
  font-family: Open Sans, Arial; }

body {
  background-color: #333333;
  color: white;
  text-align: center; }

h1 {
  text-align: center;
  margin-top: 5%;
  font-size: 3em; }

#time-setter {
  text-align: center;
  font-size: 2em; }

.setter {
  display: inline-block;
  padding: 5%; }

#time-panel {
  border-radius: 50%;
  border: 2px solid #99CC00;
  width: 200px;
  height: 200px;
  cursor: pointer;
  text-align: center;
  margin: auto;
  position: relative; }

#time-panel p {
  font-size: 2em;
  padding: 10%; }

.sub,
.add {
  cursor: pointer;
  padding: 10px; }

#current-status {
  position: absolute;
  width: 100%;
  height: 0px;
  background: red;
  top: 0px;
  border-radius: 50%; }

button {
  border: none;
  height: 5%;
  width: 150px;
  margin-top: 3%;
  cursor: pointer;
  background: #99CC00;
  color: white;
  font-size: 1.2em; }

/*# sourceMappingURL=Pomodoro_Clock.css.map */


/*Downloaded from https://www.codeseek.co/19920612/pomodoro-clock-gLrXMz */
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $interval){
    $scope.inProcess = false;
    $scope.currentPriod = "Session";
    $scope.breakPeriod = 5;
    $scope.sessionPeriod = 25;
    $scope.remainTime = {'min': 25, 'sec': '00'};
    var pomoTimer;
    var needReset = true;
    
    $scope.changeBreakPeriod = function(target){
        if($scope.inProcess === false){
            if(target.srcElement.className === "add"){
                $scope.breakPeriod++;
            }else if(target.srcElement.className === "sub" && $scope.breakPeriod != 1){
                $scope.breakPeriod--;
            }
        }
    };
    
    $scope.changeSessionPeriod = function(target){
        if($scope.inProcess === false){
            if(target.srcElement.className === "add"){
                $scope.sessionPeriod++;
                $scope.remainTime.min++;
            }else if(target.srcElement.className === "sub" && $scope.sessionPeriod != 1){
                $scope.sessionPeriod--;
                $scope.remainTime.min--;
            }
        }
    };

    $scope.resetPomodoro = function(){
        $scope.breakPeriod = 5;
        $scope.sessionPeriod = 25;
        $scope.remainTime = {'min': 25, 'sec': '00'};
    }
    
    $scope.timerBegin = function(){
        if($scope.inProcess === false){
            //set timer
            $scope.inProcess = true;            
            pomoTimer = $interval(updateTimer, 1000);
        }else{
            //stop timer
            $scope.inProcess = false;
            $interval.cancel(pomoTimer);
        }
    };    
    
    function updateTimer(){
        //reset value
        if(needReset === true){
            $scope.remainTime.sec = '00';
            if($scope.currentPriod === "Session"){
                $scope.remainTime.min = $scope.sessionPeriod;   
            }else{
                $scope.remainTime.min = $scope.breakPeriod;                
            }
            needReset = false;
        }
        //update value
        if($scope.remainTime.sec == "00"){
            //all to zero, change period status
            if($scope.remainTime.min === 0){
                if($scope.currentPriod === "Session"){
                    $scope.currentPriod = "Break"
                }else{                
                    $scope.currentPriod === "Session"
                }
                needReset = true;
            }else{
                $scope.remainTime.min--;
                $scope.remainTime.sec = "59";
            }
        }else{
            $scope.remainTime.sec = (parseInt($scope.remainTime.sec) - 1);
            if($scope.remainTime.sec < 10)
                $scope.remainTime.sec = '0' + $scope.remainTime.sec;
        }
    }
});

Comments