123

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class="container-fluid">
  <div id="pomodoro" class="container">
    <h1 class="text-center"><span id="title">Pomodoro Clock</span></h1>
    <div id="setTimes" class="container">
      <div class="row">
        <div class="col-xs-6 text-center">
          <h3>Session</h3>
        </div>
        <div class="col-xs-6 text-center">
          <h3>Break</h3>
        </div>
      </div>
      <div class="row">
        <!--delete me-->

        <div id="decPom" class="col-xs-2 btn block-center minus">
          <i class="fa fa-chevron-down fa-1x"></i>
        </div>

        <div id="session" class="col-xs-2 block-center text-center time">
          <span id="testPom">25</span>
        </div>

        <div id="incPom" class="col-xs-2 btn block-center plus">
          <i class="fa fa-chevron-up fa-1x"></i>
        </div>


        <div id="decBreak" class="col-xs-2 btn block-center minus">
          <i class="fa fa-chevron-down fa-1x"></i>
        </div>

        <div id="break" class="col-xs-2 block-center text-center time">
          <span id="testBreak">5</span>
        </div>

        <div id="incBreak" class="col-xs-2 btn block-center plus">
          <i class="fa fa-chevron-up fa-1x"></i>
        </div>

      </div>
    </div>


    <div id="playPomodoro" class="container">
      <div class="row">
        <div class="col-xs-6">
          <div id="start" class="btn btn-block" data-toggle="tooltip" title="Start clock"><i class="fa fa-play fa-3x"></i></div>
        </div>
        <div class="col-xs-6">
          <div id="reset" class="btn btn-block" data-toggle="tooltip" title="Stop Clock and Reset Session and Break to 25 and 5"><i class="fa fa-refresh fa-3x"></i></div>
        </div>
      </div>
      <div class="row">
        <div class="col-xs-12 text-center">
          <h2 id="activity">Session</h2>
        </div>
      </div>
      <div class="row">
        <div id="testClock" class="col-xs-12 text-center"></div>
      </div>
      <div class="row">
        <div class="col-xs-6">
          <div id="pause" class="btn btn-block" data-toggle="tooltip" title="Pause clock"><i class="fa fa-pause fa-3x"></i></div>
        </div>
        <div class="col-xs-6">
          <div id="stop" class="btn btn-block" data-toggle="tooltip" title="Stop clock"><i class="fa fa-stop fa-3x"></i></div>
        </div>
      </div>
    </div>
  </div>
</div>
            
          
!
            
              @import url(https://fonts.googleapis.com/css?family=Orbitron|Oswald);
body {
  background-color: grey;
}

#pomodoro {
  margin-top: 10%;
}

#setTimes,
#playPomodoro {
  color: white;
  background-color: black;
  max-width: 450px;
}

@media screen and (max-width: 450px) {
  #setTimes,
  #playPomodoro {
    margin-left: -30px;
    margin-right: -30px;
  }
}

h1 #title {
  font-family: Oswald;
  font-weight: bold;
  font-size: 1.5em;
}

h2,
h3 {
  font-family: Oswald;
  font-weight: bold;
}

#setTimes {
  padding-bottom: 5px;
  margin-bottom: 15px;
}

.time {
  font-family: Orbitron;
  font-size: 1.5em;
}

#activity {
  margin-top: -10px;
}

#testClock {
  font-family: Orbitron;
  font-size: 4em;
}

#playPomodoro {
  padding-top: 5px;
  margin-bottom: 20px;
}

