2024-12-09 08:27:01 +01:00
|
|
|
document.addEventListener("DOMContentLoaded", () => {
|
|
|
|
if (!window.location.pathname.endsWith("options.html")) return;
|
|
|
|
|
|
|
|
const searchDiv = document.createElement("div");
|
|
|
|
searchDiv.id = "search-bar";
|
|
|
|
searchDiv.innerHTML = `
|
|
|
|
<input type="text" id="search-input" placeholder="Search options by ID..." />
|
|
|
|
<div id="search-results"></div>
|
|
|
|
`;
|
|
|
|
document.body.prepend(searchDiv);
|
|
|
|
|
|
|
|
const dtElements = Array.from(document.querySelectorAll("dt"));
|
|
|
|
const ddElements = Array.from(document.querySelectorAll("dd"));
|
|
|
|
const dtOptionIds = dtElements.map(
|
|
|
|
(dt) => dt.querySelector("a")?.id.toLowerCase() || "",
|
|
|
|
);
|
|
|
|
|
|
|
|
if (dtElements.length === 0 || ddElements.length === 0) {
|
|
|
|
console.warn("Something went wrong, page may be loaded incorrectly.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-12-10 15:15:23 +01:00
|
|
|
const dtElementsData = dtElements.map((dt, index) => ({
|
|
|
|
element: dt,
|
|
|
|
id: dtOptionIds[index],
|
|
|
|
ddElement: ddElements[index],
|
|
|
|
}));
|
|
|
|
|
2024-12-09 08:27:01 +01:00
|
|
|
let debounceTimeout;
|
|
|
|
document.getElementById("search-input").addEventListener("input", (event) => {
|
|
|
|
clearTimeout(debounceTimeout);
|
|
|
|
debounceTimeout = setTimeout(() => {
|
|
|
|
const query = event.target.value.toLowerCase();
|
|
|
|
|
2024-12-10 15:15:23 +01:00
|
|
|
requestAnimationFrame(() => {
|
|
|
|
const fragment = document.createDocumentFragment();
|
|
|
|
dtElementsData.forEach(({ element, id, ddElement }) => {
|
|
|
|
const isMatch = id.includes(query);
|
|
|
|
if (element.classList.contains("hidden") !== !isMatch) {
|
|
|
|
element.classList.toggle("hidden", !isMatch);
|
|
|
|
ddElement?.classList.toggle("hidden", !isMatch);
|
|
|
|
}
|
|
|
|
});
|
2024-12-09 08:27:01 +01:00
|
|
|
});
|
|
|
|
}, 200);
|
|
|
|
});
|
|
|
|
});
|