"use strict";(()=>{let e,t=chrome.runtime,n=location.pathname.endsWith("offscreen.html"),a=()=>{n||parent.focus(),window.closed||window.close(),e=null},o=t=>{let o=t=>{s=!0,e.postMessage({H:92,r:t}),n||setTimeout(a,0)},{t:c,s:r}=t,i=()=>{switch(c){case 5:case 3:let e=navigator.clipboard;if(n){let e=document,t=e.createElement("textarea");if(c===5)t.value=r,e.body.append(t),t.select(),e.execCommand("copy"),t.remove(),t.value="";else{let n=r<0?-1-r:r;t.maxLength=n||102400,e.body.append(t),t.focus(),e.execCommand("paste"),s=t.value.slice(0,n||102400),t.value="",t.remove(),t.removeAttribute("maxlength")}return Promise.resolve()}return c===5?e.writeText(r):e.readText().then(e=>{s=e});case 4:return window.fetch(r.u).then(e=>e.status<300&&e.status>199?e.blob():Promise.reject("HTTP "+e.status)).then(e=>{let t=URL.createObjectURL(e),n=document.createElement("a");n.href=t,n.download=r.t,n.target="_blank";let a=new MouseEvent("click",{bubbles:!0,cancelable:!0,altKey:!0,detail:1,button:0,buttons:1});n.dispatchEvent(a)});case 10:{let e=r.map(e=>!!e&&matchMedia(e).matches);o(e)}return}switch(c){case 1:case 9:let e=(c===9?new Promise((e,t)=>{let n=document.createElement("img");n.onload=()=>{let a=document.createElement("canvas"),o=a.width=n.naturalWidth,c=a.height=n.naturalHeight,r=a.getContext("2d");if(r)try{r.drawImage(n,0,0,o,c),a.toBlob(n=>n?e(n):t("Can not export from canvas"))}catch(e){t("Can not export tainted canvas")}else t("Can not create canvas")},n.onerror=()=>{t(0)},n.src=r.u}).catch(e=>e!==0?window.fetch(r.u):Promise.reject("Can not load image")):window.fetch(r.u)).then(e=>(r.u="",e instanceof Response?e.blob():e)).then(e=>{r.u="";let t="image/png",n={[t]:e.type===t?e:new Blob([e],{type:t})};return r.t&&(n["text/plain"]=new Blob([r.t],{type:"text/plain"})),navigator.clipboard.write([new ClipboardItem(n)])});return c!==9&&(r.u=""),e}},l=()=>{let e;try{e=i()}catch(e){}e?e.then(()=>{o(s)},e=>{console.log("Vimium C: can not run task=%o:",c,e),o(!1)}):o(!1)},s=!0;n||document.hasFocus()?l():(window.onfocus=l,window.focus())},c=!1;try{e=t.connect({name:""+(2176|(n?4096:0))}),e.onDisconnect.addListener(a)}catch(e){return void a()}e.onMessage.addListener(e=>{let t=e;t.N!==49||c?a():(c=!n,o(t))})})();