This repository was archived by the owner on Mar 18, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmain.js
More file actions
39 lines (37 loc) · 1.18 KB
/
main.js
File metadata and controls
39 lines (37 loc) · 1.18 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
const searchForm = document.querySelector("#search");
const searchBar = searchForm[0];
const searchEngine = "https://google.com/search?q=";
searchBar.focus();
searchForm.onsubmit = (e) => {
e.preventDefault();
const query = searchBar.value.replace(/ /g, "+");
if (validURL(query)) {
if (!query.startsWith("https://"))
return (window.location.href = "https://" + query);
else window.location.href = query;
} else return (window.location.href = "" + searchEngine + query);
};
function validURL(str) {
var pattern = new RegExp(
"^(https?:\\/\\/)?" +
"((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|" +
"((\\d{1,3}\\.){3}\\d{1,3}))" +
"(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*" +
"(\\?[;&a-z\\d%_.~+=-]*)?" +
"(\\#[-a-z\\d_]*)?$",
"i"
);
return !!pattern.test(str);
}
const timeElement = document.querySelector("#time");
function updateTime() {
const date = new Date();
var hour = date.getHours().toString();
if (hour.length === 1) hour = "0" + hour;
var minute = date.getMinutes().toString();
if (minute.length === 1) minute = "0" + minute;
const seconds = date.getSeconds();
timeElement.textContent = hour + ":" + minute;
setTimeout(updateTime, 1 - seconds);
}
updateTime();