mirror of
https://github.com/benbusby/whoogle-search
synced 2024-11-04 18:00:25 +00:00
3f363b0175
This adds a new "temporary" config section of the results view, where a user can now change the country that their results come from without changing their default config settings. Closes #322
26 lines
919 B
JavaScript
26 lines
919 B
JavaScript
document.addEventListener("DOMContentLoaded", () => {
|
|
const searchBar = document.getElementById("search-bar");
|
|
const countrySelect = document.getElementById("result-country");
|
|
const arrowKeys = [37, 38, 39, 40];
|
|
let searchValue = searchBar.value;
|
|
|
|
countrySelect.onchange = () => {
|
|
let str = window.location.href;
|
|
n = str.lastIndexOf("search");
|
|
if (n > 0) {
|
|
str = str.substring(0, n) +
|
|
`search?q=${searchBar.value}&country=${countrySelect.value}`;
|
|
window.location.href = str;
|
|
}
|
|
}
|
|
|
|
searchBar.addEventListener("keyup", function(event) {
|
|
if (event.keyCode === 13) {
|
|
document.getElementById("search-form").submit();
|
|
} else if (searchBar.value !== searchValue && !arrowKeys.includes(event.keyCode)) {
|
|
searchValue = searchBar.value;
|
|
handleUserInput();
|
|
}
|
|
});
|
|
});
|