no more mr nice countdown

This commit is contained in:
That_One_Nerd 2023-05-03 19:39:27 -04:00
parent cebd94c3cb
commit 3c781b4265
2 changed files with 0 additions and 68 deletions

View File

@ -89,5 +89,4 @@
<script type="module" src="js/imports.js"></script>
<script src="js/global.js" defer></script>
<script src="js/index.js" defer></script>
</html>

View File

@ -1,67 +0,0 @@
const title = document.getElementById("title");
// This is for the AP exam timer.
const examStart = new Date("May 3, 2023 12:00");
const examEnd = new Date("May 3, 2023 15:30");
const examElement = document.createElement("h3");
const examLink = document.createElement("a");
examElement.append(examLink);
examLink.href = "/news/ap-exam.html";
examLink.id = "ap-timer";
examLink.target = "_blank";
if (title != undefined)
{
// Add the newly created AP exam countdown element.
title.append(examElement);
// Enable the AP exam countdown.
updateCountdown();
setInterval(updateCountdown, 1000);
}
function updateCountdown()
{
// Difference between now and the desired date in milliseconds.
const now = new Date(Date.now());
var mode = "waiting";
var difference = examStart - now;
if (difference < 0)
{
difference = examEnd - now;
mode = "doing";
}
if (difference < 0)
{
difference = -difference;
mode = "done";
}
// Get minutes and seconds from decimal hours.
var deciHours = difference / (1000 * 60 * 60);
var deciMinutes = (deciHours % 1) * 60;
var deciSeconds = (deciMinutes % 1) * 60;
var hours = Math.floor(deciHours);
var minutes = Math.floor(deciMinutes);
var seconds = Math.floor(deciSeconds);
// Construct string and assign it.
var string = `${hours}:${("0" + minutes).slice(-2)}:${("0" + seconds).slice(-2)}`;
switch (mode)
{
case "waiting":
string += " until the AP exam begins!";
break;
case "doing":
string += " until the AP exam ends!";
break;
case "done":
string += " since the AP exam has been completed!";
break;
}
examLink.textContent = string;
}