Resolve various script warnings

This commit is contained in:
Jared Miller 2025-12-25 09:32:31 -05:00
parent 4f735bac3c
commit 2b242229e9
No known key found for this signature in database

View file

@ -1,3 +1,5 @@
// @ts-nocheck
const cleanTerm = (text) => text.replace(/\s+/g, " ").replace(/\.$/, "").trim();
const slugify = (text) =>
@ -38,7 +40,7 @@ termEntries.forEach(([term, id]) => {
link.textContent = term;
const item = document.createElement("li");
item.appendChild(link);
tocList.appendChild(item);
tocList?.appendChild(item);
});
Array.from(firstByLetter.entries())
@ -47,13 +49,13 @@ Array.from(firstByLetter.entries())
const link = document.createElement("a");
link.href = `#${id}`;
link.textContent = letter;
tocLetters.appendChild(link);
tocLetters?.appendChild(link);
});
const searchInput = document.getElementById("toc-search");
searchInput.addEventListener("input", (event) => {
searchInput?.addEventListener("input", (event) => {
const query = event.target.value.trim().toLowerCase();
Array.from(tocList.querySelectorAll("li")).forEach((item) => {
Array.from(tocList?.querySelectorAll("li") ?? []).forEach((item) => {
const text = item.textContent.toLowerCase();
item.style.display = text.includes(query) ? "" : "none";
});
@ -252,10 +254,9 @@ const linkifyTextNode = (node) => {
node.parentNode.replaceChild(fragment, node);
};
const walker = document.createTreeWalker(
document.getElementById("content"),
NodeFilter.SHOW_TEXT,
{
const contentEl = document.getElementById("content");
if (contentEl) {
const walker = document.createTreeWalker(contentEl, NodeFilter.SHOW_TEXT, {
acceptNode: (node) => {
const parent = node.parentElement;
if (!parent) {
@ -269,15 +270,15 @@ const walker = document.createTreeWalker(
}
return NodeFilter.FILTER_ACCEPT;
},
},
);
});
const nodesToLinkify = [];
while (walker.nextNode()) {
const nodesToLinkify = [];
while (walker.nextNode()) {
nodesToLinkify.push(walker.currentNode);
}
}
nodesToLinkify.forEach((node) => linkifyTextNode(node));
nodesToLinkify.forEach((node) => linkifyTextNode(node));
}
// TOC collapse/expand toggle
const tocToggle = document.createElement("button");
@ -290,7 +291,7 @@ const toc = document.querySelector(".toc");
const layout = document.querySelector(".layout");
tocToggle.addEventListener("click", () => {
toc.classList.toggle("collapsed");
layout.classList.toggle("toc-hidden");
toc?.classList.toggle("collapsed");
layout?.classList.toggle("toc-hidden");
document.body.classList.toggle("toc-collapsed");
});