mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
1 line
2.2 KiB
JavaScript
1 line
2.2 KiB
JavaScript
(()=>(t,e)=>{(async()=>{if(!document.URL.startsWith("https://live.bilibili.com/")){return}const t=document.URL.match(/live\.bilibili\.com\/(\d+)/);if(!t){return}const n=t[1];const a=await SpinQuery.select(".chat-history-list");if(a===null){console.warn("chatList not found");return}e.applyStyle("superchatTranslateStyle");const s=async()=>{const t=await Ajax.getJson(`https://api.live.bilibili.com/av/v1/SuperChat/getMessageList?room_id=${n}&jpn=1`);if(t.code!==0){console.warn(`getMessageList api failed: ${t.message}`);return[]}return _.get(t,"data.list",[])};const i=t=>new Promise((e=>{setTimeout((async()=>{const n=await Ajax.getJson(`https://api.live.bilibili.com/av/v1/SuperChat/messageInfo?id=${t}`);if(n.code!==0){console.warn(`messageInfo api failed: ${n.message}`);e("")}e(_.get(n,"data.message_jpn",""))}),3e3)}));Observer.childListSubtree(".pay-note-panel",(async()=>{console.log(".pay-note-panel");const t=dq(".detail-info .input-contain .text:not(.original):not(.jpn)");if(!t){return}const e=await s();const n=e.find((e=>e.message===t.innerText));if(!n){console.warn("message not found");return}const a=n.message_jpn||await i(n.id);t.classList.add("original");const o=document.createElement("span");o.classList.add("text","jpn");o.style.opacity=".5";o.innerText=a;t.insertAdjacentElement("afterend",o);console.log(`inserted translation: `,{original:n.message,translation:a})}));Observer.childList(a,(t=>{t.forEach((t=>{t.addedNodes.forEach((async t=>{if(t instanceof HTMLElement&&t.classList.contains("superChat-card-detail")){const e=t.getAttribute("data-danmaku");if(!e){console.warn("original not found");return}const n=await s();const a=n.find((t=>t.message===e));if(!a){console.warn("message not found");return}const o=a.message_jpn||await i(a.id);const r=await SpinQuery.select(`.superChat-card-detail[data-danmaku='${e}'] .input-contain .text:not(.original):not(.jpn)`);if(!r){console.warn("textElement not found");return}r.classList.add("original");const c=document.createElement("span");c.classList.add("text","jpn");c.style.opacity=".5";c.innerText=o;r.insertAdjacentElement("afterend",c);console.log(`inserted translation: `,{original:a.message,translation:o})}}))}))}))})()})(); |