mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
1 line
1.7 KiB
JavaScript
1 line
1.7 KiB
JavaScript
(()=>{return(n,t)=>{const{DanmakuInfo:e}=t.import("videoInfo");const{DanmakuConverter:o}=t.import("danmakuConverter");async function a(n,t){const a=document.title.replace("_哔哩哔哩 (゜-゜)つロ 干杯~-bilibili","").replace("_番剧_bilibili_哔哩哔哩","");const i=new e((unsafeWindow||window).cid);await i.fetchInfo();const r=(()=>{if(t===true){const n=new o({title:a,font:"Microsoft YaHei UI",alpha:.6,duration(n){switch(n.type){case 4:case 5:return 4;default:return 10}},blockTypes:[],resolution:{x:1920,y:1080},bottomMarginPercent:.15});const t=n.convertToAssDocument(i.rawXML);return new Blob([t.generateAss()],{type:"text/plain"})}else{return new Blob([i.rawXML],{type:"text/plain"})}})();const c=URL.createObjectURL(r);const s=$("#danmaku-link");const u=s.attr("href");if(u){URL.revokeObjectURL(u)}clearTimeout(n);document.querySelector("#download-danmaku>span").innerHTML="下载弹幕";s.attr("download",`${a}.${t?"ass":"xml"}`).attr("href",c).get(0).click()}return{widget:{content:`\n <button\n class="gui-settings-flat-button"\n id="download-danmaku">\n <i class="icon-danmaku"></i>\n <span>下载弹幕</span>\n <a id="danmaku-link" style="display:none"></a>\n </button>`,condition:async()=>{let n=await SpinQuery.condition(()=>(unsafeWindow||window).cid,n=>n!==undefined);return n!==undefined},success:()=>{const n=document.querySelector("#danmaku-link");$("#download-danmaku").on("click",t=>{if(t.target!==n){const n=setTimeout(()=>document.querySelector("#download-danmaku>span").innerHTML="请稍侯...",200);try{a(n,t.shiftKey)}catch(n){logError(n)}}})}}}}})(); |