(()=>(t,i)=>{const{NavbarComponent:e}=i.import("custom-navbar-component");let a=async()=>{};let n=async()=>{};let s;const c=({dataObject:t,apiUrl:e,name:n,handleJson:s,nextPage:c,template:r})=>{const d={template:r,components:{"dpi-img":()=>i.importAsync("dpi-img.vue")},methods:{handleJson:s,async fetchData(t=false){try{const t=await Ajax.getJsonWithCredentials(e);if(t.code!==0){throw new Error(t.message)}await this.handleJson(t)}catch(i){if(t===true){return}logError(`加载${n}动态失败, error = ${i}`)}finally{this.loading=false}}},data(){return Object.assign({loading:true,hasMoreContent:true,scrollObserver:null},t)},async mounted(){a=async()=>await this.fetchData(true);await this.fetchData();if(this.$refs.trigger&&typeof this.nextPage==="function"){console.log("infinite scroll");const t=this.$refs.trigger;const i=new IntersectionObserver((async t=>{console.log(t);if(t.some((t=>t.intersectionRatio>0))){const t=await this.nextPage();if(!t){console.log("disconnect");i.disconnect();this.hasMoreContent=false}}}));this.scrollObserver=i;i.observe(t)}},beforeDestroy(){a=async()=>{};if(this.scrollObserver){console.log("destroy");this.scrollObserver.disconnect();this.scrollObserver=null}}};if(c){d.methods.nextPage=c}return d};class r extends e{constructor(){super();this.boundingWidth=380;this.noPadding=true;this.href=t.oldTweets?"https://www.bilibili.com/account/dynamic":"https://t.bilibili.com/";this.html="动态";this.popupHtml=`\n
\n\n
\n\n\n\n \x3c!-- 查看更多 --\x3e\n
\n
\n`;this.active=document.URL.replace(/\?.*$/,"")===this.href;this.initialPopup=()=>{this.init()};this.onPopup=()=>{this.setNotifyCount(0)};this.getNotifyCount();setInterval((async()=>{if(!navigator.onLine){return}await this.getNotifyCount();await n();await a()}),r.updateInterval)}static get updateInterval(){return 5*60*1e3}static getLatestID(){return document.cookie.replace(new RegExp(`(?:(?:^|.*;\\s*)bp_t_offset_${getUID()}\\s*\\=\\s*([^;]*).*$)|^.*$`),"$1")}static setLatestID(t){if(t===null||t===undefined){return}const i=r.getLatestID();if(r.compareID(t,i)<0){return}document.cookie=`bp_t_offset_${getUID()}=${t};path=/;domain=.bilibili.com;max-age=${60*60*24*30}`}static compareID(t,i){if(t===i){return 0}if(t.length>i.length){return 1}if(i.length>t.length){return-1}return t>i===true?1:-1}static isNewID(t){return r.compareID(t,s)>0}static updateLatestID(t){const[i]=[...t.map((t=>t.id))].sort(r.compareID).reverse();r.setLatestID(i)}async getNotifyCount(){const t=`https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/dynamic_num?rsp_type=1&uid=${getUID()}&update_num_dy_id=${r.getLatestID()}&type_list=8,64,512`;const i=await Ajax.getJsonWithCredentials(t);if(i.code!==0){return}this.setNotifyCount(i.data.update_num)}async init(){const{isVideoCardBlocked:e,isCardBlocked:a,isPreOrderedVideo:s}=await i.importAsync("feeds-apis");Vue.component("activity-loading",{template:`\n
\n加载中...\n
`,props:["loading"]});Vue.component("activity-empty",{template:`\n
空空如也哦 = ̄ω ̄=
`});new Vue({el:await SpinQuery.select(".activity-popup"),data:{tabs:[{name:"视频",component:"video-activity",moreUrl:"https://t.bilibili.com/?tab=8",get notifyApi(){return`https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/dynamic_num?rsp_type=1&uid=${getUID()}&update_num_dy_id=${r.getLatestID()}&type_list=8`},notifyCount:null},{name:"番剧",component:"bangumi-activity",moreUrl:"https://t.bilibili.com/?tab=512,4097,4098,4099,4100,4101",get notifyApi(){return`https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/dynamic_num?rsp_type=1&uid=${getUID()}&update_num_dy_id=${r.getLatestID()}&type_list=512`},notifyCount:null},{name:"专栏",component:"column-activity",moreUrl:"https://t.bilibili.com/?tab=64",get notifyApi(){return`https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/dynamic_num?rsp_type=1&uid=${getUID()}&update_num_dy_id=${r.getLatestID()}&type_list=64`},notifyCount:null},{name:"直播",component:"live-activity",moreUrl:"https://link.bilibili.com/p/center/index#/user-center/follow/1",notifyCount:null}],selectedTab:"视频"},components:{"activity-tabs":{props:["items","tab"],template:`\n\n`,methods:{changeTab(t){if(this.tab===t.name){window.open(t.moreUrl,"_blank")}this.$emit("update:tab",t.name)}}},"video-activity":Object.assign(c({dataObject:{leftCards:[],rightCards:[]},apiUrl:`https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/dynamic_new?uid=${getUID()}&type_list=8`,name:"视频",template:`\n
\n\n\n
\n\n
\n
\n\n
\n
加载中...
\n
\n`,async handleJson(t){const i=Number(new Date);const a=i-1e3*3600*24;const n=t=>{const e=new Date(t);const a=[e.getHours(),e.getMinutes(),e.getSeconds()].map((t=>t.toString().padStart(2,"0"))).join(":");let n;if(new Date(i).getFullYear()!==e.getFullYear()){n=[e.getFullYear(),e.getMonth()+1,e.getDate()]}else{n=[e.getMonth()+1,e.getDate()]}return`${n.map((t=>t.toString().padStart(2,"0"))).join("-")} ${a}`};const s=t=>{if(at.toString().padStart(2,"0"))).join("-")}`};const c=_.get(t,"data.cards",[]).map((t=>{const i=JSON.parse(t.card);return{coverUrl:i.pic,title:i.title,timeNumber:i.duration,time:formatDuration(i.duration),description:i.desc,aid:i.aid,bvid:t.desc.bvid,videoUrl:`https://www.bilibili.com/${t.desc.bvid}`,faceUrl:t.desc.user_profile.info.face,upName:t.desc.user_profile.info.uname,upUrl:`https://space.bilibili.com/${t.desc.user_profile.info.uid}`,id:t.desc.dynamic_id_str,pubTime:n(i.pubdate*1e3),pubTimeText:s(i.pubdate*1e3),watchlater:true,get new(){return r.isNewID(this.id)}}}));const d=_.uniqBy(c.concat(this.leftCards,this.rightCards),(t=>t.aid)).sort(((t,i)=>i.id>t.id?1:-1)).filter((t=>!e(t)));if(d.length===0){this.hasMoreContent=false}this.leftCards=d.filter(((t,i)=>i%2===0));this.rightCards=d.filter(((t,i)=>i%2===1));r.updateLatestID(d)},async nextPage(){const t=[...this.leftCards,...this.rightCards].sort(((t,i)=>i.id>t.id?1:-1));if(t.length===0){return false}let i=t.pop().id;const e=`https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/dynamic_history?uid=${getUID()}&offset_dynamic_id=${i}&type=8`;const a=await Ajax.getJsonWithCredentials(e);console.log("lastCardID",i,a);if(a.code!==0){return false}await this.handleJson(a);return Boolean(_.get(a,"data.has_more",true))}}),{components:{"video-card":{props:["card","watchlaterInit"],store:store,data(){return{}},computed:{...Vuex.mapState(["watchlaterList"]),watchlater(){if(this.watchlaterInit!==null){return this.watchlaterList.includes(this.card.aid)}else{return null}}},components:{"dpi-img":()=>i.importAsync("dpi-img.vue")},methods:{...Vuex.mapActions(["toggleWatchlater"])},async mounted(){},template:`\n\n
\n\n
{{card.time}}
\n
{{card.pubTimeText}}
\n
{{card.pubTime}}
\n
{{watchlater ? '已添加' : '稍后再看'}}
\n
\n

{{card.title}}

\n
\n\n{{card.upName}}\n\n\n`}}}),"bangumi-activity":c({dataObject:{cards:[]},apiUrl:`https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/dynamic_new?uid=${getUID()}&type_list=512`,name:"番剧",template:`\n
\n\n\n\n\n

{{card.epTitle}}

\n
\n\n
{{card.title}}
\n
\n
\n
加载中...
\n
\n`,handleJson:async function(t){const i=_.get(t,"data.cards",[]).filter((t=>!s(t))).map((t=>{const i=JSON.parse(t.card);return{title:i.apiSeasonInfo.title,coverUrl:i.apiSeasonInfo.cover,epCoverUrl:i.cover,epTitle:i.new_desc,url:i.url,id:t.desc.dynamic_id_str,get new(){return r.isNewID(this.id)}}}));this.cards=_.uniqBy(i.concat(this.cards),(t=>t.id)).sort(((t,i)=>i.id>t.id?1:-1)).filter((t=>!a({text:t.epTitle,username:t.title})));if(i.length===0){this.hasMoreContent=false}r.updateLatestID(i)},async nextPage(){const t=[...this.cards];if(t.length===0){return false}let i=t.pop().id;const e=`https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/dynamic_history?uid=${getUID()}&offset_dynamic_id=${i}&type=512`;const a=await Ajax.getJsonWithCredentials(e);console.log("lastCardID",i,a);if(a.code!==0){return false}await this.handleJson(a);return Boolean(_.get(a,"data.has_more",true))}}),"column-activity":c({dataObject:{cards:[]},apiUrl:`https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/dynamic_new?uid=${getUID()}&type_list=64`,name:"专栏",template:`\n
\n\n\n\n\n

{{card.title}}

\n
{{card.description}}
\n\n
加载中...
\n
\n`,handleJson:async function(t){const i=_.get(t,"data.cards",[]).filter((t=>!s(t))).map((t=>{const i=JSON.parse(t.card);return{covers:i.image_urls,originalCovers:i.origin_image_urls,upName:i.author.name,faceUrl:i.author.face,upUrl:`https://space.bilibili.com/${i.author.mid}`,title:i.title,description:i.summary,url:`https://www.bilibili.com/read/cv${i.id}`,id:t.desc.dynamic_id_str,get new(){return r.isNewID(this.id)}}}));this.cards=_.uniqBy(i.concat(this.cards),(t=>t.id)).sort(((t,i)=>i.id>t.id?1:-1)).filter((t=>!e(t)));if(i.length===0){this.hasMoreContent=false}r.updateLatestID(this.cards)},async nextPage(){const t=[...this.cards];if(t.length===0){return false}let i=t.pop().id;const e=`https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/dynamic_history?uid=${getUID()}&offset_dynamic_id=${i}&type=64`;const a=await Ajax.getJsonWithCredentials(e);console.log("lastCardID",i,a);if(a.code!==0){return false}await this.handleJson(a);return Boolean(_.get(a,"data.has_more",true))}}),"live-activity":c({dataObject:{cards:[]},apiUrl:`https://api.live.bilibili.com/relation/v1/feed/feed_list?page=1&pagesize=24`,name:"直播",template:`\n
\n\n\n\n\n

{{card.title}}

\n
{{card.name}}
\n
\n
\n`,handleJson:async function(t){const i=t=>({faceUrl:t.face,title:t.title,name:t.uname,id:t.roomid,url:t.link});this.cards=_.get(t,"data.list",[]).map(i);const e=await Ajax.getPages({api:t=>Ajax.getJsonWithCredentials(`https://api.live.bilibili.com/relation/v1/feed/feed_list?page=${t}&pagesize=24`),getList:t=>_.get(t,"data.list",[]),getTotal:t=>_.get(t,"data.results",0)});this.cards=e.map(i)}})},computed:{content(){return this.tabs.find((t=>t.name===this.selectedTab)).component},viewMoreUrl(){return this.tabs.find((t=>t.name===this.selectedTab)).moreUrl}},mounted(){n=async()=>{for(const t of this.tabs){if(t.notifyApi){const i=await Ajax.getJsonWithCredentials(t.notifyApi);if(i.code!==0||!i.data.update_num||this.selectedTab===t.name){continue}t.notifyCount=i.data.update_num}}};n()},destroyed(){n=async()=>{}},watch:{selectedTab(t){this.tabs.find((i=>i.name===t)).notifyCount=null}}})}get name(){return"activities"}}s=r.getLatestID();return{export:{Activities:r}}})();