2023-06-07 06:44:54 -04:00
|
|
|
/**
|
|
|
|
* Selects the input element for the search box
|
|
|
|
* @type {HTMLInputElement}
|
|
|
|
*/
|
|
|
|
const searchBox = document.querySelector('input');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Redirects the user to the search results page with the query parameter
|
|
|
|
*/
|
|
|
|
function searchWeb() {
|
|
|
|
const query = searchBox.value.trim();
|
|
|
|
if (query) {
|
|
|
|
window.location.href = `search?q=${encodeURIComponent(query)}`;
|
|
|
|
}
|
2023-04-22 07:35:07 -04:00
|
|
|
}
|
|
|
|
|
2023-06-07 06:44:54 -04:00
|
|
|
/**
|
|
|
|
* Listens for the 'Enter' key press event on the search box and calls the searchWeb function
|
|
|
|
* @param {KeyboardEvent} e - The keyboard event object
|
|
|
|
*/
|
|
|
|
searchBox.addEventListener('keyup', (e) => {
|
2023-05-26 03:38:17 -04:00
|
|
|
if (e.key === 'Enter') {
|
2023-06-07 06:44:54 -04:00
|
|
|
searchWeb();
|
2023-04-22 07:35:07 -04:00
|
|
|
}
|
2023-06-07 06:44:54 -04:00
|
|
|
});
|