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
82bf10647e
commit
f0e97cc906
68
js/main.js
68
js/main.js
@ -116,39 +116,51 @@ function delPassword() {
|
|||||||
localStorage.removeItem("selenite.password");
|
localStorage.removeItem("selenite.password");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let use12HourFormat = "24" !== localStorage.getItem("timeFormat");
|
|
||||||
|
|
||||||
function getCurrentTime() {
|
let use12HourFormat = localStorage.getItem('timeFormat') !== '24';
|
||||||
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
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatTime(t) {
|
function getCurrentTime() {
|
||||||
const e = {
|
const n = document.getElementById("time");
|
||||||
hour: "numeric",
|
|
||||||
minute: "numeric",
|
|
||||||
second: "numeric",
|
|
||||||
hour12: use12HourFormat
|
|
||||||
};
|
|
||||||
return t.toLocaleTimeString(void 0, e)
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleTimeFormat() {
|
fetch("https://worldtimeapi.org/api/ip")
|
||||||
use12HourFormat = !use12HourFormat, localStorage.setItem("timeFormat", use12HourFormat ? "12" : "24"), updateButtonText(), getCurrentTime()
|
.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 updateButtonText() {
|
function formatTime(time) {
|
||||||
document.getElementById("toggleButton").textContent = use12HourFormat ? "Switch to 24-Hour Time" : "Switch to 12-Hour Time"
|
const options = {
|
||||||
}
|
hour: "numeric",
|
||||||
getCurrentTime(), updateButtonText(), setInterval(getCurrentTime, 900);
|
minute: "numeric",
|
||||||
|
second: "numeric",
|
||||||
|
hour12: use12HourFormat
|
||||||
|
};
|
||||||
|
return time.toLocaleTimeString(undefined, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleTimeFormat() {
|
||||||
|
use12HourFormat = !use12HourFormat;
|
||||||
|
localStorage.setItem('timeFormat', use12HourFormat ? '12' : '24');
|
||||||
|
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";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user