Bilibili-Evolved/min/gui-settings.min.js
2019-09-14 14:13:09 +08:00

1 line
4.4 KiB
JavaScript

(()=>{return(e,t)=>{const{ThemeColors:i}=t.import("theme-colors");const{SettingsSearch:n}=t.import("settings-search");const{Validator:s}=t.import("text-validate");let o=[];let c=[];let a=[];function r(e){let t=e.nextElementSibling;const i=[];while(t!==null&&!t.classList.contains("category")){i.push(t);t=t.nextElementSibling}return i}function l(){a.forEach(t=>t.value=e[t.getAttribute("key")]);c.forEach(t=>t.checked=e[t.getAttribute("key")])}function d(){document.querySelector(".gui-settings-mask").addEventListener("click",()=>{document.querySelectorAll(".gui-settings-widgets-box,.gui-settings-box,.gui-settings-mask,.bilibili-evolved-about").forEach(e=>e.classList.remove("opened"))});a.forEach(t=>{t.setAttribute("placeholder",e[t.getAttribute("key")])});document.querySelectorAll(".gui-settings-content ul li.category").forEach(e=>{e.addEventListener("click",e=>{const t=document.querySelector(".gui-settings-search");if(t.value!==""){t.value="";raiseEvent(t,"input")}e.currentTarget.classList.toggle("folded");r(e.currentTarget).forEach(e=>e.classList.toggle("folded"))})});document.querySelectorAll(".gui-settings-dropdown>input").forEach(e=>{e.addEventListener("click",e=>{e.currentTarget.parentElement.classList.toggle("opened")})})}function u(){c.forEach(t=>{t.addEventListener("change",()=>{const i=t.getAttribute("key");const n=t.checked;e[i]=n})});a.forEach(t=>{t.addEventListener("change",()=>{const i=t.getAttribute("key");const n=s.getValidator(i).validate(t.value);e[i]=n;t.value=n})})}function g(){const e=o.map(e=>[e.getAttribute("dependencies").split(" ").map(e=>o.find(t=>t.getAttribute("key")===e)),e]);const t=e=>e.nodeName.toUpperCase()==="LI"?e:t(e.parentElement);e.forEach(([e,i])=>{if(e[0]===undefined){return}const n=()=>{if(e.every(e=>e.checked)){t(i).classList.remove("disabled")}else{t(i).classList.add("disabled")}};e.forEach(e=>e.addEventListener("change",n));n()})}function f(){if(typeof offlineData!=="undefined"){}}function p(){if(!CSS.supports("backdrop-filter","blur(24px)")&&!CSS.supports("-webkit-backdrop-filter","blur(24px)")){o.find(e=>e.getAttribute("key")==="blurVideoControl").disabled=true;e.blurVideoControl=false}if(window.devicePixelRatio===1){o.find(e=>e.getAttribute("key")==="harunaScale").disabled=true;o.find(e=>e.getAttribute("key")==="imageResolution").disabled=true;e.harunaScale=false;e.imageResolution=false}}function b(){for(const[e,t]of Object.entries(Resource.displayNames)){const i=o.find(t=>t.getAttribute("key")===e);if(!i){continue}switch(i.type){case"checkbox":i.nextElementSibling.nextElementSibling.innerHTML=t;break;case"text":const e=i.parentElement;if(e.classList.contains("gui-settings-textbox-container")){i.previousElementSibling.innerHTML=t}else if(e.classList.contains("gui-settings-dropdown")){e.previousElementSibling.innerHTML=t}break;default:break}}}(async()=>{t.applyStyle("guiSettingsStyle");t.applyImportantStyle("iconsStyle");document.body.classList.add("round-corner");const s=document.body&&unsafeWindow.parent.window!==unsafeWindow;if(s){document.querySelector(".gui-settings-icon-panel").style.display="none"}if(e.guiSettingsDockSide==="右侧"){document.body.classList.add("gui-settings-dock-right")}const r=t.data.guiSettingsHtml.text;document.body.insertAdjacentHTML("beforeend",r);const{style:m}=await t.importAsync("mdi");if(!m){document.body.insertAdjacentHTML("afterbegin",`<link rel="stylesheet" href="//cdn.materialdesignicons.com/3.6.95/css/materialdesignicons.min.css">`)}const y=document.querySelector(".widgets-container");const h=y.querySelector(".empty-tip");Observer.childList(y,()=>{if(y.childElementCount<=1){h.classList.add("show")}else{h.classList.remove("show")}});const S=document.querySelectorAll(".gui-settings-widgets-box,.gui-settings-box");const E=document.querySelector(".gui-settings-icon-panel");E.addEventListener("mouseover",async()=>{const{loadTooltip:e}=await t.importAsync("settings-tooltip.loader");await e();await t.applyDropdownOptions();t.applyWidgets();raiseEvent(E,"be:load");raiseEvent(dq(".bilibili-evolved-about"),"be:about-load");(new i).setupDom();S.forEach(e=>e.classList.add("loaded"));o=[...document.querySelectorAll("input[key]")];c=o.filter(e=>e.type==="checkbox");a=o.filter(e=>e.type==="text"&&!e.parentElement.classList.contains("gui-settings-dropdown"));d();f();l();g();u();p();b();addSettingsListener("guiSettingsDockSide",e=>{document.body.classList[e==="右侧"?"add":"remove"]("gui-settings-dock-right")});new n},{once:true})})()}})();