Pomodoro Timer

Developer
Size
3,706 Kb
Views
8,096

How do I make an pomodoro timer?

A pomodoro timer for freeCodeCamp Zipline. Uses Bootstrap and vanilla Javascript.. What is a pomodoro timer? How do you make a pomodoro timer? This script and codes were developed by Zac Clemans on 14 January 2023, Saturday.

Pomodoro Timer Previews

Pomodoro Timer - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Pomodoro Timer</title> <link rel='stylesheet prefetch' href='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css'>
<link rel='stylesheet prefetch' href='http://cdnjs.cloudflare.com/ajax/libs/animate.css/3.2.3/animate.min.css'> <link rel="stylesheet" href="css/style.css">
</head>
<body> <head> <title>Pomodoro Timer</title> <link href='https://fonts.googleapis.com/css?family=Lobster' rel='stylesheet' type='text/css' />
</head>
<div class="container text-center main"> <h1>Pomodoro Timer</h1> <div class="container timer"> <div class="container-fluid" id="timer-message"> Pomodoro Time! </div> <div class="middle-aligner"></div> <div class="container-fluid" id="time-remaining"> 25:00 </div> <div class="bottom-aligner"></div> <div class="container-fluid btn-container"> <button type="button" class="btn btn-default start-btn" id="start-pause-btn" onclick="runTimer(); changeToPauseButton();"> <span class="glyphicon glyphicon-play"></span> Start </button> <button type="button" class="btn btn-default reset-btn" id="reset-btn" onclick="resetTimer();"> <span class="glyphicon glyphicon-repeat"></span> Reset </button> </div> </div> <button type="button" class="btn btn-info btn-lg options-btn" data-toggle="modal" data-target="#options-modal">Timer Options</button> <div id="options-modal" class="modal fade" role="dialog"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h4>Timer Options</h4> </div> <div class="modal-body"> <h4 class="timer-options-header">Session Timer Length (minutes)</h4> <div class="row"> <div class="col-sm-1"> <label id="session-label">25</label> </div> <div class="col-sm-11"> <input id="session-value" name="session-value" type="range" min="0" max="60" value="25" onchange="updateSessionLabel(); updateSessionValue();" /> </div> </div> <h4 class="timer-options-header">Break Timer Length (minutes)</h4> <div class="row"> <div class="col-sm-1"> <label id="break-label">5</label> </div> <div class="col-sm-11"> <input id="break-value" name="break-value" type="range" min="0" max="20" value="5" onchange="updateBreakLabel(); updateBreakValue();" /> </div> </div> <!--End--> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> </div> </div> </div> </div>
</div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js'></script>
<script src='https://raw.githubusercontent.com/mckamey/countdownjs/master/countdown.js'></script> <script src="js/index.js"></script>
</body>
</html>

Pomodoro Timer - Script Codes CSS Codes

body { font-family: Lobster; color: #EF4C23;
}
h1 { font-size: 5em;
}
.timer { margin-top: 20px; width: 600px; height: 600px; border: 5px solid #79C89E; border-radius: 50%;
}
.middle-aligner { display: inline-block; height: 10%;
}
.bottom-aligner { display: inline-block; height: 20%;
}
.options-btn { margin-top: 40px; margin-bottom: 40px;
}
#options-modal { margin-top: 450px;
}
#options-modal .modal-header { color: #FFFFFF; background-color: #79C89E;
}
.btn { font-size: 1.7em; color: #FFFFFF; background-color: #F26C57; opacity: 0.8; border-width: 0;
}
#timer-message { padding-top: 20%; font-size: 2em;
}
#time-remaining { font-size: 7em;
}
#session-label,
#break-label { font-size: 1.5em; color: #8B7D6B;
}
@media screen and (max-width: 600px) { h1 { font-size: 3em; } .timer { width: 300px; height: 300px; } #timer-message { padding-top: 15%; font-size: 1.5em; } #time-remaining { font-size: 4em; } .btn { font-size: 1em; } #options-modal { margin-top: 50px; } .bottom-aligner { height: 15%; }
}

Pomodoro Timer - Script Codes JS Codes

