-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
62 lines (54 loc) · 2.64 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
54
55
56
57
58
59
60
61
62
const timeContainer = document.querySelector(".time-container");
const dayNameContainer = document.querySelector(".day-name-container");
const dateContainer = document.querySelector(".date-container");
const modeSelectButton = document.querySelector(".mode-select-button");
const getDayName = (dayIndex)=>{
const days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
return days[dayIndex];
}
const getMonthName = (monthIndex)=>{
const months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
return months[monthIndex];
}
const updateTime = ()=>{
const date = new Date();
const hh24HoursFormat = date.getHours();
const am_pm = (hh24HoursFormat>=12) ? 'PM' : 'AM';
let hh = (hh24HoursFormat>12) ? hh24HoursFormat-12 : hh24HoursFormat;
hh = (hh<10) ? '0'+hh : hh;
let mm = date.getMinutes();
mm = (mm<10) ? '0'+mm : mm;
const time = `${hh}:${mm} ${am_pm}`
let dayName = getDayName(date.getDay());;
let monthDate = date.getDate();
let month = getMonthName(date.getMonth());
let year = date.getFullYear();
timeContainer.textContent = time;
dayNameContainer.textContent = `${dayName}`;
dateContainer.textContent = `${month} ${monthDate}, ${year}`;
}
setInterval(updateTime, 1000);
modeSelectButton.addEventListener("click", (e)=>{
const body = document.querySelector("body");
const container = document.querySelector(".container");
const dayDateContainer = document.querySelector(".day-date-container");
const button = document.querySelector(".mode-select-button");
if(e.target.innerHTML.toLowerCase() === "dark mode"){
body.style.backgroundColor = "var(--body-dark-background)";
container.style.backgroundColor = "var(--container-dark-background)";
container.style.color = "var(--container-dark-text-color)";
dayDateContainer.style.color = "var(--day-date-container-dark-text-color)";
button.style.color = "var(--button-dark-text-color)";
button.style.borderColor = "var(--button-dark-border-color)";
button.innerHTML = "Light Mode";
}
else{
body.style.backgroundColor = "var(--body-light-background)";
container.style.backgroundColor = "var(--container-light-background)";
container.style.color = "var(--container-light-text-color)";
dayDateContainer.style.color = "var(--day-date-container-light-text-color)";
button.style.color = "var(--button-light-text-color)";
button.style.borderColor = "var(--button-light-border-color)";
button.innerHTML = "Dark Mode";
}
});