Pen Settings

HTML

CSS

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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

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.

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

              
                <!-- 
This webpage will alert a message when added pomodoro breaktimes and back to work times is equal to the system time.
This code was assembled and written by Claive Alvin P. Acedilla. It can be copied, modified and redistributed.
November 2019
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">-->

<!DOCTYPE html>
<html>
<head>
  <style>  
  label
  {
    font-size: x-large;
  }

  input
  {
    height: 40px;
    font-size: large;
    box-sizing: border-box;
  }
  </style>
    <meta http-equiv="refresh" content="59">
    <meta http-equiv="Content-type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Send Pomodoro alarm</title>
</head>
<body>
<h1>Pomodoro work life balance</h1>
<div>
  <label for="startTime">Start time:</label>
  <input type="time" id="startTime" value="08:00" required />
  <input type="button" value="Current time" onclick="autoPopulateStartTimeCurrentTime()" />
</div>
  <br>
<div>
  <label for="endTime">End time:</label>
  <input type="time" id="stopTime" value="17:00" required />
  <input type="button" value="Current time" onclick="autoPopulateStopTimeCurrentTime()" />
</div>
<br>
<div>
  <label for="workInterval">Work interval:</label>
  <input type="number" size="4" min="5" max="720" step="5" value="25" id="workInterval" required />
</div>
<br>
<div>
  <label for="breakInterval">Break interval:</label>
  <input type="number" size="4" min="5" max="720" step="5" value="5" id="breakInterval" required />
</div>
<br>
<div>
  <input type="button" value="Add work and break intervals" onclick="addBreakResumeTimes()">
</div>
<br> 
<br>            
<input type="button" value="Show break times" onclick="showBreakTimes()"> <input type="button" value="Show resume times" onclick="showResumeTimes()">
<br> 
<br> 	
<p>Note:<br> When the first entered time arrives, a 'pop-up is blocked' notification will appear on the right corner of the address bar. 
Click on the notification and select 'Always allow..'. Click the Ok button. The break and resume time alert message will be displayed 
every time a break or resume time arrives.
</p>	
<p>
You may also add your break and resume to work times one by one in a 12-hour format like "8:25 AM".<br>
Or you may also add multiple break and resume times in a 12-hour format separated by commas like "8:25 AM, 8:55 AM, 9:25 AM, ... 8:30 AM, 9:00 AM, 9:30 AM, ...,"
</p>	
<h3> Break from work time:</h3>
<input type="text" id="breakInputField" size="70" value="8:25 AM, 8:55 AM, 9:25 AM, ...," onclick="breakInputFieldClick()"> 
<input type="button" value="Add" onclick="addBreakFromWorkTimes()">
	
<h3> Resume to work time:</h3>
<input type="text" id="backToWorkInputField" size="70" value="8:30 AM, 9:00 AM, 9:30 AM, ...," onclick="backToWorkInputFieldClick()"> 
<input type="button" value="Add" onclick="addbackToWorkTimes()">
<br> 
<br>
<input type="button" value="Show break times" onclick="showBreakTimes()"> <input type="button" value="Show resume times" onclick="showResumeTimes()">       
<br>
<br>            
<h4> Delete an unneeded 'break from work' time:</h4> Enter the number of nth break time that you want to delete starting from the top left in the break times list. <input type="button" value="Show break times" onclick="showBreakTimes()">
<br>
<br>
<input type="number" id="breakTimeIndex" size="3" onclick="breakTimeIndexClick()" min="1" max="99">
<input type="button" value="Delete" onclick="deletePomodoroTime()">
<br>
<br>	
<h4> Delete an unneeded 'resume to work' time:</h4> Enter the number of nth resume time that you want to delete starting from the top left in the resume times list. <input type="button" value="Show resume times" onclick="showResumeTimes()">
<br>
<br> 
<input type="number" id="resumeTimeIndex" size="3" onclick="resumeTimeIndexClick()" min="1" max="99">
<input type="button" value="Delete" onclick="deleteBackToWorkTime()">
<br> 
<br>	
<h4>Clear all break and resume times:</h4> <input type="button" value="Clear break times" onclick="clearBreakTimes()"> <input type="button" value="Clear resume times" onclick="clearResumeTimes()">
    
