-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
61 lines (50 loc) · 1.72 KB
/
Copy pathscript.js
File metadata and controls
61 lines (50 loc) · 1.72 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
const timeElement = document.getElementById("time");
const dateElement = document.getElementById("date");
const greetingElement = document.getElementById("greeting-text");
const searchForm = document.getElementById("search-form");
const searchInput = document.getElementById("search-input");
function updateClock() {
const now = new Date();
const time = now.toLocaleTimeString("en-US", {
hour: "2-digit",
minute: "2-digit",
hour12: false
});
const date = now.toLocaleDateString("en-US", {
weekday: "long",
month: "long",
day: "numeric"
});
timeElement.textContent = time;
timeElement.dateTime = now.toISOString();
dateElement.textContent = date;
const hour = now.getHours();
const greeting = hour < 12 ? "Good morning" : hour < 18 ? "Good afternoon" : "Good evening";
greetingElement.textContent = `${greeting}, @YOUR USERNAME.`;
}
searchForm.addEventListener("submit", (event) => {
event.preventDefault();
const query = searchInput.value.trim();
if (!query) {
return;
}
window.location.href = `https://www.google.com/search?q=${encodeURIComponent(query)}`;
});
document.addEventListener("keydown", (event) => {
const activeElement = document.activeElement;
const isTyping = activeElement && (
activeElement.tagName === "INPUT" ||
activeElement.tagName === "TEXTAREA" ||
activeElement.isContentEditable
);
if (event.key === "/" && !isTyping) {
event.preventDefault();
searchInput.focus();
}
if (event.key === "Escape" && activeElement === searchInput) {
searchInput.value = "";
searchInput.blur();
}
});
updateClock();
setInterval(updateClock, 1000);