forked from nathanielevan/startpage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
63 lines (55 loc) · 1.74 KB
/
index.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
document.onreadystatechange = updateClock();
function updateClock() {
const username = "Tiago";
const date = new Date();
document.getElementById("current-time-text").innerText =
date.toLocaleTimeString([], { hourCycle: "h23" });
const hour = date.getHours();
if (hour < 5 || hour >= 18) {
document.getElementById(
"time-greeting-text"
).innerText = `Good evening ${username}`;
} else if (hour < 12) {
document.getElementById(
"time-greeting-text"
).innerText = `Good morning ${username}`;
} else {
document.getElementById(
"time-greeting-text"
).innerText = `Good afternoon ${username}`;
}
}
function doSearch() {
const query = document.getElementById("search-input").value;
switch (document.getElementById("search-engine-select").value) {
case "google":
window.location.href = `https://www.google.com/search?q=${query}`;
break;
case "bing":
window.location.href = `https://www.bing.com/?q=${query}`;
break;
case "ddg":
window.location.href = `https://www.duckduckgo.com/?q=${query}`;
}
}
document.querySelector("#search-button").addEventListener("click", doSearch);
document
.getElementById("search-input")
.addEventListener("keypress", function onEvent(event) {
if (event.key === "Enter") {
document.getElementById("search-button").click();
}
});
document
.getElementById("search-engine-select")
.addEventListener("change", () => {
const value = document.getElementById("search-engine-select").value;
localStorage.setItem("search-engine", value);
});
document.addEventListener("DOMContentLoaded", () => {
const searchEngine = localStorage.getItem("search-engine");
if (searchEngine) {
document.getElementById("search-engine-select").value = searchEngine;
}
});
setInterval(updateClock, 1000);