2 lines
6.0 KiB
JavaScript
2 lines
6.0 KiB
JavaScript
import{b as m,g as L}from"./settings-CgBxHrrF.js";import{i as c,n as T}from"./downloadIntent-Dv31jC2S.js";const I=8e3,a=new Map;let o=!1;function M(){const e=Date.now();for(const[n,t]of a.entries())t<=e&&a.delete(n)}async function f(e,n){if(!o)return!1;const t=T(e,window.location.href);if(!t)return!1;if(M(),a.has(t))return!0;a.set(t,Date.now()+I);try{if((await m.runtime.sendMessage({type:"capture-link-download",url:t,referer:n||document.referrer||window.location.href}))?.ok)return!0}catch{}return a.delete(t),!1}function x(e){return e?e instanceof HTMLAnchorElement?e:e instanceof Element?e.closest("a[href]"):null:null}function k(e){return!!(e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)}async function S(e){if(!o||e.defaultPrevented||k(e))return;const n=x(e.target);if(!n)return;const t=n.href||"";!t||!c(t,window.location.href)||(e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation(),await f(t,document.referrer||window.location.href))}function C(e){if(!o)return;const n=x(e.target);if(!n)return;const t=n.href||"";!t||!c(t,window.location.href)||k(e)||(e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation(),f(t,document.referrer||window.location.href))}document.addEventListener("pointerdown",e=>{e.button===0&&C(e)},!0);document.addEventListener("mousedown",e=>{e.button===0&&C(e)},!0);document.addEventListener("click",e=>{e.button===0&&S(e)},!0);document.addEventListener("keydown",e=>{if(!o||e.key!=="Enter"||e.defaultPrevented||k(e))return;const n=x(e.target);if(!n)return;const t=n.href||"";!t||!c(t,window.location.href)||(e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation(),f(t,document.referrer||window.location.href))},!0);document.addEventListener("auxclick",e=>{e.button===1&&S(e)},!0);function P(){try{const e=window.open.bind(window);window.open=function(t,r,p){const g=String(t||"").trim();return o&&g&&c(g,window.location.href)?(f(g,window.location.href),null):e(t,r,p)}}catch{}try{const e=HTMLAnchorElement.prototype.click;HTMLAnchorElement.prototype.click=function(){const t=this.href||this.getAttribute("href")||"";if(o&&t&&c(t,window.location.href)){f(t,document.referrer||window.location.href);return}e.call(this)}}catch{}}P();let u=null,i=null,b=!1,E=null,y=window.location.href;function O(e){try{const n=new URL(e);return n.hostname!=="www.youtube.com"&&n.hostname!=="youtube.com"?!1:n.pathname==="/watch"&&n.searchParams.has("v")}catch{return!1}}function w(e,n="idle"){i&&(i.textContent=e,n==="ok"?i.style.color="#8ff0a4":n==="error"?i.style.color="#ff9b9b":i.style.color="#aeb7d8")}async function A(){if(!b){b=!0,w("gdown으로 전송 중...");try{const e=await m.runtime.sendMessage({type:"page:enqueue-ytdlp-url",url:window.location.href,referer:window.location.href});e?.ok?w("다운로드 모달로 전송됨","ok"):w(`전송 실패: ${e?.error||"unknown error"}`,"error")}catch(e){w(`전송 실패: ${String(e)}`,"error")}finally{b=!1}}}function h(){u&&(u.remove(),u=null,i=null)}function s(){if(!o){h();return}if(window.top!==window.self)return;if(!O(window.location.href)){h();return}if(u)return;const e=document.createElement("div");e.id="gomdown-youtube-overlay",e.style.position="fixed",e.style.right="20px",e.style.bottom="24px",e.style.zIndex="2147483647",e.style.background="rgba(17, 21, 32, 0.94)",e.style.border="1px solid rgba(133, 148, 195, 0.35)",e.style.borderRadius="12px",e.style.padding="10px",e.style.boxShadow="0 8px 24px rgba(0, 0, 0, 0.28)",e.style.backdropFilter="blur(6px)",e.style.width="220px",e.style.fontFamily="ui-sans-serif, -apple-system, BlinkMacSystemFont, Segoe UI, sans-serif",e.style.color="#e8edff";const n=document.createElement("div");n.textContent="Gdown Helper",n.style.fontSize="12px",n.style.fontWeight="700",n.style.marginBottom="8px";const t=document.createElement("button");t.type="button",t.textContent="이 영상 다운로드",t.style.width="100%",t.style.height="34px",t.style.border="1px solid #5a69f0",t.style.borderRadius="8px",t.style.background="#5a69f0",t.style.color="#ffffff",t.style.fontSize="12px",t.style.fontWeight="700",t.style.cursor="pointer",t.addEventListener("click",()=>{A()});const r=document.createElement("div");r.textContent="클릭 시 gdown 다운로드 모달로 연결",r.style.fontSize="11px",r.style.marginTop="8px",r.style.lineHeight="1.35",r.style.color="#aeb7d8",e.appendChild(n),e.appendChild(t),e.appendChild(r),document.documentElement.appendChild(e),u=e,i=r}function U(){E===null&&(E=window.setInterval(()=>{const e=window.location.href;e!==y&&(y=e,s())},800),window.addEventListener("popstate",()=>{y=window.location.href,s()}),document.addEventListener("yt-navigate-finish",()=>{y=window.location.href,s()}))}s();U();let d=null,l=null;function v(){d&&(d.style.display="none",l!==null&&(window.clearTimeout(l),l=null))}function R(){if(d)return d;const e=document.createElement("div");return e.id="gomdown-media-toast",e.style.position="fixed",e.style.left="18px",e.style.bottom="18px",e.style.zIndex="2147483647",e.style.maxWidth="360px",e.style.padding="10px 12px",e.style.borderRadius="10px",e.style.border="1px solid rgba(128, 140, 180, 0.42)",e.style.background="rgba(18, 21, 31, 0.95)",e.style.color="#dce4fa",e.style.fontSize="12px",e.style.lineHeight="1.35",e.style.fontFamily="ui-sans-serif, -apple-system, BlinkMacSystemFont, Segoe UI, sans-serif",e.style.boxShadow="0 10px 24px rgba(0, 0, 0, 0.28)",e.style.display="none",document.documentElement.appendChild(e),d=e,e}function z(e){if(!o)return;const n=R(),t=String(e?.kind||"media").toUpperCase(),r=String(e?.suggestedOut||"").trim(),p=String(e?.url||"").trim().slice(0,96);n.textContent=r?`캡처됨 [${t}] ${r}`:`캡처됨 [${t}] ${p}${p.length>=96?"…":""}`,n.style.display="block",l!==null&&window.clearTimeout(l),l=window.setTimeout(()=>{n.style.display="none",l=null},2200)}m.runtime.onMessage.addListener(e=>{e?.type==="media:captured"&&z({kind:e?.kind,url:e?.url,suggestedOut:e?.suggestedOut})});async function F(){try{o=!!(await L()).extensionStatus}catch{o=!1}o?s():(h(),v())}F();m.storage.onChanged.addListener((e,n)=>{if(n==="sync"&&e.extensionStatus){if(o=!!e.extensionStatus.newValue,!o){h(),v();return}s()}});
|