mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
1 line
1.8 KiB
JavaScript
1 line
1.8 KiB
JavaScript
(()=>{return(e,t)=>{const n="bb-comment";const r=[];const o=[];const s=[];const c=[];const i=e=>{const t=e.querySelector(".con .user .name");const n={id:e.getAttribute("data-id"),element:e,userID:t.getAttribute("data-usercard-mid"),userName:t.textContent,content:e.querySelector(".con .text").textContent,timeText:e.querySelector(".con .info .time").textContent,likes:parseInt(e.querySelector(".con .like span").textContent),replies:dqa(e,".reply-box .reply-item").map(e=>{const t=e.querySelector(".reply-con .user");return{id:e.getAttribute("data-id"),element:e,userID:t.getAttribute("data-usercard-mid"),userName:t.textContent,content:e.querySelector(".text-con").textContent,timeText:e.querySelector(".info .time").textContent,likes:parseInt(e.querySelector(".info .like span").textContent)}})};return n};const a=e=>{if(e.observer){return}e.items=dqa(e.element,".list-item.reply-wrap").map(i);e.items.forEach(e=>{o.forEach(t=>t(e))});e.observer=Observer.childListSubtree(e.element,t=>{t.forEach(t=>{const n=e=>{return e instanceof HTMLElement&&e.classList.contains("list-item")&&e.classList.contains("reply-wrap")};t.addedNodes.forEach(t=>{if(n(t)){const n=i(t);e.items.push(n);o.forEach(e=>e(n))}});t.removedNodes.forEach(t=>{if(n(t)){const n=t.getAttribute("data-id");const r=e.items.findIndex(e=>e.id===n);if(r!==-1){const[t]=e.items.splice(r,1);s.forEach(e=>e(t))}}})})})};const m=e=>{if(e instanceof HTMLElement&&e.classList.contains(n)){const t={element:e,items:[]};r.push(t);a(t);c.forEach(e=>e(t))}};const d=e=>{r.forEach(t=>e(t));c.push(e)};const u=e=>{const{added:t,removed:n}=e;d(e=>{if(t){e.items.forEach(e=>t(e));o.push(t)}if(n){s.push(n)}})};Observer.childListSubtree(document.body,e=>{e.forEach(e=>{e.addedNodes.forEach(e=>m(e))})});dqa("."+n).forEach(m);return{export:{commentAreas:r,forEachCommentArea:d,forEachCommentItem:u}}}})(); |