Add debounce timer to search, GH-370

This commit is contained in:
krateng 2025-01-16 06:22:35 +01:00
parent 1462883ab5
commit 26f26f36cb

View File

@ -1,17 +1,23 @@
var searches = []
var debounceTimer;
function search(searchfield) {
txt = searchfield.value;
if (txt == "") {
reallyclear()
}
else {
xhttp = new XMLHttpRequest();
searches.push(xhttp)
xhttp.onreadystatechange = searchresult
xhttp.open("GET","/api/search?max=5&query=" + encodeURIComponent(txt), true);
xhttp.send();
}
clearTimeout(debounceTimer);
debounceTimer = setTimeout(() => {
const txt = searchfield.value;
if (txt == "") {
reallyclear();
}
else {
const xhttp = new XMLHttpRequest();
searches.push(xhttp);
xhttp.onreadystatechange = searchresult
xhttp.open("GET","/api/search?max=5&query=" + encodeURIComponent(txt), true);
xhttp.send();
}
}, 1000);
}