#playPomodoro .fa:hover {
  color: #BFAD7C;
}
            
          
!
            
              $(document).ready(function() {
  //global variables
  var snd = new Audio("https://www.dropbox.com/s/p3wconux2o8hdbn/Air%20Horn-SoundBible.com-1561808001.wav?dl=1");
  var breakTime = 300;
  var workTime = 1500,
    currentTime = workTime,
    testPom = currentTime;
  var onDeck = "Break";
  var id = true;

  // Set session start time
  $("#testClock").text(secToTimeString(workTime));

  // Click handlers to adjust Session and Break times
  // Reduce Session time
  $("#decPom").click(function() {
    // Cannot reduce below 1
    if (testPom == workTime && $("#testPom").text() > 1) {
      var pom = $("#testPom").text();
      pom--;
      $("#testPom").text(pom);
      testPom =
        currentTime =
        workTime = eval(minToSec($("#testPom").text()));
      $("#testClock").text(secToTimeString(workTime));
    }
  });
  // Increase Session time
  $("#incPom").click(function() {
    if (testPom == workTime) {
      var pom = $("#testPom").text();
      pom++;
      $("#testPom").text(pom);
      testPom =
        currentTime =
        workTime = eval(minToSec($("#testPom").text()));
      $("#testClock").text(secToTimeString(workTime));
    }
  });
  // Reduce Break time
  $("#decBreak").click(function() {
    // Cannot reduce below 1
    if (testPom == workTime && $("#testBreak").text() > 1) {
      var brk = $("#testBreak").text();
      brk--;
      $("#testBreak").text(brk);
      breakTime = eval(minToSec($("#testBreak").text()));
    }
  });
  // Increase Break time
  $("#incBreak").click(function() {
    if (testPom == workTime) {
      var brk = $("#testBreak").text();
      brk++;
      $("#testBreak").text(brk);
      breakTime = eval(minToSec($("#testBreak").text()));
    }
  });
  
  // Click handlers for controlling flow of session
  $("#start").click(countdown);

  $("#pause").click(pauseCountdown);

  $("#stop").click(stopCountdown);

  $("#reset").click(resetCountdown);
  
/* ------------Functions------------ */

  // Convert Break and Session time from minutes to seconds
  function minToSec(min) {
    
    return min * 60;
  }
  
  // Convert seconds to 00:00:00 format.
  function secToTimeString(second) {
        
    var hour = 0,
      minute = 0;
    hour = Math.floor(second / 3600);
    second = second - (3600 * hour);
    minute = Math.floor(second / 60);
    second = second - (60 * minute);

    if (hour > 0) return n(hour) + ":" + n(minute) + ":" + n(second);
    else return n(minute) + ":" + n(second);
    
    //function to add leading 0
    function n(n) {
      return n > 9 ? "" + n : "0" + n;
    }
  }

  // Start pomodoro
  function countdown() {
    if (id === true) {
      testPom = currentTime;
      //id = setInterval(decrement, 1000);
      
      // Timing function
      function decrement() {
        
        // Toggle between Session and Break
        if (testPom == 0) {
          snd.play();
          $("#activity").text(onDeck);
          switch (onDeck) {
            case "Break":
              testPom = breakTime;
              onDeck = "Session";
              break;
            case "Session":
              testPom = workTime;
              onDeck = "Break";
              break;
          }
          $("#testClock").text(secToTimeString(testPom));
        } else {
          
          // Reduce time left by 1 second and display result in 00:00:00 format
          testPom--;
          $("#testClock").text(secToTimeString(testPom));
        }
        
        // Change color of clock based on percent of time left
        var percentLeft = Math.floor((testPom / workTime) * 100);
        if (percentLeft <= 10) {
          $("#testClock").css("color", "red");
        } else if (percentLeft <= 25) {
          $("#testClock").css("color", "yellow");
        } else {
          $("#testClock").css("color", "green");
        }
      }
      
      id = setInterval(decrement, 1000);
    }
  }

  function pauseCountdown() {
    clearInterval(id);
    id = true;
    currentTime = testPom;
  }

  function stopCountdown() {
    clearInterval(id);
    id = true;
    testPom = currentTime = workTime;
    $("#testClock").text(secToTimeString(workTime));
    $("#testClock").css("color", "white");
    $("#activity").text("Session");
    onDeck = "Break";
  }

  function resetCountdown() {
    clearInterval(id);
    id = true;
    testPom = currentTime = workTime = minToSec(25);
    breakTime = minToSec(5);

    $("#testPom").text(25);
    $("#testBreak").text(5);
    $("#testClock").text(secToTimeString(testPom));
    $("#testClock").css("color", "white");
    $("#activity").text("Session");
    onDeck = "Break";
  }

});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console