<script type="text/javascript">	
window.onbeforeunload = function()
{
  window.scrollTo(0, 0);
};
  
let breakFromWorkArray = [];
let backToWorkArray = [];
let breakFromWorkTimes; // Break from work times input	
let backToWorkTimes; //  Resume to work times input
let breakTimeString; // Convert breakTime to string to compare to currentTime
let resumeTimeString; // Convert resumeTime to string to compare to currentTime
let currentTime;

//Convert time to string in hour and minute.		
currentTime = String(new Date().toLocaleTimeString("en-US",
{
  hour12: true,
  hour: "numeric",
  minute: "numeric"
}));

if (localStorage.getItem("breakFromWorkTimes") !== null)
{
  breakFromWorkArray = JSON.parse(localStorage.getItem("breakFromWorkTimes"));
}
if (localStorage.getItem("backToWorkTimes") !== null)
{
  backToWorkArray = JSON.parse(localStorage.getItem("backToWorkTimes"));
}
loopArray(breakFromWorkArray, backToWorkArray);

function toTimeString(dateObj)
{
  return dateObj.toLocaleTimeString("en-US",
  {
    hour12: true,
    hour: "numeric",
    minute: "numeric"
  });
}

function autoPopulateStartTimeCurrentTime()
{
  let newDate = new Date();
  let currentTimeStartTime = new Date();
  let currentTimeStartTimeString;
  let currentHours;
  let currentMinutes;
  currrentHours = newDate.getHours();
  currentMinutes = newDate.getMinutes();
  currentTimeStartTime.setHours(currrentHours, currentMinutes);
  currentTimeStartTimeString = currentTimeStartTime.toTimeString();
  currentTimeStartTimeString = currentTimeStartTimeString.split(" ");
  currentTimeStartTimeString = currentTimeStartTimeString[0];
  currentTimeStartTimeString = currentTimeStartTimeString.substring(0, currentTimeStartTimeString.length - 3);
  document.getElementById("startTime").value = currentTimeStartTimeString;
}

function autoPopulateStopTimeCurrentTime()
{
  let newDate = new Date();
  let currentTimeStartTime = new Date();
  let currentTimeStartTimeString;
  let currentHours;
  let currentMinutes;
  currrentHours = newDate.getHours();
  currentMinutes = newDate.getMinutes();
  currentTimeStartTime.setHours(currrentHours, currentMinutes);
  currentTimeStartTimeString = currentTimeStartTime.toTimeString();
  currentTimeStartTimeString = currentTimeStartTimeString.split(" ");
  currentTimeStartTimeString = currentTimeStartTimeString[0];
  currentTimeStartTimeString = currentTimeStartTimeString.substring(0, currentTimeStartTimeString.length - 3);
  document.getElementById("stopTime").value = currentTimeStartTimeString;
}

