Debounce search input
This commit is contained in:
parent
efcaee8b20
commit
65509975da
1 changed files with 9 additions and 5 deletions
14
script.js
14
script.js
|
|
@ -53,12 +53,16 @@ Array.from(firstByLetter.entries())
|
|||
});
|
||||
|
||||
const searchInput = document.getElementById("toc-search");
|
||||
let searchTimeout;
|
||||
searchInput?.addEventListener("input", (event) => {
|
||||
const query = event.target.value.trim().toLowerCase();
|
||||
Array.from(tocList?.querySelectorAll("li") ?? []).forEach((item) => {
|
||||
const text = item.textContent.toLowerCase();
|
||||
item.style.display = text.includes(query) ? "" : "none";
|
||||
});
|
||||
clearTimeout(searchTimeout);
|
||||
searchTimeout = setTimeout(() => {
|
||||
const query = event.target.value.trim().toLowerCase();
|
||||
Array.from(tocList?.querySelectorAll("li") ?? []).forEach((item) => {
|
||||
const text = item.textContent.toLowerCase();
|
||||
item.style.display = text.includes(query) ? "" : "none";
|
||||
});
|
||||
}, 150);
|
||||
});
|
||||
|
||||
// OCR/formatting errors from epub conversion
|
||||
|
|
|
|||
Loading…
Reference in a new issue