mirror of
https://gitlab.com/skysthelimit.dev/selenite.git
synced 2025-06-15 18:12:08 -05:00
Update js/main.js
This commit is contained in:
parent
940aae94f5
commit
ef4d8bce12
60
js/main.js
60
js/main.js
@ -117,43 +117,37 @@ function delPassword() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let use12HourFormat = localStorage.getItem('timeFormat') !== '24';
|
let use12HourFormat = "24" !== localStorage.getItem("timeFormat");
|
||||||
|
|
||||||
function getCurrentTime() {
|
function getCurrentTime() {
|
||||||
const n = document.getElementById("time");
|
const t = 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
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
fetch("https://worldtimeapi.org/api/ip")
|
function formatTime(t) {
|
||||||
.then(response => response.json())
|
const e = {
|
||||||
.then(data => {
|
hour: "numeric",
|
||||||
const t = new Date(data.utc_datetime);
|
minute: "numeric",
|
||||||
const formattedTime = formatTime(t);
|
second: "numeric",
|
||||||
n.textContent = formattedTime;
|
hour12: use12HourFormat
|
||||||
})
|
};
|
||||||
.catch(() => {
|
return t.toLocaleTimeString(void 0, e)
|
||||||
const currentTime = new Date();
|
}
|
||||||
const formattedTime = formatTime(currentTime);
|
|
||||||
n.textContent = formattedTime;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatTime(time) {
|
function toggleTimeFormat() {
|
||||||
const options = {
|
use12HourFormat = !use12HourFormat, localStorage.setItem("timeFormat", use12HourFormat ? "12" : "24"), updateButtonText(), getCurrentTime()
|
||||||
hour: "numeric",
|
}
|
||||||
minute: "numeric",
|
|
||||||
second: "numeric",
|
|
||||||
hour12: use12HourFormat
|
|
||||||
};
|
|
||||||
return time.toLocaleTimeString(undefined, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleTimeFormat() {
|
function updateButtonText() {
|
||||||
use12HourFormat = !use12HourFormat;
|
document.getElementById("toggleButton").textContent = use12HourFormat ? "Switch to 24-Hour Time" : "Switch to 12-Hour Time"
|
||||||
localStorage.setItem('timeFormat', use12HourFormat ? '12' : '24');
|
}
|
||||||
getCurrentTime();
|
getCurrentTime(), updateButtonText(), setInterval(getCurrentTime, 900);
|
||||||
}
|
|
||||||
|
|
||||||
getCurrentTime();
|
|
||||||
setInterval(getCurrentTime, 900);
|
|
||||||
|
|
||||||
|
|
||||||
let cookieConsentScript = document.createElement("script");
|
let cookieConsentScript = document.createElement("script");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user