function addBreakResumeTimes()
{
  let resumeInterval = document.getElementById("breakInterval").value;
  let resumeDuration = parseFloat(resumeInterval);
  let workInterval = document.getElementById("workInterval").value;
  let breakDuration = parseFloat(workInterval);
  let breakTime = new Date();
  let breakHours;
  let breakMinutes;
  let resumeTime = new Date();
  let resumeHours;
  let resumeMinutes;
  let startTime;
  let startTimeObject = new Date();
  let stopTime;
  let stopTimeObject = new Date();
  
  startTime = document.getElementById("startTime").value;
  stopTime = document.getElementById("stopTime").value;
  if (startTime == "" || stopTime == "" || resumeInterval == "" || workInterval == "")
  {
    alert("Please enter a start time, a stop time, a break time interval and a resume to work time interval.");
    return;
  }
  startTime = startTime.substring(0, 5);
  startTime = startTime.split(":");
  startTimeObject.setHours(startTime[0], startTime[1]);
  breakMinutes = startTimeObject.getMinutes();
  breakHours = startTimeObject.getHours();
  breakTime.setHours(breakHours, breakMinutes);
  resumeHours = startTimeObject.getHours();
  resumeMinutes = startTimeObject.getMinutes();
  resumeTime.setHours(resumeHours, resumeMinutes);
  stopTime = stopTime.substring(0, 5);
  stopTime = stopTime.split(":");
  stopTimeObject.setHours(stopTime[0], stopTime[1]);
  if (breakTime > stopTimeObject && resumeTime > stopTimeObject)
  {
    let newStartTimeObject = new Date();
    newStartTimeObject.setHours(24, 0);
    breakMinutes = newStartTimeObject.getMinutes();
    breakHours = newStartTimeObject.getHours();
    breakTime.setHours(breakHours, breakMinutes);
    resumeHours = newStartTimeObject.getHours();
    resumeMinutes = newStartTimeObject.getMinutes();
    resumeTime.setHours(resumeHours, resumeMinutes);
    while (breakTime < stopTimeObject && resumeTime < stopTimeObject)
    {
      breakMinutes = resumeMinutes + breakDuration;
      /* if (breakMinutes == 0)
      {
      	breakMinutes = resumeMinutes + breakDuration;					
      }	 */
      breakTime.setHours(breakHours, breakMinutes);
      resumeMinutes = breakMinutes + resumeDuration;
      resumeTime.setHours(resumeHours, resumeMinutes);
      breakTimeString = toTimeString(breakTime);
      breakFromWorkTimes = breakTimeString;
      breakFromWorkArray.push(breakFromWorkTimes);
      resumeTimeString = toTimeString(resumeTime);
      backToWorkTimes = resumeTimeString;
      backToWorkArray.push(backToWorkTimes);
    }
    breakFromWorkArray.sort(function(a, b) {
        return new Date('1970/01/01 ' + a) - new Date('1970/01/01 ' + b);
    });
    backToWorkArray.sort(function(a, b) {
        return new Date('1970/01/01 ' + a) - new Date('1970/01/01 ' + b);
    });
    localStorage.setItem("breakFromWorkTimes", JSON.stringify(breakFromWorkArray));
    localStorage.setItem("backToWorkTimes", JSON.stringify(backToWorkArray));
    breakMinutes = startTimeObject.getMinutes();
    breakHours = startTimeObject.getHours();
    breakTime.setHours(breakHours, breakMinutes);
    resumeHours = startTimeObject.getHours();
    resumeMinutes = startTimeObject.getMinutes();
    resumeTime.setHours(resumeHours, resumeMinutes);
    stopTimeObject.setHours(23, 59);
    while (breakTime < stopTimeObject && resumeTime < stopTimeObject)
    {
      breakMinutes = resumeMinutes + breakDuration;
      /* if (breakMinutes == 0)
      {
      	breakMinutes = resumeMinutes + breakDuration;					
      }	 */
      breakTime.setHours(breakHours, breakMinutes);
      resumeMinutes = breakMinutes + resumeDuration;
      resumeTime.setHours(resumeHours, resumeMinutes);
      breakTimeString = toTimeString(breakTime);
      breakFromWorkTimes = breakTimeString;
      breakFromWorkArray.push(breakFromWorkTimes);
      resumeTimeString = toTimeString(resumeTime);
      backToWorkTimes = resumeTimeString;
      backToWorkArray.push(backToWorkTimes);
    }
    backToWorkArray.pop(backToWorkTimes);
     breakFromWorkArray.sort(function(a, b) {
        return new Date('1970/01/01 ' + a) - new Date('1970/01/01 ' + b);
    });
    backToWorkArray.sort(function(a, b) {
        return new Date('1970/01/01 ' + a) - new Date('1970/01/01 ' + b);
    });
    localStorage.setItem("breakFromWorkTimes", JSON.stringify(breakFromWorkArray));
    localStorage.setItem("backToWorkTimes", JSON.stringify(backToWorkArray));
    alert("Break and resume time intervals were added.");
  }
  else
  {
    while (breakTime < stopTimeObject && resumeTime < stopTimeObject)
    {
      breakMinutes = resumeMinutes + breakDuration;
      /* if (breakMinutes == 0)
      {
      	breakMinutes = resumeMinutes + breakDuration;					
      }	 */
      breakTime.setHours(breakHours, breakMinutes);
      resumeMinutes = breakMinutes + resumeDuration;
      resumeTime.setHours(resumeHours, resumeMinutes);
      breakTimeString = toTimeString(breakTime);
      breakFromWorkTimes = breakTimeString;
      breakFromWorkArray.push(breakFromWorkTimes);
      resumeTimeString = toTimeString(resumeTime);
      backToWorkTimes = resumeTimeString;
      backToWorkArray.push(backToWorkTimes);
    }
    backToWorkArray.pop(backToWorkTimes);
     breakFromWorkArray.sort(function(a, b) {
        return new Date('1970/01/01 ' + a) - new Date('1970/01/01 ' + b);
    });
    backToWorkArray.sort(function(a, b) {
        return new Date('1970/01/01 ' + a) - new Date('1970/01/01 ' + b);
    });
    localStorage.setItem("breakFromWorkTimes", JSON.stringify(breakFromWorkArray));
    localStorage.setItem("backToWorkTimes", JSON.stringify(backToWorkArray));
    alert("Break and resume time intervals were added.");
  }
}

