Skip to content

Commit ceb52b4

Browse files
committed
Fix: Prevent FOUC for clock
1 parent a8a5220 commit ceb52b4

2 files changed

Lines changed: 12 additions & 14 deletions

File tree

index.html

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,18 @@ <h2>Editors</h2>
12681268
<span></span>
12691269
<span></span>
12701270
</div> -->
1271-
1271+
1272+
<script type="text/javascript">
1273+
const clock = document.querySelector("#menutime");
1274+
1275+
function time() {
1276+
clock.textContent = (new Date()).toLocaleTimeString("en-us", { hour12: false });
1277+
}
1278+
1279+
time();
1280+
setInterval(time, 1000);
1281+
</script>
1282+
12721283
<script id="rendered-js" src="/dist/utilities/particles.js"></script>
12731284
<script src="/dist/main.js" type="module" defer></script>
12741285

src/utilities/timestamp.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88
const days = [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ];
99
const months = [ "Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec" ];
10-
const delay = 1000; // 1 second
1110

1211
function initializeTimestamp() {
1312
let date = new Date();
@@ -18,24 +17,12 @@ function initializeTimestamp() {
1817
return weekDay.concat(" ", month, " ", day, " ", time);
1918
}
2019

21-
function currentTimestamp() {
22-
let date = new Date();
23-
return date.toLocaleTimeString("en-us", { hour12: false });
24-
}
25-
26-
function updateTimestamp() {
27-
document.querySelector("#menutime").textContent = currentTimestamp();
28-
}
29-
3020
function randomInt(min, max) {
3121
let minCeiled = Math.ceil(min);
3222
let maxFloored = Math.floor(max);
3323
return Math.floor(Math.random() * (maxFloored - minCeiled + 1) + minCeiled); // Min and max are inclusive
3424
}
3525

3626
export function initTimestamp() {
37-
setInterval(updateTimestamp, delay);
38-
updateTimestamp();
39-
4027
document.getElementById("timestamp").innerHTML = "Last login: ".concat(initializeTimestamp(), " on ttys00", randomInt(0, 6));
4128
}

0 commit comments

Comments
 (0)