var sessionTimeLeft = 1500;
var breakTimeLeft = 300;
var timerIsRunning = false;
var timerIsPaused = false;
var alarm = new Audio("https://s3-us-west-2.amazonaws.com/s.cdpn.io/41203/beep.mp3");
function runTimer() { if (!timerIsRunning) { timerIsRunning = true; timerIsPaused = false; timer = setInterval(function() { var timeLeft = createTimer(); document.getElementById("time-remaining").innerHTML = displayTime(timeLeft.minutes, timeLeft.seconds); displayTimerMessage(); soundAlarm(); if (isTimerDone()) { resetTimer(); } }, 1000); }
}
function createTimer() { now = new Date(); if (isBreakTime()) { deadline = new Date(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours(), now.getMinutes(), now.getSeconds() + breakTimeLeft); breakTimer = countdown(null, deadline); breakTimeLeft--; return breakTimer; } else { deadline = new Date(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours(), now.getMinutes(), now.getSeconds() + sessionTimeLeft); sessionTimer = countdown(null, deadline); sessionTimeLeft--; return sessionTimer; }
}
function pauseTimer() { clearInterval(timer); timerIsRunning = false; timerIsPaused = true;
}
function resetTimer() { clearInterval(timer); if (timerIsRunning) { changeToStartButton(); } timerIsRunning = false; timerIsPaused = false; sessionTimeLeft = getSessionValue(); breakTimeLeft = getBreakValue(); document.getElementById("time-remaining").innerHTML = displayTime(sessionTimeLeft / 60, 0); document.getElementById("timer-message").innerHTML = "Pomodoro Time!";
}
function isBreakTime() { if (sessionTimeLeft <= 0) { return true; } else { return false; }
}
function isTimerDone() { if (sessionTimeLeft <= 0 && breakTimeLeft <= 0) { document.getElementById("timer-message").innerHTML = "Timer Complete!"; return true; } else { return false; }
}
function displayTime(minutes, seconds) { timeOutput = ""; if (minutes < 10) { timeOutput += ('0' + minutes + ':'); } else { timeOutput += (minutes + ':'); } if (seconds < 10) { timeOutput += ('0' + seconds); } else { timeOutput += seconds; } return timeOutput;
}
function displayTimerMessage() { if (isBreakTime()) { document.getElementById("timer-message").innerHTML = "Break time!"; } else { document.getElementById("timer-message").innerHTML = "Session in progress..."; }
}
function soundAlarm() { if (sessionTimeLeft <= 0 && breakTimeLeft === getBreakValue()) { alarm.play(); } if (breakTimeLeft <= 0) { alarm.play(); }
}
function changeToPauseButton() { document.getElementById("start-pause-btn").setAttribute("onclick", "javascript: pauseTimer(); changeToStartButton();"); document.getElementById("start-pause-btn").innerHTML = '<span class="glyphicon glyphicon-pause"></span> Pause';
}
function changeToStartButton() { document.getElementById("start-pause-btn").setAttribute("onclick", "javascript: runTimer(); changeToPauseButton();"); document.getElementById("start-pause-btn").innerHTML = '<span class="glyphicon glyphicon-play"></span> Start';
}
function updateSessionLabel() { document.getElementById("session-label").innerHTML = getSessionValue() / 60;
}
function updateBreakLabel() { document.getElementById("break-label").innerHTML = getBreakValue() / 60;
}
function updateSessionValue() { if (!timerIsRunning && !timerIsPaused) { sessionTimeLeft = getSessionValue(); document.getElementById("time-remaining").innerHTML = displayTime(sessionTimeLeft / 60, 0); }
}
function updateBreakValue() { if (!timerIsRunning && !timerIsPaused) { breakTimeLeft = getBreakValue(); }
}
function getSessionValue() { return document.getElementById("session-value").value * 60;
}
function getBreakValue() { return document.getElementById("break-value").value * 60;
}
Pomodoro Timer - Script Codes
Pomodoro Timer - Script Codes
Home Page Home
Developer Zac Clemans
Username thalpha
Uploaded January 14, 2023
Rating 3
Size 3,706 Kb
Views 8,096
Do you need developer help for Pomodoro Timer?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Zac Clemans (thalpha) Script Codes
Create amazing video scripts with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!