mirror of
https://gitlab.com/skysthelimit.dev/selenite.git
synced 2025-06-16 02:22:07 -05:00
Update js/main.js
This commit is contained in:
parent
f0e97cc906
commit
9d1362106d
41
js/main.js
41
js/main.js
@ -116,9 +116,6 @@ function delPassword() {
|
|||||||
localStorage.removeItem("selenite.password");
|
localStorage.removeItem("selenite.password");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let use12HourFormat = localStorage.getItem('timeFormat') !== '24';
|
|
||||||
|
|
||||||
function getCurrentTime() {
|
function getCurrentTime() {
|
||||||
const n = document.getElementById("time");
|
const n = document.getElementById("time");
|
||||||
|
|
||||||
@ -126,40 +123,28 @@ function delPassword() {
|
|||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
const t = new Date(data.utc_datetime);
|
const t = new Date(data.utc_datetime);
|
||||||
const formattedTime = formatTime(t);
|
const formattedTime = t.toLocaleTimeString(undefined, {
|
||||||
|
hour: "numeric",
|
||||||
|
minute: "numeric",
|
||||||
|
second: "numeric",
|
||||||
|
hour12: true
|
||||||
|
});
|
||||||
n.textContent = formattedTime;
|
n.textContent = formattedTime;
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
|
|
||||||
const currentTime = new Date();
|
const currentTime = new Date();
|
||||||
const formattedTime = formatTime(currentTime);
|
const formattedTime = currentTime.toLocaleTimeString(undefined, {
|
||||||
|
hour: "numeric",
|
||||||
|
minute: "numeric",
|
||||||
|
second: "numeric",
|
||||||
|
hour12: true
|
||||||
|
});
|
||||||
n.textContent = formattedTime;
|
n.textContent = formattedTime;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatTime(time) {
|
|
||||||
const options = {
|
|
||||||
hour: "numeric",
|
|
||||||
minute: "numeric",
|
|
||||||
second: "numeric",
|
|
||||||
hour12: use12HourFormat
|
|
||||||
};
|
|
||||||
return time.toLocaleTimeString(undefined, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleTimeFormat() {
|
|
||||||
use12HourFormat = !use12HourFormat;
|
|
||||||
localStorage.setItem('timeFormat', use12HourFormat ? '12' : '24');
|
|
||||||
updateButtonText();
|
|
||||||
getCurrentTime();
|
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);
|
setInterval(getCurrentTime, 900);
|
||||||
|
|
||||||
let cookieConsentScript = document.createElement("script");
|
let cookieConsentScript = document.createElement("script");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user