Bilibili-Evolved/video/view-cover.min.js
2018-09-07 15:42:30 +08:00

1 line
2.3 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);t.applyStyle("imageViewerStyle","image-viewer-style");$(".image-viewer-container .close").on("click",()=>this.hide())}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");$("html,body").addClass("image-viewer-opened")}hide(){this.viewer.removeClass("opened");$("html,body").removeClass("image-viewer-opened")}}SpinQuery.any(()=>$("span.settings-category"),e=>{SpinQuery.any(()=>$("meta[itemprop='image']"),t=>{if(t.length>0){$(e.filter((e,t)=>t.innerHTML==="视频与直播")).parent().after(`\n <li class="indent-center">\n <button\n class="gui-settings-button"\n title="查看当前视频的封面"\n id="view-video-cover">\n 查看封面\n </button>\n </li>`);const n=new i(t.prop("content"));$("#view-video-cover").on("click",()=>{n.show()})}});SpinQuery.any(()=>$(".header-info-ctnr .room-cover"),t=>{const n=t.attr("href").match(/space\.bilibili\.com\/([\d]+)/);if(n&&n[1]){const t=n[1];const o=`https://api.live.bilibili.com/bili/getRoomInfo/${t}`;downloadText(o,t=>{const n=t.slice(1,-2);const o=JSON.parse(n).data.cover;$(e.filter((e,t)=>t.innerHTML==="视频与直播")).parent().after(`\n <li class="indent-center">\n <button\n class="gui-settings-button"\n title="查看当前直播的封面"\n id="view-live-cover">\n 查看封面\n </button>\n </li>`);const a=new i(o);$("#view-live-cover").on("click",()=>{a.show()})})}})});return{ajaxReload:false}}})();