Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="container">
<!--   <h3>Pomodoro Clock</h3> -->
  <div class="circle total-progress">
    <div class="seconds progress">
      <div class="middle">
        <div id="time-status">
          <div id="timer-type"></div>
          <span class="hidden" id="hours-left"></span>
          <span id="min-left"></span>
          <span id="sec-left"></span>
        </div>
      </div>
    </div>
  </div>
  <div class="settings">
    <div class="session-settings">
      <span class="settings-headers">session time</span>
      <span id="session-time"></span>
      <button class="settings-btn-plus" id="session-plus" type="button">+</button>
      <button class="settings-btn-minus" id="session-minus" type="button">-</button>
    </div>
    <div class="break-settings">
      <span class="settings-headers">break time</span>
      <span id="break-time"></span>
      <button class="settings-btn-plus" id="break-plus" type="button">+</button>
      <button class="settings-btn-minus" id="break-minus" type="button">-</button>
    </div>
    <div class="operations">
      <button type="button" class="operation-btn" id="start">start</button>
<!--       <button type="button" class="operation-btn" id="pause">pause</button> -->
      <button type="button" class="operation-btn" id="stop">stop</button>
    </div>
  </div>
  <div class="footer">&copyjulsmorozova</div>
</div>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
}

body {
  height: 100vh;
  width: 100%;
  margin: 0;
  display: flex;
  justify-content: center;
  font-family: Tahoma, Verdana, sans-serif;
  color: #777;
  background-color: #0E1826;
}

button {
  outline: none;
  border: none;
  min-width: 2rem;
  min-height: 2rem;
  background: none;
  color: #777;
  font-size: 1.7rem;
  margin: 0.3rem;
  &:hover {
    color: #64D7DB;
  }
}

.hidden {
  display: none;
}

.container {
  padding: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
}

.circle {
  width: 15rem;
  height: 15rem;
  min-height: 15rem;
  background-color: #64D7DB;
  border: 0.125rem solid #b0b0b0;
  border-radius: 50%;
  margin: 2rem 0 1rem;
  color: #4097B2;
  font-size: 3rem;
  display: flex;
  position: relative;
  justify-content: center;
  align-items: center;
  &.total-progress {
    background-image:
        linear-gradient(90deg, transparent 50%, #0E1826 50%),
        linear-gradient(90deg, #0E1826 50%, transparent 50%);
  }
  .seconds {
    border-radius: 50%;
    background-color: #BFD7EA;
    width: 90%;
    height: 90%;
    display: flex;
    justify-content: center;
    align-items: center;
    &.progress {
      background-image:
          linear-gradient(90deg, transparent 50%, #0E1826 50%),
          linear-gradient(90deg, #0E1826 50%, transparent 50%);
    }
  }
}

.middle {
  border-radius: 50%;
  background-color: #0E1826;
  width: 90%;
  height: 90%;
  display: flex;
  justify-content: center;
  align-items: center;
}

#time-status {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  #timer-type{
    width: 100%;
    text-align: center;
    margin: -1.3rem 0 0.5rem;
    font-size: 1.3rem;
    color: #777;
  }
}

.settings {
  width: 60%;
  margin: 1rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  .session-settings, .break-settings {
    width: 45%;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    .settings-headers, #session-time, #break-time {
      width: 100%;
      text-align: center;
      margin: 0.5rem;
    }
    #session-time, #break-time {
      font-size: 1.6rem;
      color: #4097B2;
    }
  }
}

.operations {
  margin: 1rem;
  width: 100%;
  display: flex;
  justify-content: center;
  button {
    margin: 0.5rem;
    width: 4rem;
    height: 2rem;
    line-height: 1.8rem;
    font-size: 0.9rem;
    color: #BFD7EA;
    background-color: #777;
    &:hover {
      opacity: 0.5;
    }
  }
}

.footer {
  height: 2rem;
  line-height: 2rem;
  width: 100%;
  display: flex;
  justify-content: flex-start;
  padding: 0 1.5rem;
  margin: 1rem 0 0;
}
              
            
!

JS

              
                var increaseButtons = document.querySelectorAll('.settings-btn-plus');
var decreaseButtons = document.querySelectorAll('.settings-btn-minus');
var startBtn = document.querySelector("#start");
var stopBtn = document.querySelector("#stop");
var sessionTimeBlock = document.querySelector("#session-time");
var breakTimeBlock = document.querySelector("#break-time");
var timeStatusBlock = document.querySelector("#time-status");
var hoursSpan = document.querySelector("#hours-left");
var minSpan = document.querySelector("#min-left");
var secSpan = document.querySelector("#sec-left");
var timerTypeName = document.querySelector("#timer-type");
var totalProgress = document.querySelector(".total-progress");
var secondsProgress = document.querySelector(".progress");

var timer = '';//below used for setInterval/clearInterval
var timerActive = false;
var timerType = 'session';//is then changed to break
var startTime = 1500; //start of the session: session time by default
var sessionTime = 1500;//default session time stored in seconds
var breakTime = 300; //default break time stored in seconds;
var currentTime = 1500; //time displayed on timer in seconds

function displayDefaultTime() {
  sessionTimeBlock.innerHTML = displayMinutes(sessionTime) + ' min';
  breakTimeBlock.innerHTML = displayMinutes(breakTime) + ' min';
  displayCurrentTime();
}

