mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
1 line
3.0 KiB
JavaScript
1 line
3.0 KiB
JavaScript
(()=>{return(e,t)=>{const{VideoInfo:i}=t.import("video-info");const{getFriendlyTitle:n}=t.import("title");class o{constructor(e){this.url=e;if(document.querySelector(".image-viewer")===null){this.createContainer()}this.viewer=document.querySelector(".image-viewer-container");this.downloadImage();addSettingsListener("filenameFormat",()=>{this.viewer.querySelector(".download").setAttribute("download",this.filename)})}createContainer(){document.body.insertAdjacentHTML("beforeend",t.import("imageViewerHtml"));const e=dq(".image-viewer-container");const i=dq(".image-viewer");dq(e,".close").addEventListener("click",()=>this.hide());dq(".image-viewer-container").addEventListener("click",t=>{if(t.target===e||t.target===i){this.hide()}});t.applyStyle("imageViewerStyle")}downloadImage(){document.querySelector("#view-cover").style.display=this.url?"flex":"none";if(this.url===""){return}const e=new XMLHttpRequest;e.open("GET",this.url.replace("http:","https:"),true);e.responseType="blob";e.onload=(()=>{const t=URL.createObjectURL(e.response);if(this.imageData){URL.revokeObjectURL(this.imageData)}this.imageData=t;const i=this.viewer.querySelector(".download");i.setAttribute("href",t);i.setAttribute("download",this.filename);this.viewer.querySelector(".copy-link").addEventListener("click",()=>GM.setClipboard(this.url));this.viewer.querySelector(".new-tab").setAttribute("href",this.url);this.viewer.querySelector(".image").src=t});e.send()}show(){this.viewer.classList.add("opened")}hide(){this.viewer.classList.remove("opened")}get filename(){return n(document.URL.includes("/www.bilibili.com/bangumi/"))+this.url.substring(this.url.lastIndexOf("."))}}return(()=>{if(!document.URL.includes("live.bilibili.com")){return{widget:{content:`\n<button\n class="gui-settings-flat-button"\n id="view-cover">\n<i class="icon-view"></i>\n<span>查看封面</span>\n</button>`,condition:async()=>{const e=await SpinQuery.select(()=>(unsafeWindow||window).aid);return Boolean(e)},success:async()=>{async function e(){const e=(unsafeWindow||window).aid;const t=new i(e);try{await t.fetchInfo()}catch(e){return""}return t.coverUrl}let t=new o(await e());document.querySelector("#view-cover").addEventListener("click",()=>{t.show()});const n=async()=>{t=new o(await e())};Observer.videoChange(n)}}}}else{return{widget:{content:`\n<button\n class="gui-settings-flat-button"\n id="view-cover">\n<i class="icon-view"></i>\n<span>查看封面</span>\n</button>`,condition:async()=>{const e=await SpinQuery.select(()=>document.querySelector(".header-info-ctnr .room-cover"));return Boolean(e)},success:async()=>{const e=document.querySelector(".header-info-ctnr .room-cover");const t=e.getAttribute("href").match(/space\.bilibili\.com\/([\d]+)/);if(t&&t[1]){const e=t[1];const i=`https://api.live.bilibili.com/room/v1/Room/getRoomInfoOld?mid=${e}`;const n=await Ajax.getJson(i);const r=n.data.cover;const s=new o(r);document.querySelector("#view-cover").addEventListener("click",()=>{s.show()})}}}}}})()}})(); |