Update js/main.js

This commit is contained in:
LEGALISE_PIRACY 2024-03-11 03:24:16 +00:00
parent f0e97cc906
commit 9d1362106d

View File

@ -116,52 +116,37 @@ function delPassword() {
localStorage.removeItem("selenite.password"); localStorage.removeItem("selenite.password");
} }
function getCurrentTime() {
const n = document.getElementById("time");
let use12HourFormat = localStorage.getItem('timeFormat') !== '24'; fetch("https://worldtimeapi.org/api/ip")
.then(response => response.json())
function getCurrentTime() { .then(data => {
const n = document.getElementById("time"); const t = new Date(data.utc_datetime);
const formattedTime = t.toLocaleTimeString(undefined, {
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 = {
hour: "numeric", hour: "numeric",
minute: "numeric", minute: "numeric",
second: "numeric", second: "numeric",
hour12: use12HourFormat hour12: true
}; });
return time.toLocaleTimeString(undefined, options); n.textContent = formattedTime;
} })
.catch(() => {
function toggleTimeFormat() { const currentTime = new Date();
use12HourFormat = !use12HourFormat; const formattedTime = currentTime.toLocaleTimeString(undefined, {
localStorage.setItem('timeFormat', use12HourFormat ? '12' : '24'); hour: "numeric",
updateButtonText(); minute: "numeric",
getCurrentTime(); second: "numeric",
} hour12: true
});
n.textContent = formattedTime;
});
}
function updateButtonText() { getCurrentTime();
const button = document.getElementById('toggleButton'); setInterval(getCurrentTime, 900);
button.textContent = use12HourFormat ? 'Switch to 24-Hour Time' : 'Switch to 12-Hour Time';
}
getCurrentTime();
updateButtonText();
setInterval(getCurrentTime, 900);
let cookieConsentScript = document.createElement("script"); let cookieConsentScript = document.createElement("script");
cookieConsentScript.src = "/js/cookieConsent.js"; cookieConsentScript.src = "/js/cookieConsent.js";
document.head.appendChild(cookieConsentScript); document.head.appendChild(cookieConsentScript);