From 1fc25997a7d4b3cf80dbc09a3f48afd031ba5d0e Mon Sep 17 00:00:00 2001 From: Jan Palma Date: Fri, 27 Feb 2026 17:59:06 +0100 Subject: Init --- assets/js/main.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 assets/js/main.js (limited to 'assets/js/main.js') diff --git a/assets/js/main.js b/assets/js/main.js new file mode 100644 index 0000000..bd14b0c --- /dev/null +++ b/assets/js/main.js @@ -0,0 +1,25 @@ +const elements = document.querySelectorAll(".my-age") + +const specificDate = new Date("2010-05-11T22:50:00"); +const updateAge = () => { + const currentDate = new Date(); + const age = ( + (currentDate - specificDate) / + (1000 * 60 * 60 * 24 * 365.25) + ).toFixed(15); + let nextBirthday = new Date(specificDate); + nextBirthday.setFullYear(currentDate.getFullYear()); + if (currentDate > nextBirthday) { + nextBirthday.setFullYear(currentDate.getFullYear() + 1); + } + const timeDiff = nextBirthday - currentDate; + const daysLeft = Math.floor(timeDiff / (1000 * 60 * 60 * 24)); + + elements.forEach(e => { + e.textContent = `${age}`; + e.title = `${daysLeft} days left`; + }) + requestAnimationFrame(updateAge); +} +updateAge(); + -- cgit v1.3-7-ge9ab