function handleTotalProgress(startTime, currentTime) {
  var progressColor = '';
  if (timerType === 'session') {
      progressColor = '#64D7DB';
      totalProgress.style.backgroundColor = '#64D7DB';
    }
    else {
      progressColor = '#A75ACE';
      totalProgress.style.backgroundColor = '#A75ACE';
    }
  var timePassed = startTime - currentTime;
  var deg;
  if (timePassed < (startTime / 2)) {
    deg = 90 + (360 * timePassed / startTime)
    totalProgress.style.backgroundImage = 'linear-gradient('+deg+'deg, transparent 50%, #0E1826 50%),linear-gradient(90deg, #0E1826 50%, transparent 50%)';
  }
  else if (timePassed >= (startTime / 2)) {
    deg = -90 + (360 * timePassed / startTime);
    totalProgress.style.backgroundImage = 'linear-gradient('+deg+'deg, transparent 50%, '+progressColor+' 50%),linear-gradient(90deg, #0E1826 50%, transparent 50%)';
  }
}

function handleSecondsProgress(currentTime) {
  var progressBarColor = '';
  if (timerType === 'session') {
    progressBarColor = '#BFD7EA';
    secondsProgress.style.backgroundColor = '#BFD7EA';
  }
  else {
    progressBarColor = '#F9EDF9';
    secondsProgress.style.backgroundColor = '#F9EDF9';
  }
  var secondsPassed = 60 - convertFromSec(currentTime).seconds;
  var deg;
  if (secondsPassed < (60 / 2)) {
    deg = 90 + (360 * secondsPassed / 60)
    secondsProgress.style.backgroundImage = 'linear-gradient('+deg+'deg, transparent 50%, #0E1826 50%),linear-gradient(90deg, #0E1826 50%, transparent 50%)';
  }
  else if (secondsPassed >= (60 / 2)) {
    deg = -90 + (360 * secondsPassed / 60);
    secondsProgress.style.backgroundImage = 'linear-gradient('+deg+'deg, transparent 50%, '+progressBarColor+' 50%),linear-gradient(90deg, #0E1826 50%, transparent 50%)';
  }
}

function displayCurrentTime() {
  if (convertFromSec(currentTime).hours) {
    hoursSpan.classList.remove('hidden');
    hoursSpan.innerHTML = convertFromSec(currentTime).hours + ': ';
  } 
  else {
    hoursSpan.innerHTML = '';
  }
  minSpan.innerHTML = convertFromSec(currentTime).minutes + ': ';
  secSpan.innerHTML = convertFromSec(currentTime).seconds;
}

function addLeadingZero(time) {
  return time < 10? '0' + time : time;
}

function displayMinutes(timeInSec) {
  return parseInt(timeInSec / 60);
}

function convertFromSec(timeInSec) {
  var result = { hours: 0, minutes: 0, seconds: 0 };
  var seconds = timeInSec % 60;
  var minutes = parseInt(timeInSec / 60) % 60;
  var hours = parseInt(timeInSec / 3600);
  if (hours > 0) {
    result.hours = hours;
  }
  result.minutes = addLeadingZero(minutes);
  result.seconds = addLeadingZero(seconds);
  return result;
}

function countDown() {
  timerTypeName.innerHTML = timerType;
  if (currentTime > 0) {
    currentTime --;
    displayCurrentTime();
    handleTotalProgress(startTime, currentTime);
    handleSecondsProgress(currentTime);
    if (currentTime === 0) {
      if (timerType === 'session') {
        currentTime = breakTime;
        startTime = breakTime;
        timerType = 'break';
        timerTypeName.innerHTML = timerType;
      }
      else {
        currentTime = sessionTime;
        startTime = sessionTime;
        timerType = 'session';
        timerTypeName.innerHTML = timerType;
      }
    }
  }
}

function toggleTimer() {
  if (timerActive) {
    clearInterval(timer);
    startBtn.innerHTML = 'start';
    timerActive = false;
  }
  else {
    startBtn.innerHTML = 'pause';
    timer = setInterval(countDown, 1000);
    timerActive = true;
  }
}

function stopTimer() {
  timerActive = false;
  startBtn.innerHTML = 'start';
  clearInterval(timer);
  timerType = 'session';
  currentTime = sessionTime;
  handleTotalProgress(startTime, currentTime);
  handleSecondsProgress(currentTime);
  displayDefaultTime();
}

function displayChangedTime(e, time) {
  if (e.target.id === 'session-plus' || e.target.id === 'session-minus') {
    sessionTimeBlock.innerHTML = displayMinutes(sessionTime) + ' min';
  }
  else if (e.target.id === 'break-plus' || e.target.id === 'break-minus') {
    breakTimeBlock.innerHTML = displayMinutes(breakTime) + ' min';
  }
}

startBtn.addEventListener('click', toggleTimer);
stopBtn.addEventListener('click', stopTimer);

for (var i = 0; i < increaseButtons.length; i++) {
  increaseButtons[i].addEventListener('click', function(e) {
    if (!timerActive) {
      if (e.target.id === 'session-plus') {
        sessionTime += 60;
        currentTime = sessionTime;
        startTime = sessionTime;
        displayChangedTime(e, sessionTime);
        displayCurrentTime();
      }
      else if (e.target.id === 'break-plus') {
        breakTime += 60;
        displayChangedTime(e, breakTime);
        displayCurrentTime();
      }
    }
  });
} 

for (var i = 0; i < decreaseButtons.length; i++) {
  decreaseButtons[i].addEventListener('click', function(e) {
    if (!timerActive) {
      if (e.target.id === 'session-minus') {
        if (sessionTime > 60) {
          sessionTime -= 60;
          currentTime = sessionTime;
          startTime = sessionTime;
          displayChangedTime(e, sessionTime);
          displayCurrentTime();
        }
      }
      else if (e.target.id === 'break-minus') {
        if (breakTime > 60) {
          breakTime -= 60;
          displayChangedTime(e, breakTime);
          displayCurrentTime();
        }
      }
    }
  });
} 

document.addEventListener('DOMContentLoaded', displayDefaultTime);
              
            
!
999px

Console