mirror of
https://github.com/abhijithvijayan/web-extension-starter.git
synced 2026-03-20 01:37:46 +01:00
2 lines
5.0 KiB
JavaScript
2 lines
5.0 KiB
JavaScript
import{j as t,B as m,G as C,r as l,c as I}from"./GitHubIcon-DnWgqK1U.chunk.js";import{b as r,g as w}from"./storage-DjahtsqZ.chunk.js";const y="_card_127h0_5",S="_large_127h0_13",T="_header_127h0_18",L="_title_127h0_25",_={card:y,large:S,header:T,title:L},k=({title:s,size:c="default",children:n,className:d})=>{const h=[_.card,c==="large"&&_.large,d].filter(Boolean).join(" ");return t.jsxs("div",{className:h,children:[s&&t.jsx("div",{className:_.header,children:t.jsx("span",{className:_.title,children:s})}),n]})},G="_content_1dzc3_5",E="_favicon_1dzc3_12",P="_faviconPlaceholder_1dzc3_22",M="_details_1dzc3_36",z="_title_1dzc3_41",U="_url_1dzc3_52",o={content:G,favicon:E,faviconPlaceholder:P,details:M,title:z,url:U},V=({title:s,url:c,favIconUrl:n,onReload:d})=>{const h=x=>x.charAt(0).toUpperCase();return t.jsxs(k,{title:"Current Tab",children:[t.jsxs("div",{className:o.content,children:[n?t.jsx("img",{src:n,alt:"",className:o.favicon}):t.jsx("div",{className:o.faviconPlaceholder,children:h(s)}),t.jsxs("div",{className:o.details,children:[t.jsx("p",{className:o.title,children:s}),t.jsx("p",{className:o.url,children:c})]})]}),t.jsx(m,{variant:"secondary",fullWidth:!0,onClick:d,children:"Reload Tab"})]})},W=({size:s=14})=>t.jsxs("svg",{width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[t.jsx("circle",{cx:"12",cy:"12",r:"3"}),t.jsx("path",{d:"M12 1v2m0 18v2M4.22 4.22l1.42 1.42m12.72 12.72 1.42 1.42M1 12h2m18 0h2M4.22 19.78l1.42-1.42M18.36 5.64l1.42-1.42"})]}),B=({size:s=14})=>t.jsx("svg",{width:s,height:s,viewBox:"0 0 24 24",fill:"currentColor",children:t.jsx("path",{d:"M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z"})}),$="_footer_6a002_5",H="_button_6a002_10",u={footer:$,button:H},R=({onSettings:s,onGitHub:c,onSupport:n})=>t.jsxs("div",{className:u.footer,children:[t.jsxs(m,{variant:"settings",size:"small",className:u.button,onClick:s,children:[t.jsx(W,{}),t.jsx("span",{children:"Settings"})]}),t.jsxs(m,{variant:"github",size:"small",className:u.button,onClick:c,children:[t.jsx(C,{}),t.jsx("span",{children:"GitHub"})]}),t.jsxs(m,{variant:"support",size:"small",className:u.button,onClick:n,children:[t.jsx(B,{}),t.jsx("span",{children:"Support"})]})]}),A="_popup_19dhs_24",O="_header_19dhs_29",q="_title_19dhs_36",F="_greeting_19dhs_47",D="_tabCard_19dhs_54",J="_statsCard_19dhs_58",K="_statsTitle_19dhs_66",Q="_statsGrid_19dhs_75",X="_statItem_19dhs_81",Y="_statValue_19dhs_90",Z="_statLabel_19dhs_96",tt="_visitCard_19dhs_102",st="_visitLabel_19dhs_113",et="_visitCount_19dhs_118",e={popup:A,header:O,title:q,greeting:F,tabCard:D,statsCard:J,statsTitle:K,statsGrid:Q,statItem:X,statValue:Y,statLabel:Z,visitCard:tt,visitLabel:st,visitCount:et};function j(s){return r.tabs.create({url:s})}const at=()=>{const[s,c]=l.useState(null),[n,d]=l.useState(null),[h,x]=l.useState(0),[p,f]=l.useState("");l.useEffect(()=>{r.tabs.query({active:!0,currentWindow:!0}).then(i=>{const a=i[0];a&&(c({title:a.title||"Unknown",url:a.url||"Unknown",favIconUrl:a.favIconUrl}),a.id&&r.tabs.sendMessage(a.id,{type:"GET_PAGE_INFO"}).then(N=>{const v=N;v?.data&&d(v.data)}).catch(()=>{}))}),r.runtime.sendMessage({type:"GET_VISIT_COUNT"}).then(i=>{const a=i;a?.count!==void 0&&x(a.count)}).catch(()=>{}),w(["username"]).then(({username:i})=>{f(i)})},[]);const g=async()=>{const a=(await r.tabs.query({active:!0,currentWindow:!0}))[0];a?.id&&await r.tabs.reload(a.id)};return t.jsxs("section",{className:e.popup,children:[t.jsxs("header",{className:e.header,children:[t.jsx("h1",{className:e.title,children:"Web Extension Starter"}),p&&t.jsxs("p",{className:e.greeting,children:["Hello, ",p,"!"]})]}),s&&t.jsx("div",{className:e.tabCard,children:t.jsx(V,{title:s.title,url:s.url,favIconUrl:s.favIconUrl,onReload:g})}),n&&t.jsxs("div",{className:e.statsCard,children:[t.jsx("h3",{className:e.statsTitle,children:"Page Stats"}),t.jsxs("div",{className:e.statsGrid,children:[t.jsxs("div",{className:e.statItem,children:[t.jsx("span",{className:e.statValue,children:n.wordCount}),t.jsx("span",{className:e.statLabel,children:"Words"})]}),t.jsxs("div",{className:e.statItem,children:[t.jsx("span",{className:e.statValue,children:n.linkCount}),t.jsx("span",{className:e.statLabel,children:"Links"})]}),t.jsxs("div",{className:e.statItem,children:[t.jsx("span",{className:e.statValue,children:n.imageCount}),t.jsx("span",{className:e.statLabel,children:"Images"})]})]})]}),t.jsxs("div",{className:e.visitCard,children:[t.jsx("span",{className:e.visitLabel,children:"Pages tracked:"}),t.jsx("span",{className:e.visitCount,children:h})]}),t.jsx(R,{onSettings:()=>j("/Options/options.html"),onGitHub:()=>j("https://github.com/abhijithvijayan/web-extension-starter"),onSupport:()=>j("https://www.buymeacoffee.com/abhijithvijayan")})]})},b=document.getElementById("popup-root");if(!b)throw new Error("Could not find root container to mount the app");const nt=I.createRoot(b);nt.render(t.jsx(l.StrictMode,{children:t.jsx(at,{})}));
|