(()=>{return(e,t)=>{const{getFriendlyTitle:i}=t.import("title");const n=document.createElement("canvas");class s{constructor(e,t){this.url="";this.timeStamp=(new Date).getTime();this.video=e;this.videoTime=t;this.createUrl()}async createUrl(){n.width=this.video.videoWidth;n.height=this.video.videoHeight;const e=n.getContext("2d");if(e===null){throw new Error("视频截图失败: canvas 未创建或创建失败.")}e.drawImage(this.video,0,0);n.toBlob(e=>{if(e===null){throw new Error("视频截图失败: 创建 blob 失败.")}this.blob=e;this.url=URL.createObjectURL(e)},"image/png")}get filename(){return`${i()} @${this.videoTime.toString()}:${this.timeStamp.toString()}.png`}get id(){return this.videoTime.toString()+this.timeStamp.toString()}revoke(){URL.revokeObjectURL(this.url)}}const o=e=>{const t=e.currentTime;return new s(e,t)};t.applyStyle("videoScreenshotStyle");document.body.insertAdjacentHTML("beforeend",`\n
\n
\n \n \n
\n
\n
\n
\n
\n
\n`);Vue.component("video-screenshot",{props:{objectUrl:String,filename:String},template:`\n \n
![]()
\n
\n
\n
\n
`,methods:{discard(){this.$emit("discard")},save(){this.$el.querySelector(".link").click();this.discard()}}});const r=new Vue({el:".video-screenshot-container",data:{screenshots:[],batchFilename:i()+".zip"},methods:{discard(e){this.screenshots.splice(this.screenshots.indexOf(e),1);e.revoke()},async saveAll(){const e=new JSZip;this.screenshots.forEach(t=>{e.file(t.filename,t.blob,{date:new Date(t.timeStamp)})});const t=await e.generateAsync({type:"blob"});const i=this.$el.querySelector(".batch-link");i.href=URL.createObjectURL(t);i.click();URL.revokeObjectURL(i.href);i.href="";this.discardAll()},discardAll(){this.screenshots.forEach(e=>e.revoke());this.screenshots=[]}},computed:{showBatch(){return this.screenshots.length>=2}}});const c=`\n \n \n
`;Observer.videoChange(async()=>{const t=await SpinQuery.select("#bofqi video");if(t===null){return}if(e.framePlayback){const e=await SpinQuery.select(".frame-playback.prev-frame");if(e===null||document.querySelector(".video-take-screenshot")){return}e.insertAdjacentHTML("beforebegin",c)}else{const e=await SpinQuery.select(".bilibili-player-video-time");if(e===null||document.querySelector(".video-take-screenshot")){return}e.insertAdjacentHTML("afterend",c)}const i=document.querySelector(".video-take-screenshot");i.addEventListener("click",async()=>{const e=await SpinQuery.select("#bofqi video");const t=o(e);r.screenshots.unshift(t)});document.addEventListener("keydown",e=>{if(document.activeElement&&["input","textarea"].includes(document.activeElement.nodeName.toLowerCase())){return}if(e.ctrlKey&&e.altKey&&e.key.toLowerCase()==="c"){e.stopPropagation();e.preventDefault();i.click()}})});return{export:{takeScreenshot:o,screenShotsList:r},unload:()=>document.querySelectorAll(".bilibili-player-video-control-bottom .video-take-screenshot,.video-screenshot-container").forEach(e=>e.setAttribute("style","display: none !important")),reload:()=>document.querySelectorAll(".bilibili-player-video-control-bottom .video-take-screenshot,.video-screenshot-container").forEach(e=>e.setAttribute("style","display: flex !important"))}}})();