From 9d1362106da1f15b732ff86a11f293d68f74b5ad Mon Sep 17 00:00:00 2001 From: LEGALISE_PIRACY Date: Mon, 11 Mar 2024 03:24:16 +0000 Subject: [PATCH] Update js/main.js --- js/main.js | 63 +++++++++++++++++++++--------------------------------- 1 file changed, 24 insertions(+), 39 deletions(-) diff --git a/js/main.js b/js/main.js index 8690ef15..06ffb6eb 100644 --- a/js/main.js +++ b/js/main.js @@ -116,52 +116,37 @@ function delPassword() { localStorage.removeItem("selenite.password"); } +function getCurrentTime() { + const n = document.getElementById("time"); - let use12HourFormat = localStorage.getItem('timeFormat') !== '24'; - - function getCurrentTime() { - const n = document.getElementById("time"); - - fetch("https://worldtimeapi.org/api/ip") - .then(response => response.json()) - .then(data => { - const t = new Date(data.utc_datetime); - const formattedTime = formatTime(t); - n.textContent = formattedTime; - }) - .catch(() => { - const currentTime = new Date(); - const formattedTime = formatTime(currentTime); - n.textContent = formattedTime; - }); - } - - function formatTime(time) { - const options = { + fetch("https://worldtimeapi.org/api/ip") + .then(response => response.json()) + .then(data => { + const t = new Date(data.utc_datetime); + const formattedTime = t.toLocaleTimeString(undefined, { hour: "numeric", minute: "numeric", second: "numeric", - hour12: use12HourFormat - }; - return time.toLocaleTimeString(undefined, options); - } + hour12: true + }); + n.textContent = formattedTime; + }) + .catch(() => { - function toggleTimeFormat() { - use12HourFormat = !use12HourFormat; - localStorage.setItem('timeFormat', use12HourFormat ? '12' : '24'); - updateButtonText(); - getCurrentTime(); - } + const currentTime = new Date(); + const formattedTime = currentTime.toLocaleTimeString(undefined, { + hour: "numeric", + minute: "numeric", + second: "numeric", + hour12: true + }); + n.textContent = formattedTime; + }); +} - function updateButtonText() { - const button = document.getElementById('toggleButton'); - button.textContent = use12HourFormat ? 'Switch to 24-Hour Time' : 'Switch to 12-Hour Time'; - } +getCurrentTime(); +setInterval(getCurrentTime, 900); - getCurrentTime(); - updateButtonText(); - setInterval(getCurrentTime, 900); - let cookieConsentScript = document.createElement("script"); cookieConsentScript.src = "/js/cookieConsent.js"; document.head.appendChild(cookieConsentScript);