Update js/main.js

This commit is contained in:
LEGALISE_PIRACY 2024-03-11 03:21:32 +00:00
parent 82bf10647e
commit f0e97cc906

View File

@ -117,38 +117,50 @@ function delPassword() {
} }
let use12HourFormat = "24" !== localStorage.getItem("timeFormat"); let use12HourFormat = localStorage.getItem('timeFormat') !== '24';
function getCurrentTime() { function getCurrentTime() {
const t = document.getElementById("time"); const n = document.getElementById("time");
fetch("https://worldtimeapi.org/api/ip").then((t => t.json())).then((e => {
const o = formatTime(new Date(e.utc_datetime));
t.textContent = o
})).catch((() => {
const e = formatTime(new Date);
t.textContent = e
}))
}
function formatTime(t) { fetch("https://worldtimeapi.org/api/ip")
const e = { .then(response => response.json())
hour: "numeric", .then(data => {
minute: "numeric", const t = new Date(data.utc_datetime);
second: "numeric", const formattedTime = formatTime(t);
hour12: use12HourFormat n.textContent = formattedTime;
}; })
return t.toLocaleTimeString(void 0, e) .catch(() => {
} const currentTime = new Date();
const formattedTime = formatTime(currentTime);
n.textContent = formattedTime;
});
}
function toggleTimeFormat() { function formatTime(time) {
use12HourFormat = !use12HourFormat, localStorage.setItem("timeFormat", use12HourFormat ? "12" : "24"), updateButtonText(), getCurrentTime() const options = {
} hour: "numeric",
minute: "numeric",
second: "numeric",
hour12: use12HourFormat
};
return time.toLocaleTimeString(undefined, options);
}
function updateButtonText() { function toggleTimeFormat() {
document.getElementById("toggleButton").textContent = use12HourFormat ? "Switch to 24-Hour Time" : "Switch to 12-Hour Time" use12HourFormat = !use12HourFormat;
} localStorage.setItem('timeFormat', use12HourFormat ? '12' : '24');
getCurrentTime(), updateButtonText(), setInterval(getCurrentTime, 900); updateButtonText();
getCurrentTime();
}
function updateButtonText() {
const button = document.getElementById('toggleButton');
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";