Bilibili-Evolved/min/settings-search.min.js
2019-07-04 11:48:10 +08:00

1 line
1.5 KiB
JavaScript

(()=>{return(t,e)=>{class s{constructor(){this.input=document.querySelector(".gui-settings-search");const t=[...document.querySelectorAll(".gui-settings-content>ul>li")];const e=t=>e=>e.classList.contains("category")===t;this.categories=t.filter(e(true));this.items=t.filter(e(false));this.importToolTips().then(()=>this.input.addEventListener("input",()=>this.keywordChange()))}async importToolTips(){if(typeof getI18nKey==="undefined"){console.error("请更新脚本后再使用设置搜索功能.");return}const{toolTips:t}=await e.importAsync(`settings-tooltip.${getI18nKey()}`);this.toolTips=t}keywordChange(){const t=this.input.value.trim();if(!t){this.categories.concat(this.items).forEach(t=>t.classList.add("folded"));return}this.items.forEach(e=>{const s=e.querySelector("input").getAttribute("key");const i=this.toolTips.get(s);let o=Resource.displayNames[s];if(i!==undefined){o+=i.replace(/<.*>|<\/.*>/g,"")}if(o.includes(t)){e.classList.remove("folded");const t=e.getAttribute("data-dependencies");if(t!==undefined){t.split(" ").forEach(t=>{const e=this.items.find(e=>e.getAttribute("data-key")===t);if(e!==undefined){e.classList.remove("folded")}})}}else{e.classList.add("folded")}});this.foldCategories()}foldCategories(){for(const e of this.categories){function t(){let t=e.nextElementSibling;while(t!==null&&!t.classList.contains("category")){if(!t.classList.contains("folded")){return"remove"}t=t.nextElementSibling}return"add"}e.classList[t()]("folded")}}}return{export:{SettingsSearch:s}}}})();