-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
100 lines (88 loc) · 2.79 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
let wakeLock = null;
async function requestWakeLock() {
try {
wakeLock = await navigator.wakeLock.request("screen");
console.log("Wake Lock is active");
} catch (err) {
console.error(`${err.name}, ${err.message}`);
}
}
function releaseWakeLock() {
if (wakeLock) {
wakeLock.release();
wakeLock = null;
console.log("Wake Lock is released");
}
}
document.addEventListener("visibilitychange", () => {
if (document.visibilityState === "visible") {
requestWakeLock();
} else {
releaseWakeLock();
}
});
requestWakeLock();
function updateClock() {
const now = new Date();
let hours = now.getHours();
let minutes = now.getMinutes();
hours = hours < 10 ? "0" + hours : hours;
minutes = minutes < 10 ? "0" + minutes : minutes;
document.getElementById("time").textContent = `${hours}:${minutes}`;
updateCalendar(now);
}
function updateCalendar(date) {
const monthNames = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
];
const dayNames = ["S", "M", "T", "W", "T", "F", "S"];
const month = date.getMonth();
const year = date.getFullYear();
document.getElementById("month-name").textContent = monthNames[month];
const calendarGrid = document.getElementById("calendar-grid");
calendarGrid.innerHTML = ""; // Clear previous calendar
dayNames.forEach((day) => {
const dayElement = document.createElement("span");
dayElement.textContent = day;
dayElement.classList.add("weekday-header");
calendarGrid.appendChild(dayElement);
});
const firstDayOfMonth = new Date(year, month, 1).getDay();
const daysInMonth = new Date(year, month + 1, 0).getDate();
for (let i = 0; i < firstDayOfMonth; i++) {
const emptyDay = document.createElement("span");
calendarGrid.appendChild(emptyDay);
}
for (let day = 1; day <= daysInMonth; day++) {
const dayElement = document.createElement("span");
dayElement.textContent = day;
if (day === date.getDate()) {
dayElement.classList.add("today");
}
calendarGrid.appendChild(dayElement);
}
}
function toggleFullscreen() {
if (!document.fullscreenElement) {
document.documentElement.requestFullscreen().catch((err) => {
console.error(
`Error attempting to enable full-screen mode: ${err.message} (${err.name})`
);
});
} else {
document.exitFullscreen();
}
}
setInterval(updateClock, 1000);
updateClock();