0
0
mirror of https://github.com/neon-mmd/websurfx.git synced 2024-11-24 15:08:22 -05:00
websurfx/public/static/index.js

26 lines
626 B
JavaScript
Raw Normal View History

/**
* 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
}
/**
* 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') {
searchWeb();
2023-04-22 07:35:07 -04:00
}
});