mirror of
https://github.com/neon-mmd/websurfx.git
synced 2024-11-21 21:48: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:
parent
9253d9e48f
commit
a727d389ae
@ -2,16 +2,25 @@
|
|||||||
* Selects the input element for the search box
|
* Selects the input element for the search box
|
||||||
* @type {HTMLInputElement}
|
* @type {HTMLInputElement}
|
||||||
*/
|
*/
|
||||||
const searchBox = document.querySelector('input');
|
const searchBox = document.querySelector('input')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Redirects the user to the search results page with the query parameter
|
* Redirects the user to the search results page with the query parameter
|
||||||
*/
|
*/
|
||||||
function searchWeb() {
|
function searchWeb() {
|
||||||
const query = searchBox.value.trim();
|
const query = searchBox.value.trim()
|
||||||
if (query) {
|
try {
|
||||||
window.location.href = `search?q=${encodeURIComponent(query)}`;
|
let safeSearchLevel = document.querySelector('.search_options select').value
|
||||||
}
|
if (query) {
|
||||||
|
window.location.href = `search?q=${encodeURIComponent(
|
||||||
|
query,
|
||||||
|
)}&safesearch=${encodeURIComponent(safeSearchLevel)}`
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
if (query) {
|
||||||
|
window.location.href = `search?q=${encodeURIComponent(query)}`
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -19,7 +28,7 @@ function searchWeb() {
|
|||||||
* @param {KeyboardEvent} e - The keyboard event object
|
* @param {KeyboardEvent} e - The keyboard event object
|
||||||
*/
|
*/
|
||||||
searchBox.addEventListener('keyup', (e) => {
|
searchBox.addEventListener('keyup', (e) => {
|
||||||
if (e.key === 'Enter') {
|
if (e.key === 'Enter') {
|
||||||
searchWeb();
|
searchWeb()
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user