Reputation: 111
I'm making a dictionary website for Lojban. It's relatively simple: load a premade <div id="entries">
and move all the entries with an innerText
containing the search query into div#results
.
There are no entries containing the string u.a
, yet a result for one exists, whose innerText
contains u\n\na
. The innerText
in search(query)
seems to be removing newlines, even though (a) it shouldn't do that (b) running document.querySelector("#results .entry").innerText.includes("u.a")
returns false
.
Running .replaceAll(/\n+g/, " ")
on the innerText
before finding the search query in it
const id = (x) => document.getElementById(x);
function search(query) {
var i = 0;
var results = [];
for (const entry of id("entries").childNodes) {
const text = entry.innerText.replaceAll(/\n+/g, " ");
if (text.includes(query)) {
console.log(text, query, text.includes(query));
results.push(entry);
i++;
}
}
return [i, results];
}
// ... lazy-loading function ...
var timer;
id("search").addEventListener("input", function() {
clearTimeout(timer);
id("status").innerHTML = "<span>.....</span>";
const q = id("search").value;
let page = 0;
if (observer) {
observer.disconnect();
}
timer = setTimeout(function() {
if (q.length != 0) {
const s = search(q);
const l = String(s[0]);
const res = s[1];
const pad = "<span>" + "0".repeat(5 - l.length) + "</span>";
id("status").innerHTML = pad + l;
id("results").innerHTML = "";
// ... lazy-loading + url updating ...
} else {
id("status").innerHTML = "";
id("results").innerHTML = "";
page = 0;
}
}, 100);
});
Upvotes: 0
Views: 98
Reputation: 111
Solved this by adding one space character to my database-generating program. lol
Upvotes: 0