Bilibili-Evolved/min/view-cover.min.js
2018-12-02 19:43:42 +08:00

1 line
2.2 KiB
JavaScript

(()=>{return(e,t)=>{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","");const i=URL.createObjectURL(e.response);this.imageData=i;this.viewer.find(".download").attr("href",i).attr("download",t);this.viewer.find(".image").prop("src",i)});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="hidden gui-settings-flat-button"\n id="view-cover">\n <i class="icon-view"></i>\n <span>查看封面</span>\n </button>`,success:async()=>{const e=await SpinQuery.condition(()=>$("meta[itemprop='image'],meta[property='og:image']"),e=>e.length>0&&e.prop("content")).catch(()=>$("#view-cover").remove());if(!e){return}const t=new i(e.prop("content"));$("#view-cover").on("click",()=>{t.show()}).removeClass("hidden")}}}}else{return{widget:{content:`\n <button\n class="hidden gui-settings-flat-button"\n id="view-cover">\n <i class="icon-view"></i>\n <span>查看封面</span>\n </button>`,success:async()=>{const e=await SpinQuery.any(()=>$(".header-info-ctnr .room-cover")).catch(()=>$("#view-cover").remove());if(!e){return}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/bili/getRoomInfo/${e}`;const o=await downloadText(n);const s=o.slice(1,-2);const a=JSON.parse(s).data.cover;const c=new i(a);$("#view-cover").on("click",()=>{c.show()}).removeClass("hidden")}}}}}}})();