2020-06-04 05:27:00 +02:00
|
|
|
// 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) => {
|
|
|
|
|
2020-06-06 05:34:20 +02:00
|
|
|
if (event.key === 'Tab') return;
|
|
|
|
|
2020-06-04 05:27:00 +02:00
|
|
|
// 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()
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
);
|