-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
40 lines (35 loc) · 1.28 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
// Listen for 'Enter' key to trigger search
document.addEventListener("keydown", (event) => {
if (event.key === "Enter") {
search();
}
});
// Display the currently selected search engine
function displaySE() {
const currentSE = document.getElementById("SE");
const seId = currentSE[currentSE.selectedIndex].id;
alert(`You are now searching on ${seId}`);
return currentSE[currentSE.selectedIndex].value;
}
// Toggle display of the settings menu
function toggleSettings() {
const settingsDiv = document.getElementById("settings");
settingsDiv.style.display = settingsDiv.style.display === "none" ? "block" : "none";
}
// Perform the search based on user input
function search() {
const searchbox = document.getElementById("input");
const url = searchbox.value.trim();
const engineval = document.getElementById("SE");
const searchEngine = engineval[engineval.selectedIndex].value;
// Redirect based on whether the input is a URL or a search term
if (url.includes("://")) {
window.location.href = url;
} else if (url.includes(".")) {
window.location.href = `https://${url}`;
} else {
window.location.href = `${searchEngine}${url}`;
}
// Clear the input field after searching
searchbox.value = "";
}