import{h as C}from"./jszip.min-DpCewD43.js";import{p as w,b as x,r as g,a as E}from"./content-processor-IWRcpt0Y.js";import{c as R}from"./fab-W2bspDnB.js";import"./_commonjsHelpers-BosuxZz1.js";import"./logger-CvfM-6aa.js";(()=>{let n=null,r=null;function u(){if(!document.querySelector("#js_content")||document.querySelector("#wechatsync-fab"))return;const e=R({onClick:()=>h()});document.body.appendChild(e)}async function h(){var d;if(r)return;r=document.createElement("div"),r.id="wechatsync-dialog-overlay",r.style.cssText=`
    position: fixed; inset: 0; z-index: 2147483647;
    display: flex; align-items: center; justify-content: center;
    background: rgba(0,0,0,0.3);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  `,r.addEventListener("click",c=>{c.target===r&&y()});const t=document.createElement("div");t.style.cssText=`
    background: white; padding: 20px 32px; border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    display: flex; align-items: center; gap: 12px;
  `,t.innerHTML=`
    <div style="width:20px;height:20px;border:3px solid #e5e5e5;border-top-color:#07c160;border-radius:50%;animation:wcs-spin 0.8s linear infinite;"></div>
    <span style="font-size:14px;color:#333;">正在提取文章...</span>
    <style>@keyframes wcs-spin { to { transform: rotate(360deg); } }</style>
  `,r.appendChild(t),document.body.appendChild(r);const[e,s]=await Promise.all([Promise.resolve(f()),chrome.runtime.sendMessage({type:"CHECK_ALL_AUTH"}).catch(()=>({platforms:[]}))]);if(!e){chrome.runtime.sendMessage({type:"TRACK_ARTICLE_EXTRACT",payload:{source:"weixin",success:!1}}).catch(()=>{}),y();return}chrome.runtime.sendMessage({type:"TRACK_ARTICLE_EXTRACT",payload:{source:"weixin",success:!0,hasTitle:!!e.title,hasContent:!!e.content,hasCover:!!e.cover,contentLength:((d=e.content)==null?void 0:d.length)||0}}).catch(()=>{});const o=s.platforms||[];if(!r)return;t.remove(),n=document.createElement("iframe"),n.src=chrome.runtime.getURL("src/sync-dialog/index.html"),n.style.cssText=`
    width: 400px; height: 520px; border: none;
    border-radius: 12px; overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  `,r.appendChild(n);const i=c=>{var a;try{(typeof c.data=="string"?JSON.parse(c.data):c.data).type==="SYNC_DIALOG_READY"&&(window.removeEventListener("message",i),(a=n==null?void 0:n.contentWindow)==null||a.postMessage(JSON.stringify({type:"INIT_DATA",article:e,platforms:o}),"*"))}catch{}};window.addEventListener("message",i)}function y(){r&&(r.remove(),r=null,n=null)}window.addEventListener("message",t=>{try{const e=typeof t.data=="string"?JSON.parse(t.data):t.data;if(e.type==="CLOSE_SYNC_DIALOG")y();else if(e.type==="START_SYNC"){const s=e.syncId;chrome.runtime.sendMessage({type:"SYNC_ARTICLE",payload:{article:e.article,platforms:e.platforms,source:"weixin",syncId:s}}).then(o=>{var i;(i=n==null?void 0:n.contentWindow)==null||i.postMessage(JSON.stringify({type:"SYNC_COMPLETE",results:o.results,rateLimitWarning:o.rateLimitWarning,syncId:s}),"*")}).catch(o=>{var i;(i=n==null?void 0:n.contentWindow)==null||i.postMessage(JSON.stringify({type:"SYNC_ERROR",error:o.message,syncId:s}),"*")})}}catch{}}),chrome.runtime.onMessage.addListener(t=>{var e,s,o;n&&(t.type==="SYNC_PROGRESS"&&((s=n.contentWindow)==null||s.postMessage(JSON.stringify({type:"SYNC_PROGRESS",result:(e=t.payload)==null?void 0:e.result,syncId:t.syncId}),"*")),t.type==="SYNC_DETAIL_PROGRESS"&&((o=n.contentWindow)==null||o.postMessage(JSON.stringify({type:"SYNC_DETAIL_PROGRESS",progress:t.payload,syncId:t.syncId}),"*")))}),chrome.runtime.onMessage.addListener((t,e,s)=>{if(t.type==="EXTRACT_ARTICLE"){const o=f();return s({article:o}),!0}if(t.type==="PREPROCESS_FOR_PLATFORMS"){const{rawHtml:o,platforms:i,configs:d}=t.payload,c={};for(const a of i){const l=d[a];l&&(c[a]=w(o,l))}return s({platformContents:c}),!0}});function f(){var d,c,a,l;const t=(c=(d=document.querySelector("#activity-name"))==null?void 0:d.textContent)==null?void 0:c.trim(),e=document.querySelector("#js_content"),s=(a=document.querySelector('meta[property="og:image"]'))==null?void 0:a.getAttribute("content"),o=(l=document.querySelector('meta[property="og:description"]'))==null?void 0:l.getAttribute("content");if(!t||!e)return null;const i=x(e);try{const p=e.cloneNode(!0);g(i),E(p);const m=p.innerHTML,S=C(m);return{title:t,html:m,content:m,markdown:S,summary:o||void 0,cover:s||void 0,source:{url:window.location.href,platform:"weixin"}}}catch(p){throw g(i),p}}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",u):u()})();
