mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
1 line
2.0 KiB
JavaScript
1 line
2.0 KiB
JavaScript
(()=>{return(t,e)=>{const{NavbarComponent:a}=e.import("custom-navbar-component");class i extends a{constructor(){super();this.href="https://message.bilibili.com/";this.html="消息";this.popupHtml=`\n<ul id="message-list">\n<li><a data-name="reply" target="_blank" href="https://message.bilibili.com/#/reply">回复我的</a></li>\n<li><a data-name="at" target="_blank" href="https://message.bilibili.com/#/at">@我的</a></li>\n<li><a data-name="like" target="_blank" href="https://message.bilibili.com/#/love">收到的赞</a></li>\n<li><a data-name="user_msg" target="_blank" href="https://message.bilibili.com/#/whisper">我的消息</a></li>\n<li><a data-name="sys_msg" target="_blank" href="https://message.bilibili.com/#/system">系统通知</a></li>\n</ul>\n`;this.requestedPopup=true;this.active=document.URL.startsWith("https://message.bilibili.com/");this.fetchSettings().then(t=>{if(t){this.init()}})}get name(){return"messages"}async fetchSettings(){const t=await Ajax.getJsonWithCredentials(`https://api.vc.bilibili.com/link_setting/v1/link_setting/get?msg_notify=1`);if(t.code!==0){return}await this.setNotifyStyle(t.data.msg_notify);return t.data.msg_notify!==3}async init(){const t=await Ajax.getJsonWithCredentials(`https://api.bilibili.com/x/msgfeed/unread`);const e=await Ajax.getJsonWithCredentials(`https://api.vc.bilibili.com/session_svr/v1/session_svr/single_unread`);const a=await SpinQuery.select("#message-list");const i=[...a.querySelectorAll("a[data-name]")];const s=i.map(t=>t.getAttribute("data-name"));if(t.code!==0||e.code!==0){return}t.data["user_msg"]=e.data.unfollow_unread+e.data.follow_unread;let n=s.reduce((e,a)=>e+t.data[a],0);if(!n){return}await this.setNotifyCount(n);s.forEach((e,a)=>{const s=t.data[e];if(s>0){i[a].setAttribute("data-count",s.toString())}else{i[a].removeAttribute("data-count")}});i.forEach(t=>{t.addEventListener("click",()=>{const e=parseInt(t.getAttribute("data-count"));t.removeAttribute("data-count");n-=e;this.setNotifyCount(n)})})}}return{export:{Messages:i}}}})(); |