JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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">
<div class="row">
<div class="col-xs-12">
<div id="timerTitle">Pomodoro Timer</div>
</div>
</div>
<div class="row">
<div id="pomDisplayBox" class="col-xs-12 col-md-2 col-md-offset-5">
<div id="pomDisplay">0m 0s</div>
</div>
</div>
<div class="row">
<div class="col-xs-4 col-xs-offset-4">
<input id="pomInput" type="number" value="0" max="99" min="0">
<label for="pomInput">Pom Time (Minutes)</label>
</div>
</div>
<div class="row">
<div class="col-xs-4 col-xs-offset-4">
<input id="breakInput" type="number" value="0">
<label for="breakInput">Break Time (Minutes)</label>
</div>
</div>
<div class="row buttonRow">
<div class="col-xs-12 col-md-3 col-md-offset-4">
<button class="btn btn-primary" id="startButton">Start</button>
<button class="btn btn-warning" id="pauseButton">Pause</button>
<button class="btn btn-danger" id="clearButton">Clear</button>
</div>
</div>
</div>
#timerTitle {
font-family: 'Raleway', sans-serif;
font-size: 36px;
color: #5b5b5b;
text-align: center;
margin: 3%;
}
#pomInput, #breakInput{
width: 30%;
float: left;
margin: 20px 10px 5px 40px;
border-style: solid;
border-width: 1px;
border-radius: 5%;
text-align: center;
font-size: 22px;
}
label {
color: #919191;
font-family: 'Raleway', sans-serif;
font-size: 16px;
padding-top: 7%;
float: left;
}
button {
font-family: 'Raleway', sans-serif;
margin: 5% 1%;
}
.buttonRow {
margin-top: 2%;
margin-left: 9%;
}
#minutes {
float: left;
padding: .5% 2%;
}
#pomDisplayBox {
border: solid;
border-width: 1px;
border-color: #ccc;
border-radius: 50%;
height: 200px;
width: 200px;
margin-bottom: 2%;
}
#pomDisplay {
font-family: 'Raleway', sans-serif;
font-size: 36px;
text-align: center;
padding-top: 40%;
}
var pause = false;
var clear = false;
var interval;
var startButton, pauseButton, clearButton, pomInput, breakInput, pomDisplay;
window.onload = function() {
startButton = document.querySelector("#startButton");
pauseButton = document.querySelector("#pauseButton");
clearButton = document.querySelector("#clearButton");
pomInput = document.querySelector("#pomInput");
breakInput = document.querySelector("#breakInput");
pomDisplay = document.querySelector("#pomDisplay");
startButton.addEventListener("click", startFunc);
pauseButton.addEventListener("click", pauseFunc);
clearButton.addEventListener("click", clearFunc);
}
function breakFunc() {
startButton.innerHTML = "Start";
startButton.disabled = true;
pomInput.readOnly = true;
var breakInputTime = breakInput.value * 60000;
var currentTime = new Date().getTime();
var pomEnd = currentTime + breakInputTime;
interval = setInterval (function() {
if (!pause) {
//figure out, in milliseconds, the difference between current time and the end point for your timer
currentTime = new Date().getTime();
pomTime = pomEnd - currentTime;
//do the math to display minutes and seconds properly
var minutes = Math.floor((pomTime % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((pomTime % (1000 * 60)) / 1000);
//if there is still time on the clock, display it. If not, send a message.
if (pomTime > 0) {
pomDisplay.innerHTML = minutes + "m " + seconds + "s ";
} else if (pomTime <= 0) {
pomDisplay.innerHTML = "Done!";
return;
}
}
}, 1000);
}
function startFunc() {
startButton.innerHTML = "Start";
startButton.disabled = true;
pomInput.readOnly = true;
var pomInputTime = pomInput.value * 60000;
var currentTime = new Date().getTime();
var pomEnd = currentTime + pomInputTime;
interval = setInterval (function() {
if (!pause) {
//figure out, in milliseconds, the difference between current time and the end point for your timer
currentTime = new Date().getTime();
pomTime = pomEnd - currentTime;
//do the math to display minutes and seconds properly
var minutes = Math.floor((pomTime % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((pomTime % (1000 * 60)) / 1000);
//if there is still time on the clock, display it. If not, send a message.
if (pomTime > 0) {
pomDisplay.innerHTML = minutes + "m " + seconds + "s ";
} else if (pomTime <= 0) {
breakFunc();
return;
}
}
}, 1000);
}
function pauseFunc() {
pause = !pause;
if (pause) {
pauseButton.innerHTML = "Resume";
} else if (!pause) {
pauseButton.innerHTML = "Pause";
}
}
function clearFunc() {
clearInterval(interval);
pomInput.value = 0;
pomDisplay.innerHTML = "0m 0s";
startButton.innerHTML = "Start";
startButton.disabled = false;
pomInput.readOnly = false;
}
Also see: Tab Triggers