2 lines
6.0 KiB
JavaScript
2 lines
6.0 KiB
JavaScript
import{c as U,j as s,R as o}from"./client-BzjyOx7y.js";import{g as E,b as i,s as v}from"./settings-CgBxHrrF.js";import{n as R}from"./clipTypes-C_ha5Ash.js";function F(){const[a,u]=o.useState(null),[j,t]=o.useState(""),[x,h]=o.useState([]),[g,y]=o.useState(null),[N,k]=o.useState(""),[w,l]=o.useState([]);o.useEffect(()=>{E().then(u)},[]),o.useEffect(()=>{let e=null;const n=async()=>{const r=await i.runtime.sendMessage({type:"media:list"});r?.ok&&Array.isArray(r.items)&&h(r.items.slice(0,10))};return n(),e=window.setInterval(()=>{n()},2e3),()=>{e!==null&&window.clearInterval(e)}},[]),o.useEffect(()=>{const e=async()=>{const c=(await i.tabs.query({active:!0,currentWindow:!0}))[0],m=R(String(c?.url||""));if(y(Number.isInteger(c?.id)?c?.id:null),k(m),!m){l([]);return}const p=await i.runtime.sendMessage({type:"clip:list",pageUrl:m});p?.ok&&Array.isArray(p.items)&&l(p.items)};e();const n=window.setInterval(()=>{e()},2500);return()=>{window.clearInterval(n)}},[]);const d=(e,n)=>{u(r=>r&&{...r,[e]:n})},f=async e=>{if(!a)return;const n={...a,extensionStatus:e};u(n),await v({extensionStatus:e}),t(e?"Extension ON":"Extension OFF"),window.setTimeout(()=>t(""),1200)},b=async()=>{a&&(await v(a),t("Saved"),window.setTimeout(()=>t(""),1200))},C=async()=>{const e=i.runtime.getURL("src/config/index.html");await i.tabs.create({url:e})},S=async()=>{const e=i.runtime.getURL("src/history/index.html");await i.tabs.create({url:e})},A=async()=>{const e=await i.runtime.sendMessage({type:"page:enqueue-ytdlp"});t(e?.ok?"Active tab sent to gdown (yt-dlp)":`Send failed: ${e?.error||"unknown error"}`),window.setTimeout(()=>t(""),1800)},T=async e=>{const n=await i.runtime.sendMessage({type:"media:enqueue",url:e.url,referer:e.referer||"",kind:e.kind,suggestedOut:e.suggestedOut||"",cookie:e.cookie||"",userAgent:e.userAgent||""});t(n?.ok?"Media sent to gdown":`Send failed: ${n?.error||"unknown error"}`),window.setTimeout(()=>t(""),1600)},M=async()=>{await i.runtime.sendMessage({type:"media:clear"}),h([]),t("Captured media cleared"),window.setTimeout(()=>t(""),1200)},I=async()=>{if(!Number.isInteger(g)){t("활성 탭을 찾을 수 없습니다."),window.setTimeout(()=>t(""),1600);return}const e=await i.tabs.sendMessage(g,{type:"clip:create-from-selection"});if(!e?.ok){t(`클립 생성 실패: ${e?.error||"선택 텍스트를 확인하세요"}`),window.setTimeout(()=>t(""),2e3);return}t("클립 저장 완료"),window.setTimeout(()=>t(""),1400);const n=await i.runtime.sendMessage({type:"clip:list",pageUrl:N});n?.ok&&Array.isArray(n.items)&&l(n.items)},P=async e=>{const n=await i.runtime.sendMessage({type:"clip:reveal",id:e});t(n?.ok?n.opened?"클립 페이지를 열었습니다":"클립 위치로 이동":`이동 실패: ${n?.error||"unknown error"}`),window.setTimeout(()=>t(""),1700)},O=async e=>{const n=await i.runtime.sendMessage({type:"clip:delete",id:e});if(!n?.ok){t(`삭제 실패: ${n?.error||"unknown error"}`),window.setTimeout(()=>t(""),1600);return}l(r=>r.filter(c=>c.id!==e)),t("클립 삭제 완료"),window.setTimeout(()=>t(""),1200)};return a?s.jsxs("div",{className:"container",children:[s.jsxs("div",{className:"top-row",children:[s.jsx("h1",{children:"Gomdown Helper"}),s.jsxs("button",{className:`power-toggle ${a.extensionStatus?"on":"off"}`,onClick:()=>{f(!a.extensionStatus)},children:[s.jsx("span",{className:"power-dot"}),a.extensionStatus?"ON":"OFF"]})]}),s.jsxs("div",{className:"field",children:[s.jsx("label",{children:"RPC Secret"}),s.jsx("input",{type:"text",value:a.motrixAPIkey,onChange:e=>d("motrixAPIkey",e.target.value),placeholder:"aria2 rpc secret"})]}),s.jsxs("div",{className:"field",children:[s.jsx("label",{children:"RPC Port"}),s.jsx("input",{type:"number",value:a.motrixPort,onChange:e=>d("motrixPort",Number(e.target.value||16800))})]}),s.jsxs("label",{className:"toggle",children:["Use Native Host",s.jsx("input",{type:"checkbox",checked:a.useNativeHost,onChange:e=>d("useNativeHost",e.target.checked)})]}),s.jsxs("label",{className:"toggle",children:["Activate gdown App",s.jsx("input",{type:"checkbox",checked:a.activateAppOnDownload,onChange:e=>d("activateAppOnDownload",e.target.checked)})]}),s.jsx("button",{onClick:b,children:"Save"}),s.jsx("button",{onClick:C,children:"Settings"}),s.jsx("button",{onClick:S,children:"History"}),s.jsx("button",{onClick:()=>{A()},children:"Send Active Tab (yt-dlp)"}),s.jsx("button",{onClick:()=>{I()},children:"Create Clip From Selection"}),s.jsxs("div",{className:"media-panel",children:[s.jsxs("div",{className:"media-head",children:[s.jsx("strong",{children:"Captured Media"}),s.jsx("button",{className:"mini ghost",onClick:M,children:"Clear"})]}),x.length===0?s.jsx("div",{className:"empty",children:"No media captured yet"}):s.jsx("div",{className:"media-list",children:x.map(e=>s.jsxs("div",{className:"media-item",children:[s.jsxs("div",{className:"media-meta",children:[s.jsx("span",{className:"kind",children:e.kind.toUpperCase()}),e.pageTitle?s.jsx("span",{className:"url",children:e.pageTitle}):null,s.jsx("span",{className:"url",children:e.url})]}),s.jsx("button",{className:"mini",onClick:()=>{T(e)},children:"Add"})]},e.id))})]}),s.jsxs("div",{className:"media-panel",children:[s.jsxs("div",{className:"media-head",children:[s.jsx("strong",{children:"Page Clips"}),s.jsx("span",{className:"hint",children:"Alt+Shift+C"})]}),w.length===0?s.jsx("div",{className:"empty",children:"No clips for this page"}):s.jsx("div",{className:"media-list",children:w.map(e=>s.jsxs("div",{className:"clip-item",children:[s.jsxs("div",{className:"media-meta",children:[s.jsx("span",{className:"kind",children:"CLIP"}),s.jsx("span",{className:"url",children:e.quote||e.anchor.exact})]}),s.jsxs("div",{className:"clip-actions",children:[s.jsx("button",{className:"mini",onClick:()=>{P(e.id)},children:"Go"}),s.jsx("button",{className:"mini ghost",onClick:()=>{O(e.id)},children:"Del"})]})]},e.id))})]}),s.jsx("div",{className:"status",children:j})]}):s.jsx("div",{className:"container",children:"Loading..."})}U.createRoot(document.getElementById("root")).render(s.jsx(o.StrictMode,{children:s.jsx(F,{})}));
|