0
0
mirror of https://github.com/neon-mmd/websurfx.git synced 2024-11-21 13:38:21 -05:00

feat: implement code to query the engine based on the options selected under the search bar (#210)

This commit is contained in:
neon_arch 2023-09-22 19:59:06 +03:00
parent 9253d9e48f
commit a727d389ae

View File

@ -2,15 +2,24 @@
* Selects the input element for the search box
* @type {HTMLInputElement}
*/
const searchBox = document.querySelector('input');
const searchBox = document.querySelector('input')
/**
* Redirects the user to the search results page with the query parameter
*/
function searchWeb() {
const query = searchBox.value.trim();
const query = searchBox.value.trim()
try {
let safeSearchLevel = document.querySelector('.search_options select').value
if (query) {
window.location.href = `search?q=${encodeURIComponent(query)}`;
window.location.href = `search?q=${encodeURIComponent(
query,
)}&safesearch=${encodeURIComponent(safeSearchLevel)}`
}
} catch (error) {
if (query) {
window.location.href = `search?q=${encodeURIComponent(query)}`
}
}
}
@ -20,6 +29,6 @@ function searchWeb() {
*/
searchBox.addEventListener('keyup', (e) => {
if (e.key === 'Enter') {
searchWeb();
searchWeb()
}
});
})