Bilibili-Evolved/min/custom-navbar-settings.min.js
2021-10-26 13:22:15 +08:00

1 line
3.8 KiB
JavaScript

(()=>(e,t)=>{const s=async()=>{await SpinQuery.select(".custom-navbar-settings");const{Slip:s}=await t.importAsync("slip");const a=dq("#custom-navbar-settings");a.addEventListener("click",(async()=>{const e=dq(".custom-navbar-settings");if(e){e.classList.toggle("show");dq(".gui-settings-mask").click()}}));a.addEventListener("mouseover",(()=>{const t={blank1:"弹性空白1",logo:"Logo",category:"主站",rankingLink:"排行",drawingLink:"相簿",bangumiLink:"番剧",musicLink:"音频",gamesIframe:"游戏中心",livesIframe:"直播",matchLink:"赛事",shopLink:"会员购",mangaIframe:"漫画",blank2:"弹性空白2",search:"搜索框",userInfo:"用户信息",messages:"消息",activities:"动态",bangumi:"订阅",watchlaterList:"稍后再看",favoritesList:"收藏",historyList:"历史",upload:"投稿入口",blank3:"弹性空白3",darkMode:"夜间模式开关"};Vue.component("order-item",{props:["item"],template:`\n<li @mouseenter="viewBorder(true)"\n @mouseleave="viewBorder(false)"\n :class="{hidden: hidden()}">\n<i class="mdi mdi-menu"></i>\n {{item.displayName}}\n<button @click="toggleHidden()">\n<i v-if="hidden()" class="mdi mdi-eye-off"></i>\n<i v-else class="mdi mdi-eye"></i>\n</button>\n</li>\n`,methods:{hidden(){return e.customNavbarHidden.includes(this.item.name)},viewBorder(e){const t=dq(`.custom-navbar li[data-name='${this.item.name}']`);if(t!==null){t.classList.toggle("view-border",e)}},toggleHidden(){const t=this.hidden();if(t===false){e.customNavbarHidden.push(this.item.name)}else{const t=e.customNavbarHidden.indexOf(this.item.name);if(t===-1){return}e.customNavbarHidden.splice(t,1)}this.$forceUpdate();const s=dq(`.custom-navbar li[data-name='${this.item.name}']`);if(s!==null){s.style.display=t?"flex":"none"}e.customNavbarHidden=e.customNavbarHidden}}});const a=_.debounce((t=>{document.documentElement.style.setProperty("--navbar-bounds-padding",`0 ${t}%`);e.customNavbarBoundsPadding=t}),200);new Vue({el:".custom-navbar-settings",mounted(){const t=dq(".custom-navbar-settings .order-list");const a=({sourceItem:s,targetItem:a,orderBefore:n,orderAfter:r})=>{if(n===r){return}const i=Object.entries(e.customNavbarOrder).filter((([e])=>e in customNavbarDefaultOrders));const o=i.sort(((e,t)=>e[1]-t[1])).map((e=>e[0]));if(n<r){for(let t=n+1;t<=r;t++){const s=o[t];e.customNavbarOrder[s]=t-1;const a=dq(`.custom-navbar li[data-name='${s}']`);a.style.order=(t-1).toString()}}else{for(let t=n-1;t>=r;t--){const s=o[t];e.customNavbarOrder[s]=t+1;const a=dq(`.custom-navbar li[data-name='${s}']`);a.style.order=(t+1).toString()}}e.customNavbarOrder[o[n]]=r;const d=dq(`.custom-navbar li[data-name='${o[n]}']`);d.style.order=r.toString();t.insertBefore(s,a);e.customNavbarOrder=e.customNavbarOrder};new s(t);t.addEventListener("slip:beforewait",(e=>{if(e.target.classList.contains("mdi-menu")){e.preventDefault()}}),false);t.addEventListener("slip:beforeswipe",(e=>e.preventDefault()),false);t.addEventListener("slip:reorder",(e=>{a({sourceItem:e.target,targetItem:e.detail.insertBefore,orderBefore:e.detail.originalIndex,orderAfter:e.detail.spliceIndex});return false}),false)},computed:{orderList(){const s=Object.entries(e.customNavbarOrder);return s.filter((e=>e[0]in t)).sort(((e,t)=>e[1]-t[1])).map((e=>({displayName:t[e[0]],name:e[0],order:e[1]})))}},data:{boundsPadding:e.customNavbarBoundsPadding},watch:{boundsPadding(e){a(e)}},methods:{close(){dq(".custom-navbar-settings").classList.remove("show")},restoreDefault(){if(typeof customNavbarDefaultOrders==="undefined"){Toast.error("未找到默认值设定, 请更新您的脚本.","自定义顶栏",3e3);return}if(confirm("确定要恢复默认顶栏布局吗? 恢复后页面将刷新.")){this.boundsPadding=5;e.customNavbarOrder=customNavbarDefaultOrders;location.reload()}}}})}),{once:true})};return{export:{initSettingsPanel:s}}})();