mirror of
https://github.com/benbusby/whoogle-search
synced 2024-11-18 09:25:33 +00:00
20 lines
577 B
JavaScript
20 lines
577 B
JavaScript
document.addEventListener("DOMContentLoaded", function() {
|
|
const searchBar = document.getElementById("search-bar");
|
|
const searchBtn = document.getElementById("search-submit");
|
|
|
|
// Automatically focus on search field
|
|
searchBar.focus();
|
|
searchBar.select();
|
|
|
|
searchBar.addEventListener("keyup", function(event) {
|
|
if (event.keyCode === 13) {
|
|
event.preventDefault();
|
|
searchBtn.click();
|
|
}
|
|
});
|
|
|
|
searchBtn.onclick = function() {
|
|
window.location.href = '/search?q=' + encodeURI(searchBar.value);
|
|
}
|
|
});
|