Debounce search input
This commit is contained in:
parent
5e7146e3cc
commit
1ad3abf156
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");
|
const searchInput = document.getElementById("toc-search");
|
||||||
|
let searchTimeout;
|
||||||
searchInput?.addEventListener("input", (event) => {
|
searchInput?.addEventListener("input", (event) => {
|
||||||
const query = event.target.value.trim().toLowerCase();
|
clearTimeout(searchTimeout);
|
||||||
Array.from(tocList?.querySelectorAll("li") ?? []).forEach((item) => {
|
searchTimeout = setTimeout(() => {
|
||||||
const text = item.textContent.toLowerCase();
|
const query = event.target.value.trim().toLowerCase();
|
||||||
item.style.display = text.includes(query) ? "" : "none";
|
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
|
// OCR/formatting errors from epub conversion
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue