Delay superchat api calls

This commit is contained in:
the1812 2019-10-15 00:01:22 +08:00
parent 95a74c1e83
commit 77fe30e237
9 changed files with 24 additions and 19 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -139,7 +139,7 @@
"slip.min.js": "0905C7F3B0BFA6535D48CA9A4D2DDCE0EDD83E66AA3D19AA3C1A6A53ECDD15FE",
"style.min.css": "27223BD1ABBB5D8E529B13C009B5099F53F75B26AA713E4C660C205C1121495B",
"superchat-translate.min.css": "F4874FE716A750AE0D21DA44393F286E5AABFFA949476E2FA06CDBE2748CF095",
"superchat-translate.min.js": "06FA00F803DEEEB27ACD6983D52C1D17E7A8CA79EA7F301524DDAF58BBA9D6B3",
"superchat-translate.min.js": "BFD480C237AC2F9D20BD1474C9F6B580388BF19AA6EDB4F16B37C46CCAD04900",
"text-validate.min.js": "3F523485A3EAB6F5BB5C81570A8F4796F13EA00E4A229CFD24CB10DC5B5B61C0",
"theme-colors.min.js": "3001D5DAD0EFBAEC7F96C51FD3BE2C4677E358AD70D8DD019D2280EA450A34E7",
"title.min.js": "340C0A454E4717E5A61F24EBCAC2F67B8B1B1C821FCA86A2ADC5FFA486F1862E",

Binary file not shown.

View File

@ -1 +1 @@
(()=>{return(t,n)=>{(async()=>{if(!document.URL.startsWith("https://live.bilibili.com/")){return}const t=document.URL.match(/live\.bilibili\.com\/(\d+)/);if(!t){return}const e=t[1];const a=await SpinQuery.select(".chat-history-list");if(a===null){console.warn("chatList not found");return}n.applyStyle("superchatTranslateStyle");const s=async()=>{const t=await Ajax.getJson(`https://api.live.bilibili.com/av/v1/SuperChat/getMessageList?room_id=${e}&jpn=1`);if(t.code!==0){console.warn(`getMessageList api failed with ${t.code}`);return[]}return _.get(t,"data.list",[])};const i=async t=>{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 with ${n.code}`);return""}return _.get(n,"data.message_jpn","")};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 n=await s();const e=n.find(n=>n.message===t.innerText);if(!e){console.warn("message not found");return}const a=e.message_jpn||await i(e.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:e.message,translation:a})});Observer.childList(a,t=>{console.log("chat-list");t.forEach(t=>{t.addedNodes.forEach(async t=>{if(t instanceof HTMLElement&&t.classList.contains("superChat-card-detail")){const n=t.getAttribute("data-danmaku");if(!n){console.warn("original not found");return}const e=await s();const a=e.find(t=>t.message===n);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='${n}'] .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})}})})})})()}})();
(()=>{return(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=async t=>{return 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})}})})})})()}})();

View File

@ -2,7 +2,9 @@
"name": "bilibili-evolved",
"description": "「 强大的哔哩哔哩增强脚本 」",
"main": "bilibili-evolved.user.js",
"dependencies": {},
"dependencies": {
"ffmpeg.js": "^3.1.9001"
},
"devDependencies": {
"@types/jquery": "^3.3.31",
"@types/lodash": "^4.14.138",
@ -32,4 +34,4 @@
"url": "https://github.com/the1812/Bilibili-Evolved/issues"
},
"homepage": "https://github.com/the1812/Bilibili-Evolved#readme"
}
}

View File

@ -16,18 +16,22 @@
const getSuperchatMessageList = async () => {
const json = await Ajax.getJson(`https://api.live.bilibili.com/av/v1/SuperChat/getMessageList?room_id=${roomID}&jpn=1`)
if (json.code !== 0) {
console.warn(`getMessageList api failed with ${json.code}`)
console.warn(`getMessageList api failed: ${json.message}`)
return []
}
return _.get(json, 'data.list', [])
}
const getTranslation = async (id: number | string) => {
const json = await Ajax.getJson(`https://api.live.bilibili.com/av/v1/SuperChat/messageInfo?id=${id}`)
if (json.code !== 0) {
console.warn(`messageInfo api failed with ${json.code}`)
return ''
}
return _.get(json, 'data.message_jpn', '')
const getTranslation = async (id: number | string): Promise<string> => {
return new Promise(resolve => {
setTimeout(async () => {
const json = await Ajax.getJson(`https://api.live.bilibili.com/av/v1/SuperChat/messageInfo?id=${id}`)
if (json.code !== 0) {
console.warn(`messageInfo api failed: ${json.message}`)
resolve('')
}
resolve(_.get(json, 'data.message_jpn', ''))
}, 3000)
})
}
Observer.childListSubtree('.pay-note-panel', async () => {
console.log('.pay-note-panel')
@ -54,7 +58,6 @@
})
})
Observer.childList(chatList, records => {
console.log('chat-list')
records.forEach(record => {
record.addedNodes.forEach(async node => {
if (node instanceof HTMLElement && node.classList.contains('superChat-card-detail')) {