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.addEv
|