Bilibili-Evolved/min/view-cover.min.js
2018-12-23 18:18:06 +08:00

1 line
2.4 KiB
JavaScript

(()=>{return(e,t)=>{const n=t.attributes.videoInfo.export.VideoInfo;class i{constructor(e){this.url=e;if($(".image-viewer").length===0){this.createDom()}this.viewer=$(".image-viewer-container");this.downloadImage()}createDom(){$("body").append(t.data.imageViewerDom.text);$(".image-viewer-container .close").on("click",()=>this.hide());t.applyStyle("imageViewerStyle")}downloadImage(){const e=new XMLHttpRequest;e.open("GET",this.url.replace("http:","https:"),true);e.responseType="blob";e.onload=(()=>{const t=document.title.replace("_哔哩哔哩 (゜-゜)つロ 干杯~-bilibili","").replace("_番剧_bilibili_哔哩哔哩","");const n=URL.createObjectURL(e.response);this.imageData=n;this.viewer.find(".download").attr("href",n).attr("download",t);this.viewer.find(".image").prop("src",n)});e.send()}show(){this.viewer.addClass("opened")}hide(){this.viewer.removeClass("opened")}}if($("meta[itemprop='image'],meta[property='og:image']").length>0){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.condition(()=>(unsafeWindow||window).aid,e=>e!==undefined);return e!=="undefined"},success:async()=>{async function e(){const e=(unsafeWindow||window).aid;const t=new n(e);await t.fetchInfo();return t.coverUrl}let t=new i(await e());$("#view-cover").on("click",()=>{t.show()});(Observer.childList||Observer.subtree)("#bofqi",async()=>{t=new i(await e())})}}}}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.any(()=>$(".header-info-ctnr .room-cover"));return typeof e!=="undefined"},success:async()=>{const e=$(".header-info-ctnr .room-cover");const t=e.attr("href").match(/space\.bilibili\.com\/([\d]+)/);if(t&&t[1]){const e=t[1];const n=`https://api.live.bilibili.com/room/v1/Room/getRoomInfoOld?mid=${e}`;const o=await downloadText(n);const s=JSON.parse(o).data.cover;const a=new i(s);$("#view-cover").on("click",()=>{a.show()})}}}}}}})();