mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
1 line
3.9 KiB
JavaScript
1 line
3.9 KiB
JavaScript
(()=>{return(e,t)=>{const r={repost:{id:1,name:"转发"},textWithImages:{id:2,name:"图文"},text:{id:4,name:"文字"},video:{id:8,name:"视频"},miniVideo:{id:16,name:"小视频"},column:{id:64,name:"专栏"},audio:{id:256,name:"音频"},bangumi:{id:512,name:"番剧"},share:{id:2048,name:"分享"}};class n extends EventTarget{constructor(){super(...arguments);this.cards=[]}addEventListener(e,t,r){super.addEventListener(e,t,r)}removeEventListener(e,t,r){super.removeEventListener(e,t,r)}addCard(e){if(e instanceof HTMLElement&&e.classList.contains("card")){if(e.querySelector(".skeleton")!==null){const t=Observer.childList(e,()=>{if(e.querySelector(".skeleton")===null){t.forEach(e=>e.stop());this.addCard(e)}})}else{const t=this.parseCard(e);this.cards.push(t);const r=new CustomEvent("addCard",{detail:t});this.dispatchEvent(r)}}}removeCard(e){if(e instanceof HTMLElement&&e.classList.contains("card")){const t=this.parseCard(e).id;const r=this.cards.findIndex(e=>e.id===t);const n=this.cards[r];this.cards.splice(r,1);const i=new CustomEvent("removeCard",{detail:n});this.dispatchEvent(i)}}parseCard(e){const t=t=>{if(e.querySelector(t)===null){console.warn(e,t);return""}return e.querySelector(t).innerText};const n=e=>{const r=parseInt(t(e));if(isNaN(r)){return 0}return r};const i=(()=>{if(e.querySelector(".repost")){return r.repost}if(e.querySelector(".imagesbox")){return r.textWithImages}if(e.querySelector(".video-container")){return r.video}if(e.querySelector(".bangumi-container")){return r.bangumi}if(e.querySelector(".article-container")){return r.column}if(e.querySelector(".music-container")){return r.audio}if(e.querySelector(".h5share-container")){return r.share}if(e.querySelector(".vc-ctnr")){return r.miniVideo}return r.text})();const a={id:e.getAttribute("data-did"),username:t(".main-content .user-name"),text:t(".card-content .text.description"),reposts:n(".button-bar .single-button:nth-child(1) .text-offset"),comments:n(".button-bar .single-button:nth-child(2) .text-offset"),likes:n(".button-bar .single-button:nth-child(3) .text-offset"),element:e,type:i};e.setAttribute("data-type",i.id.toString());return a}async startWatching(){const e=await SpinQuery.select(".card-list .content");if(!e){return false}const t=[...e.querySelectorAll(".content>.card")];t.forEach(e=>this.addCard(e));Observer.childList(e,e=>{e.forEach(e=>{e.addedNodes.forEach(e=>this.addCard(e));e.removedNodes.forEach(e=>this.removeCard(e))})});return true}}const i=new n;const a=async(e="video")=>{const r=await Ajax.getJsonWithCredentials(`https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/dynamic_new?uid=${getUID()}&type_list=${e==="video"?8:512}`);if(r.code!==0){throw new Error(r.message)}if(e==="video"){const{getWatchlaterList:e}=await t.importAsync("watchlater-api");const n=await e();return r.data.cards.map(e=>{const t=JSON.parse(e.card);const r=_.get(e,"display.topic_info.topic_details",[]).map(e=>{return{id:e.topic_id,name:e.topic_name}});return{id:e.desc.dynamic_id_str,aid:t.aid,title:t.title,upID:e.desc.user_profile.info.uid,upName:e.desc.user_profile.info.uname,upFaceUrl:e.desc.user_profile.info.face,coverUrl:t.pic,description:t.desc,timestamp:e.timestamp,time:new Date(e.timestamp*1e3),topics:r,dynamic:t.dynamic,like:formatCount(e.desc.like),duration:t.duration,durationText:formatDuration(t.duration,0),playCount:formatCount(t.stat.view),danmakuCount:formatCount(t.stat.danmaku),watchlater:n.includes(t.aid)}})}else if(e==="bangumi"){return r.data.cards.map(e=>{const t=JSON.parse(e.card);return{id:e.desc.dynamic_id_str,aid:t.aid,epID:t.episode_id,title:t.new_desc,upName:t.apiSeasonInfo.title,upFaceUrl:t.apiSeasonInfo.cover,coverUrl:t.cover,description:"",timestamp:e.timestamp,time:new Date(e.timestamp*1e3),like:formatCount(e.desc.like),durationText:"",playCount:formatCount(t.play_count),danmakuCount:formatCount(t.bullet_count),watchlater:false}})}else{return[]}};return{export:{feedsCardsManager:i,feedsCardTypes:r,getVideoFeeds:a}}}})(); |