mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
59 lines
1.9 KiB
JavaScript
59 lines
1.9 KiB
JavaScript
import { toolTips } from "./tooltip/settings-tooltip";
|
|
export class SettingsSearch
|
|
{
|
|
constructor()
|
|
{
|
|
this.input = document.querySelector(".gui-settings-search");
|
|
const items = [...document.querySelectorAll(".gui-settings-content>ul>li")];
|
|
const ifCategory = condition => item => item.classList.contains("category") === condition;
|
|
this.categories = items.filter(ifCategory(true));
|
|
this.items = items.filter(ifCategory(false));
|
|
this.input.addEventListener("input", () => this.keywordChange());
|
|
}
|
|
keywordChange()
|
|
{
|
|
const value = this.input.value.trim();
|
|
if (!value)
|
|
{
|
|
this.categories.concat(this.items).forEach(it => it.classList.add("folded"));
|
|
return;
|
|
}
|
|
this.items.forEach(item =>
|
|
{
|
|
const key = item.querySelector("input").getAttribute("key");
|
|
const texts = Resource.displayNames[key] + toolTips[key].replace(/<span>|<\/span>/g, "");
|
|
if (texts.includes(value))
|
|
{
|
|
item.classList.remove("folded");
|
|
}
|
|
else
|
|
{
|
|
item.classList.add("folded");
|
|
}
|
|
});
|
|
this.foldCategories();
|
|
}
|
|
foldCategories()
|
|
{
|
|
for (const category of this.categories)
|
|
{
|
|
function fold()
|
|
{
|
|
let item = category.nextElementSibling;
|
|
while (item !== null && !item.classList.contains("category"))
|
|
{
|
|
if (!item.classList.contains("folded"))
|
|
{
|
|
return "remove";
|
|
}
|
|
item = item.nextElementSibling;
|
|
}
|
|
return "add";
|
|
}
|
|
category.classList[fold()]("folded");
|
|
}
|
|
}
|
|
}
|
|
export default {
|
|
export: { SettingsSearch },
|
|
}; |