update timer
All checks were successful
ci/woodpecker/push/deploy-rsync Pipeline was successful
ci/woodpecker/push/deploy-netlify Pipeline was successful
ci/woodpecker/push/deploy-cloudflare Pipeline was successful

This commit is contained in:
Adora Laura Kalb 2024-05-23 07:06:41 +02:00
parent 4151758ff6
commit 38783f27c2
Signed by: adoralaura
SSH key fingerprint: SHA256:3XrkbR8ikAZJVtYfaUliX1MhmJYVAe/ocIb/MiDHBJ8

View file

@ -1,32 +1,64 @@
^-^ <a id="inconspicuous-timer-a" href="/images/secret.jpg"><i id="inconspicuous-timer"></i></a> ^-^ <a id="inconspicuous-timer-a" href="/images/secret.jpg"><i id="inconspicuous-timer"></i></a>
<script> <script>
function getTimeSince(dateString) {
// Parse the input date string into a Date object
const startDate = new Date(dateString);
// Get the current date
const currentDate = new Date();
// Calculate the differences in each unit
let years = currentDate.getFullYear() - startDate.getFullYear();
let months = currentDate.getMonth() - startDate.getMonth();
let days = currentDate.getDate() - startDate.getDate();
let hours = currentDate.getHours() - startDate.getHours();
let minutes = currentDate.getMinutes() - startDate.getMinutes();
// Adjust for negative month difference
if (months < 0) {
years--;
months += 12;
}
// Adjust for negative day difference
if (days < 0) {
months--;
let prevMonth = new Date(currentDate.getFullYear(), currentDate.getMonth(), 0).getDate();
days += prevMonth;
}
// Adjust for negative hour difference
if (hours < 0) {
days--;
hours += 24;
}
// Adjust for negative minute difference
if (minutes < 0) {
hours--;
minutes += 60;
}
return {
years: years,
months: months,
days: days,
hours: hours,
minutes: minutes
};
}
// Set the date we're counting up from // Set the date we're counting up from
const countUpDate = new Date("Dec 28, 2023 12:34:56").getTime(); const startDate = new Date("Dec 28, 2023 16:34:56");
const timerElement = document.getElementById("inconspicuous-timer")
function updateHtml() { function updateHtml() {
// Get today's date and time const result = getTimeSince("Dec 28, 2023 16:34:56");
var now = new Date().getTime(); const timerElement = document.getElementById("inconspicuous-timer")
timerElement.innerHTML = `${result.years}y ${result.months}m ${result.days}d ${result.hours}h ${result.minutes}min`;
// Find the distance between now and the count up date
var distance = now - countUpDate;
// Time calculations for days, hours, minutes and seconds
var years = Math.floor(distance / (1000 * 60 * 60 * 24 * 365));
var days = Math.floor(distance % (1000 * 60 * 60 * 24 * 365) / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var text = ""
if (years != 0) {
text = years + "y " + days + "d " + hours + "h " + minutes + "m "
} else {
text = days + "d " + hours + "h " + minutes + "m "
}
timerElement.innerHTML = text;
} }
updateHtml() updateHtml()
var x = setInterval(updateHtml, 1000); var x = setInterval(updateHtml, 10000);
</script> </script>