-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
53 lines (44 loc) · 1.46 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
document.addEventListener("DOMContentLoaded", () => {
const menuBtn = document.querySelector(".hamburger-menu");
const closeBtn = document.querySelector(".close-btn");
const menu = document.querySelector("menu");
const navItems = document.querySelectorAll(".nav_item");
navItems.forEach((ele) => {
ele.addEventListener("click", () => {
if (menu.classList.contains("open")) {
menu.classList.remove("open");
}
});
});
const closeMenu = () => {
menu.classList.remove("open");
};
const updateYear = () => {
const now = new Date();
const currentYear = now.getFullYear();
document.querySelector(".copy span").textContent = currentYear;
};
function updateDateTime() {
const now = new Date();
const options = { weekday: "long" };
const currentDay = now.toLocaleDateString("en-US", options);
const currentTimeUTC = now.toUTCString().split(" ")[4];
document.querySelector('[data-testid="currentTimeUTC"]').textContent =
currentTimeUTC;
document.querySelector('[data-testid="currentDay"]').textContent =
currentDay;
}
closeMenu();
updateDateTime();
updateYear();
setInterval(updateDateTime, 1000);
menuBtn.addEventListener("click", () => {
menu.classList.add("open");
});
closeBtn.addEventListener("click", closeMenu);
document.addEventListener("click", (event) => {
if (!menu.contains(event.target) && !menuBtn.contains(event.target)) {
closeMenu();
}
});
});