function addBreakFromWorkTimes()
{
  breakFromWorkTimes = document.getElementById("breakInputField").value;
  if (breakFromWorkTimes == "")
  {
    alert("Please enter a break time in 0:00 AM or PM format.");
  }
  else
  {
    let ctr = 0;
    breakFromWorkTimes = breakFromWorkTimes.split(", ");
    while (ctr < breakFromWorkTimes.length)
    {
      breakFromWorkArray.push(breakFromWorkTimes[ctr]);
      ctr = ctr + 1;
    }
	  
    breakFromWorkArray.sort(function(a, b) {
        return new Date('1970/01/01 ' + a) - new Date('1970/01/01 ' + b);
    });
    
    if (ctr == 1)
    {
      alert("Break time was added.");
    }
    else if (ctr > 1)
    {
      alert("Break times were added.");
    }
    localStorage.setItem("breakFromWorkTimes", JSON.stringify(breakFromWorkArray));
  }
}

function addbackToWorkTimes()
{
  backToWorkTimes = document.getElementById("backToWorkInputField").value;
  if (backToWorkTimes == "")
  {
    alert("Please enter a break time in 0:00 AM or PM format.");
  }
  else
  {
    let ctr = 0;
    backToWorkTimes = backToWorkTimes.split(", ");
    while (ctr < backToWorkTimes.length)
    {
      backToWorkArray.push(backToWorkTimes[ctr]);
      ctr = ctr + 1;
    }
	  
    backToWorkArray.sort(function(a, b) {
        return new Date('1970/01/01 ' + a) - new Date('1970/01/01 ' + b);
    });
	  
    if (ctr > 1)
    {
      alert("Resume times were added.");
    }
    else if (ctr == 1)
    {
      alert("Resume time was added.");
    }
    localStorage.setItem("backToWorkTimes", JSON.stringify(backToWorkArray));
  }
}

function showBreakTimes()
{
  if (breakFromWorkArray.length == 0)
  {
    alert("Break times is empty. Please add break times.");
  }
  else
  {
    alert(breakFromWorkArray);
  }
}

function showResumeTimes()
{
  if (backToWorkArray.length == 0)
  {
    alert("Resume times is empty. Please add resume times");
  }
  else
  {
    alert(backToWorkArray);
  }
}

function deletePomodoroTime()
{
  let ctr = document.getElementById("breakTimeIndex").value;
  if (breakFromWorkArray.length == 0)
  {
    alert("Break times is empty");
    return;
  }
  if (ctr == "")
  {
    alert("Enter the number of nth resume time starting from the top left in the resume times list.");
  }
  else
  {
    let index = parseFloat(ctr);
    breakFromWorkArray.splice(index - 1, 1);
    breakFromWorkTimes = breakFromWorkArray;
    localStorage.setItem("breakFromWorkTimes", JSON.stringify(breakFromWorkArray));
    alert("Break time was cleared.");
  }
}

function deleteBackToWorkTime()
{
  let ctr = document.getElementById("resumeTimeIndex").value;
  if (backToWorkArray.length == 0)
  {
    alert("Break times is empty");
    return;
  }
  if (ctr == "")
  {
    alert("Enter the number of nth resume time starting from the top left in the resume times list.");
  }
  else
  {
    let index = parseFloat(ctr);
    backToWorkArray.splice(index - 1, 1);
    backToWorkTimes = backToWorkArray;
    localStorage.setItem("backToWorkTimes", JSON.stringify(backToWorkArray));
    alert("Resume time was cleared.");
  }
}

