mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
1 line
2.1 KiB
JavaScript
1 line
2.1 KiB
JavaScript
(()=>{return(e,t)=>{var o;(function(e){e[e["Default"]=1]="Default";e[e["ByTime"]=2]="ByTime";e[e["ByLikes"]=3]="ByLikes"})(o||(o={}));const r=(e,t,r=1)=>{if(t===o.ByTime){return Ajax.getJson(`https://api.bilibili.com/x/v2/reply/main?oid=${e}&type=1&mode=${t}`)}return Ajax.getJson(`https://api.bilibili.com/x/v2/reply/main?oid=${e}&type=1&mode=${t}&next=${r}`)};const i=async e=>{if(document.URL.match(/\/\/www\.bilibili\.com\/(video|bangumi)/)){return await SpinQuery.select(()=>unsafeWindow.aid)}console.error("No oid extract method for current context.",e)};const n=async e=>{const t=await i(e);if(t===undefined){return}const n=dq(e,".hot-sort.on")!==null?o.ByLikes:o.ByTime;const s=parseInt(dq(e,".paging-box .current").textContent);const a=await r(t,n,s);if(a.code!==0){console.error("Comment API failed: ",a.message);return}const l=_.flatMap(_.get(a,"data.replies",[]),e=>{const t=[{id:e.rpid_str,floor:e.floor}];if(e.replies!==null){t.push(...e.replies.map(e=>{return{id:e.rpid_str,floor:e.floor}}))}return t});console.log(l);const c=dqa(e,".reply-wrap[data-id]");const d=c.map(e=>dq(e,".reply-wrap > .con > .info, .reply-wrap > .info"));c.forEach((e,t)=>{const o=e.getAttribute("data-id");const r=l.find(e=>e.id===o);if(r!==undefined){const e=d[t];if(e.getAttribute("data-restore-floor")===null){e.insertAdjacentHTML("afterbegin",`<span class="floor">#${r.floor}</span>`);e.setAttribute("data-restore-floor",r.floor.toString())}}})};const s=e=>{const t="comment-loading";if(Array.prototype.some.call(e.children,e=>e.classList.contains(t))){const o=Observer.childList(e,r=>{if(r.some(e=>{Array.prototype.some.call(e.removedNodes,e=>{return e.nodeType===Node.ELEMENT_NODE&&e.classList.contains(t)})})){o.stop();s(e)}})}else{if(e.getAttribute("data-restore-floor")===null){e.setAttribute("data-restore-floor","true");const t=dq(e,".comment-list");Observer.childList(t,_.debounce(t=>{console.log(t);n(e)},100))}}};fullyLoaded(()=>{if(document.URL.match(/\/\/www\.bilibili\.com\/(video|bangumi)/)){const e=_.debounce(()=>dqa(".bb-comment").forEach(e=>s(e)),200);Observer.childListSubtree(document.body,e)}})}})(); |