mirror of
https://github.com/manilarome/the-glorious-startpage.git
synced 2024-11-24 08:33:21 +01:00
33 lines
603 B
JavaScript
33 lines
603 B
JavaScript
// Search box
|
|
var searchBox = document.getElementById("searchBox");
|
|
|
|
// Web Search
|
|
const webSearch = () => {
|
|
// Search
|
|
window.location.href = encodeURI(searchQueryPrefix + searchBox.value);
|
|
};
|
|
|
|
// Key release event
|
|
searchBox.addEventListener(
|
|
"keyup",
|
|
(event) => {
|
|
|
|
if (event.key === 'Tab') return;
|
|
|
|
// Number 13 is the "Enter" key on the keyboard
|
|
if (event.key === 'Enter') {
|
|
|
|
// Don't accept empty strings
|
|
if (searchBox.value < 1) {
|
|
return;
|
|
}
|
|
|
|
// Cancel the default action, if needed
|
|
event.preventDefault();
|
|
|
|
// Search the web
|
|
webSearch()
|
|
};
|
|
|
|
}
|
|
); |