Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
75 lines (59 loc) · 2.05 KB
/
Copy pathscript.js
File metadata and controls
75 lines (59 loc) · 2.05 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const formatBtn = document.querySelector(".btn");
const lightBtn = document.getElementById("light");
const hideBtn = document.getElementById("hide");
const gh = document.querySelector(".gh");
const set = document.querySelector(".set");
const menu = document.querySelector("menu");
formatBtn.addEventListener("click", () => {
formatBtn.classList.toggle("active");
formatBtn.dataset.f = formatBtn.dataset.f == 12 ? 24 : 12;
});
lightBtn.addEventListener("click", () => {
lightBtn.classList.toggle("active");
document.body.classList.toggle("light");
});
hideBtn.addEventListener("click", () => {
hideBtn.classList.toggle("active");
gh.classList.toggle("hide");
set.classList.toggle("hide");
});
function clock() {
const t = new Date();
let h = t.getHours();
let m = t.getMinutes();
let s = t.getSeconds();
let ap = "AM";
if (h >= 12) ap = "PM";
if (formatBtn.dataset.f == 12) h = h % 12 || 12;
h = h.toString().padStart(2, "0");
m = m.toString().padStart(2, "0");
s = s.toString().padStart(2, "0");
document.querySelector(".h").textContent = h;
document.querySelector(".m").textContent = m;
document.querySelector(".ap").textContent = ap;
document.querySelector(".s").textContent = s;
}
setInterval(clock, 1000);
clock();
const today = new Date();
document.getElementById("y").textContent = today.getFullYear();
document.getElementById("mo").textContent = today.toLocaleString("default", { month: "short" });
document.getElementById("da").textContent = today.getDate();
document.getElementById("w").textContent = today.toLocaleString("default", { weekday: "long" });
set.addEventListener("click", () => {
menu.classList.toggle("active");
});
document.addEventListener("click", (e) => {
if (!e.target.closest(".set, .item")) {
menu.classList.remove("active");
}
});
function updateFavicon() {
const isLight = document.body.classList.contains('light');
const favicon = document.querySelector('link[rel="icon"]');
if (favicon) {
favicon.href = isLight ? 'favicon.ico' : 'favicon-dark.ico';
}
}
updateFavicon();
lightBtn.addEventListener('click', updateFavicon);