function clearBreakTimes()
{
  while (breakFromWorkArray.length)
  {
    while (breakFromWorkArray.length > 0)
    {
      localStorage.removeItem("breakFromWorkTimes");
      breakFromWorkArray = [];
    }
    alert("Break times were cleared.");
    return;
  }
  if (breakFromWorkArray.length == 0)
  {
    alert("Break times is empty. Please add resume times.");
  }
}

function clearResumeTimes()
{
  while (backToWorkArray.length)
  {
    while (backToWorkArray.length > 0)
    {
      localStorage.removeItem("backToWorkTimes");
      backToWorkArray = [];
    }
    alert("Resume times were cleared.");
    return;
  }
  if (backToWorkArray.length == 0)
  {
    alert("Resume times is empty. Please add resume times.");
  }
}

function showPopupBlocked()
{
   setTimeout(function()
   {
      document.title = "Pop-up blocked";
      alert("Pop-up was blocked.  Click on the pop-up blocker and allow pop-ups to display the break and resume to work notifications.");
   }, 2000);
}

function showAlarmWindow(pageURL, pageTitle, popupWinWidth, popupWinHeight, message) 
{  
   let left;
   let top;
   let breakAlarmWindow;
   let resumeAlarmWindow;
      
   left = (screen.width - popupWinWidth) / 2; 
   top = (screen.height - popupWinHeight) / 4; 
   
   if (pageTitle == "Break Time")
   {
      breakAlarmWindow = window.open("", pageTitle, 'width=' + popupWinWidth + ', height=' + popupWinHeight + ', top=' + top + ', left=' + left); 
      
      if (!breakAlarmWindow || breakAlarmWindow.closed || typeof breakAlarmWindow.closed == "undefined")
      {
         showPopupBlocked();
      }      
      breakAlarmWindow.document.write(message);
      breakAlarmWindow.focus();
      setTimeout(function()
      {
        breakAlarmWindow.close();
      }, 50000);
   }
   if (pageTitle == "Resume Time")
   {
      resumeAlarmWindow = window.open("", pageTitle, 'width=' + popupWinWidth + ', height=' + popupWinHeight + ', top=' + top + ', left=' + left);       
      if (!resumeAlarmWindow|| resumeAlarmWindow.closed || typeof resumeAlarmWindow.closed == "undefined")
      {
         showPopupBlocked();
      }
      resumeAlarmWindow.document.write(message);
      resumeAlarmWindow.focus();
      setTimeout(function()
      {
        resumeAlarmWindow.close();
      }, 50000);
   }
} 
        
function loopArray(breakFromWorkArray, backToWorkArray)
{
  let breakMessage;
  let resumeMessage;
  let ctr = 0;
  
  //Loop the arrays while breakFromWorkArray is not equal to currentTime or backToWorkArray is not equal to currentTime
  while (breakFromWorkArray[ctr] != currentTime || backToWorkArray[ctr] != currentTime)
  {
    // If pomodoro time is equal to current time, alarm for pomodoro with alarmWindow-up message		
    if (breakFromWorkArray[ctr] == currentTime)
    {
      breakMessage = "<p>Time for a break because it is now " + breakFromWorkArray[ctr] + ".";
      showAlarmWindow("", "Break Time", 500, 50, breakMessage);
      break;
    }
    // If back to work time is equal to current time, alarm for back to work with alarmWindow-up message    			
    if (backToWorkArray[ctr] == currentTime)
    {
      resumeMessage = "<p>Time to resume to work because it is now " + backToWorkArray[ctr] + ".";
      showAlarmWindow("", "Resume Time", 550, 50, resumeMessage);
      break;
    }
    //break from the ctr if the iteration reach the last elements of the pomodoro and back to work time arrays
    if (breakFromWorkArray[ctr] == breakFromWorkArray[breakFromWorkArray.length] && backToWorkArray[ctr] == backToWorkArray[backToWorkArray.length])
    {
      break;
    }
    //increment ctr count
    ctr = ctr + 1;
  }
}
</script>		
</body>
</html>

              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console