(function(){function Fe(){return typeof chrome<"u"&&chrome.runtime?chrome.runtime:typeof browser<"u"&&browser.runtime?browser.runtime:null}function L(e,o){const t=Fe();if(!t||!t.sendMessage){console.warn("WiseMindAI runtime.sendMessage 不可用");return}try{t.sendMessage(e,o)}catch(r){console.warn("WiseMindAI 发送消息失败",r)}}function xe(e,o="success"){const t=String(e||"").trim();if(!t)return;const r=document.getElementById("wisemind-page-toast");r!=null&&r.parentNode&&r.parentNode.removeChild(r);const n=document.createElement("div");n.id="wisemind-page-toast",n.textContent=t;const i=o==="error"||t.startsWith("✗");n.style.cssText=`
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 2147483647;
    max-width: min(360px, calc(100vw - 48px));
    padding: 12px 14px;
    border-radius: 10px;
    background: ${i?"#fef2f2":"#ecfdf5"};
    border: 1px solid ${i?"#fecaca":"#bbf7d0"};
    color: ${i?"#991b1b":"#14532d"};
    box-shadow: 0 16px 40px rgba(15, 23, 42, 0.18);
    font-size: 14px;
    line-height: 1.5;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    white-space: normal;
    word-break: break-word;
    pointer-events: none;
    opacity: 0;
    transform: translateY(-8px);
    transition: opacity 180ms ease, transform 180ms ease;
  `,document.documentElement.appendChild(n),window.requestAnimationFrame(()=>{n.style.opacity="1",n.style.transform="translateY(0)"}),window.setTimeout(()=>{n.style.opacity="0",n.style.transform="translateY(-8px)",window.setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n)},220)},4200)}function He(e){const o=(e==null?void 0:e.from_folder)??(e==null?void 0:e.fromFolder)??(e==null?void 0:e.parentId);if(o==null)return!0;const t=String(o).trim();return t===""||t==="0"}function ze(){const e=window.getSelection();if(!e||e.rangeCount===0)return{html:"",text:""};const o=e.getRangeAt(0),t=document.createElement("div");t.appendChild(o.cloneContents());const r=t.innerHTML||"",n=e.toString()||"";return{html:r,text:n}}function pe(){try{const e=document.body.cloneNode(!0);return e.querySelectorAll("script, style, noscript").forEach(r=>r.remove()),(e.innerText||e.textContent||"").replace(/\s+/g," ").replace(/\n\s*\n/g,`
`).trim()}catch(e){return e.message&&!e.message.includes("Mixed Content")&&console.error("Failed to get page text content:",e),""}}let ie=!1,z=null,X=null;function Ue(){z||(z=document.createElement("div"),z.id="wisemind-block-picker-overlay",z.style.cssText=`
      position: fixed;
      z-index: 10000000;
      border: 2px solid #57be72;
      background: rgba(87, 190, 114, 0.08);
      pointer-events: none;
      transition: all 0.05s ease;
    `,document.body.appendChild(z)),X||(X=document.createElement("div"),X.id="wisemind-block-picker-tip",X.textContent="选择内容块：鼠标悬浮高亮，点击保存，按 Esc 取消",X.style.cssText=`
      position: fixed;
      bottom: 16px;
      left: 50%;
      transform: translateX(-50%);
      background: #111827;
      color: #ffffff;
      padding: 8px 12px;
      border-radius:12px;
      font-size: 12px;
      z-index: 10000001;
      box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
      pointer-events: none;
    `,document.body.appendChild(X))}function $e(){z&&(z.remove(),z=null),X&&(X.remove(),X=null)}function Re(e){return e&&(e.id==="wisemind-block-picker-overlay"||e.id==="wisemind-block-picker-tip")}function ve(e){const o=document.elementFromPoint(e.clientX,e.clientY);return!o||Re(o)||o===document.body||o===document.documentElement?null:o}function Ye(e){if(!z||!e)return;const o=e.getBoundingClientRect();z.style.top=`${Math.max(o.top,0)}px`,z.style.left=`${Math.max(o.left,0)}px`,z.style.width=`${Math.max(o.width,0)}px`,z.style.height=`${Math.max(o.height,0)}px`}function Ee(){ie&&(ie=!1,document.removeEventListener("mousemove",Ce,!0),document.removeEventListener("click",Te,!0),document.removeEventListener("keydown",Se,!0),$e())}function Ce(e){const o=ve(e);o&&Ye(o)}function Te(e){const o=ve(e);if(!o)return;e.preventDefault(),e.stopPropagation();const t=o.innerText||o.textContent||"";if(!t.trim())return;Ee();const r={type:"WISEMIND_BLOCK_SELECTED",text:t,title:document.title||"",url:window.location.href||""};L(r)}function Se(e){e.key==="Escape"&&Ee()}function ke(){ie||(ie=!0,Ue(),document.addEventListener("mousemove",Ce,!0),document.addEventListener("click",Te,!0),document.addEventListener("keydown",Se,!0))}let M=null,ue=!1,se="",K={enabled:!0,whitelist:"",items:["save-note","save-file","save-card"]},Z=null,ae=null;function Ie(){var e;(e=chrome.storage)!=null&&e.sync&&chrome.storage.sync.get(["wisemindConfig"],o=>{const t=o.wisemindConfig||{},r=Array.isArray(t.selectionMenuItems)?t.selectionMenuItems:[];K={enabled:t.selectionMenuEnabled!==!1,whitelist:t.selectionMenuWhitelist||"",items:r.length?r:["save-note","save-file","save-card"]},Me()})}function Xe(){if(M)return;M=document.createElement("div"),M.id="wisemind-selection-toolbar",M.style.cssText=`
    position: fixed;
    z-index: 10000002;
    display: none;
    background: #ffffff;
    color: #0f172a;
    border-radius: 12px;
    padding: 6px;
    gap: 6px;
    align-items: center;
    border: 1px solid #e2e8f0;
    box-shadow: 0 16px 40px rgba(15, 23, 42, 0.15);
  `,M.style.display="none";const e=(t,r)=>{const n=document.createElement("button");n.type="button",n.style.cssText=`
      display: flex;
      align-items: center;
      gap: 6px;
      background: #f8fafc;
      color: #0f172a;
      border: 1px solid #e2e8f0;
      border-radius: 8px;
      padding: 6px 10px;
      font-size: 12px;
      font-weight: 600;
      cursor: pointer;
      transition: all 0.15s ease;
    `;const i=document.createElement("img");i.src=chrome.runtime.getURL("icons/icon16.png"),i.alt="WiseMindAI",i.style.cssText="width: 16px; height: 16px;";const s=document.createElement("span");return s.textContent=t,n.appendChild(i),n.appendChild(s),n.addEventListener("click",f=>{f.preventDefault(),f.stopPropagation(),r()}),n.addEventListener("mouseenter",()=>{n.style.background="#eef2f7",n.style.borderColor="#cbd5f5"}),n.addEventListener("mouseleave",()=>{n.style.background="#f8fafc",n.style.borderColor="#e2e8f0"}),n},o=()=>{const t=document.createElement("button");t.type="button",t.style.cssText=`
      display: flex;
      align-items: center;
      justify-content: center;
      background: #f8fafc;
      color: #0f172a;
      border: 1px solid #e2e8f0;
      border-radius: 8px;
      padding: 6px;
      cursor: pointer;
      transition: all 0.15s ease;
    `;const r=document.createElement("img");return r.src=chrome.runtime.getURL("src/components/icons/settings.svg"),r.alt="设置",r.style.cssText="width: 14px; height: 14px; opacity: 0.72;",t.appendChild(r),t.addEventListener("mouseenter",()=>{t.style.background="#eef2f7",t.style.borderColor="#cbd5f5"}),t.addEventListener("mouseleave",()=>{t.style.background="#f8fafc",t.style.borderColor="#e2e8f0"}),t.addEventListener("click",n=>{n.preventDefault(),n.stopPropagation(),L({type:"WISEMIND_OPEN_OPTIONS",section:"selection"}),Y()}),t};Z=e,ae=o,window.requestAnimationFrame(Me),document.body.appendChild(M)}function Me(){if(!(!M||!Z||!ae)){if(M.innerHTML="",!K.enabled){M.appendChild(ae());return}if(K.items.includes("save-note")){const e=Z("保存笔记",()=>{const o=se||"";o.trim()&&(Y(),L({type:"WISEMIND_SAVE_NOTE_SELECTION",text:o,title:document.title||"",url:window.location.href||""}))});M.appendChild(e)}if(K.items.includes("save-file")){const e=Z("保存文档",()=>{const o=se||"";o.trim()&&(Y(),L({type:"WISEMIND_SAVE_FILE_SELECTION",text:o}))});M.appendChild(e)}if(K.items.includes("save-card")){const e=Z("保存知识卡片",()=>{const o=se||"";o.trim()&&(Y(),L({type:"WISEMIND_SAVE_CARD_SELECTION",text:o}))});M.appendChild(e)}M.appendChild(ae())}}function Ge(e){if(!K.enabled||(M||Xe(),!M))return;const o=Math.max(e.top-44,8),t=Math.max(e.left,8);M.style.top=`${o}px`,M.style.left=`${t}px`,M.style.display="flex",ue=!0}function Y(){M&&(M.style.display="none",ue=!1)}function Ke(e){if(!e||e.rangeCount===0)return null;const o=e.getRangeAt(0);let t=o.getBoundingClientRect();if(!t||!t.width&&!t.height){const r=o.getClientRects();r&&r.length>0&&(t=r[r.length-1])}return t}function Le(){if(ie){Y();return}if(K.whitelist&&Ne(window.location.href,K.whitelist)){Y();return}const e=window.getSelection(),o=e?e.toString():"";if(!e||e.isCollapsed||!o.trim()){Y();return}se=o;const t=Ke(e);if(!t){Y();return}Ge(t)}document.addEventListener("mouseup",()=>{setTimeout(Le,0)},!0);document.addEventListener("keyup",e=>{(e.key==="Shift"||e.key==="ArrowLeft"||e.key==="ArrowRight"||e.key==="ArrowUp"||e.key==="ArrowDown")&&setTimeout(Le,0)},!0);document.addEventListener("selectionchange",()=>{if(!ue)return;const e=window.getSelection();(!e||e.isCollapsed||!e.toString().trim())&&Y()});window.addEventListener("scroll",()=>{ue&&Y()});let u=null,y=null,B=null,U=null,D=null,ee=null,te=null,ne=null,J=null,oe=null,ce=!1,g=null,G=null,me=!0,H=null,$=null,R=null,re=!1;const ge=["save-page","ai-chat","pick-text","capture-custom","capture-full-page","save-page-pdf"];let _e=[...ge];const Ae={"save-page":"保存网页","ai-chat":"AI 对话","pick-text":"选择文本","capture-custom":"自定义截图","capture-full-page":"截取完整页面","save-page-pdf":"保存网页为 PDF"};function Ne(e,o){if(!o||!o.trim())return!1;const t=o.split(`
`).map(n=>n.trim()).filter(n=>n),r=new URL(window.location.href).hostname;for(const n of t){let i=n;if(i.includes("://"))try{i=new URL(i).hostname}catch{i=i.split("://").pop()||i}i.includes("/")&&(i=i.split("/")[0]),i.includes(":")&&(i=i.split(":")[0]);const s=i.replace(/\./g,"\\.").replace(/\*/g,".*");if(new RegExp(`^${s}$`,"i").test(r))return!0}return!1}async function Ve(){return new Promise(e=>{chrome.storage.sync.get(["wisemindDisabledSites"],o=>{const t=o.wisemindDisabledSites||{},r=new URL(window.location.href).hostname;e(t[r]===!0)})})}async function je(){return sessionStorage.getItem("wisemind_current_visit_closed")==="true"}function qe(){y||(y=document.createElement("div"),y.id="wisemind-close-button",y.innerHTML="×",y.style.cssText=`
    position: absolute;
    top: -8px;
    left: -8px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #ffffff;
    color: #6b7280;
    font-size: 16px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    z-index: 1000000;
    transition: all 0.2s;
    line-height: 1;
    opacity: 0;
    pointer-events: none;
  `,y.addEventListener("mouseenter",()=>{y.style.background="#ef4444",y.style.color="#ffffff",y.style.transform="scale(1.1)"}),y.addEventListener("mouseleave",()=>{y.style.background="#ffffff",y.style.color="#6b7280",y.style.transform="scale(1)"}),y.addEventListener("click",e=>{e.stopPropagation(),Ze()}),u&&u.appendChild(y))}function Je(){y&&y.parentNode&&(y.parentNode.removeChild(y),y=null)}function Qe(){if(B)return;B=document.createElement("div"),B.id="wisemind-close-dialog",B.style.cssText=`
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10000000;
    display: none;
    align-items: center;
    justify-content: center;
  `;const e=document.createElement("div");e.style.cssText=`
    background: #ffffff;
    border-radius: 12px;
    padding: 24px;
    width: 400px;
    max-width: 90%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    position: relative;
  `;const o=document.createElement("div");o.innerHTML="×",o.style.cssText=`
    position: absolute;
    top: 12px;
    right: 12px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 20px;
    color: #6b7280;
    transition: all 0.2s;
    border-radius: 4px;
  `,o.addEventListener("mouseenter",()=>{o.style.background="#f3f4f6",o.style.color="#111827"}),o.addEventListener("mouseleave",()=>{o.style.background="transparent",o.style.color="#6b7280"}),o.addEventListener("click",()=>{le()});const t=document.createElement("h3");t.textContent="关闭悬浮球",t.style.cssText=`
    margin: 0 0 20px 0;
    font-size: 18px;
    font-weight: 700;
    color: #111827;
  `;const r=document.createElement("div");r.style.cssText=`
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
  `;const n=[{value:"current",label:"本次关闭直到下次访问"},{value:"site",label:"当前网站禁用(可在设置页开启)"},{value:"permanent",label:"永久禁用(可在设置页开启)"}];let i="current";n.forEach(w=>{const c=document.createElement("div");c.style.cssText=`
      display: flex;
      align-items: center;
      gap: 10px;
      padding: 12px;
      border-radius: 8px;
      cursor: pointer;
      transition: all 0.2s;
    `;const a=document.createElement("input");a.type="radio",a.name="closeOption",a.value=w.value,a.checked=w.value==="current",a.style.cssText=`
      width: 18px;
      height: 18px;
      cursor: pointer;
      accent-color: #57be72;
    `;const d=document.createElement("label");d.textContent=w.label,d.style.cssText=`
      flex: 1;
      font-size: 14px;
      color: #374151;
      cursor: pointer;
      margin: 0;
    `,a.addEventListener("change",()=>{a.checked&&(i=w.value,r.querySelectorAll("div").forEach(h=>{h.style.background=""}),c.style.background="#f0fdf4")}),w.value==="current"&&(c.style.background="#f0fdf4"),c.addEventListener("click",()=>{a.checked=!0,a.dispatchEvent(new Event("change"))}),c.appendChild(a),c.appendChild(d),r.appendChild(c)});const s=document.createElement("div");s.style.cssText=`
    display: flex;
    gap: 10px;
    justify-content: flex-end;
  `;const f=document.createElement("button");f.textContent="取消",f.style.cssText=`
    padding: 4px 20px;
    font-size: 14px;
    font-weight: 600;
    border-radius: 8px;
    border: 1px solid #57be72;
    background: #ffffff;
    color: #57be72;
    cursor: pointer;
    transition: all 0.2s;
  `,f.addEventListener("mouseenter",()=>{f.style.background="#f0fdf4"}),f.addEventListener("mouseleave",()=>{f.style.background="#ffffff"}),f.addEventListener("click",()=>{le()});const p=document.createElement("button");p.textContent="确定",p.style.cssText=`
    padding: 4px 20px;
    font-size: 14px;
    font-weight: 600;
    border-radius: 8px;
    border: none;
    background: #57be72;
    color: #ffffff;
    cursor: pointer;
    transition: all 0.2s;
  `,p.addEventListener("mouseenter",()=>{p.style.background="#4a9d5f"}),p.addEventListener("mouseleave",()=>{p.style.background="#57be72"}),p.addEventListener("click",async()=>{await et(i),le()}),s.appendChild(f),s.appendChild(p),e.appendChild(o),e.appendChild(t),e.appendChild(r),e.appendChild(s),B.appendChild(e),B.addEventListener("click",w=>{w.target===B&&le()}),document.body.appendChild(B)}function Ze(){B||Qe(),B.style.display="flex"}function le(){B&&(B.style.display="none")}async function et(e){const o=window.location.href,t=new URL(o).hostname;e==="current"?(sessionStorage.setItem("wisemind_current_visit_closed","true"),V()):e==="site"?(chrome.storage.sync.get(["wisemindDisabledSites"],r=>{const n=r.wisemindDisabledSites||{};n[t]=!0,chrome.storage.sync.set({wisemindDisabledSites:n})}),V()):e==="permanent"&&(chrome.storage.sync.get(["wisemindConfig"],r=>{const n=r.wisemindConfig||{};n.enableFloatingButton=!1,chrome.storage.sync.set({wisemindConfig:n})}),V())}function tt(){B&&B.parentNode&&(B.parentNode.removeChild(B),B=null)}function Q(){U&&U.parentNode&&(U.parentNode.removeChild(U),U=null)}function Pe(){D&&D.parentNode&&D.parentNode.removeChild(D),D=null,ee=null,te=null,ne=null,J=null,oe=null}function nt(){if(D)return D;D=document.createElement("div"),D.id="wisemind-article-batch-progress",D.style.cssText=`
    position: fixed;
    right: 20px;
    bottom: 20px;
    width: min(360px, calc(100vw - 24px));
    padding: 14px;
    border-radius: 14px;
    background: rgba(17, 24, 39, 0.94);
    color: #ffffff;
    z-index: 10000003;
    box-shadow: 0 18px 50px rgba(15, 23, 42, 0.35);
    display: flex;
    flex-direction: column;
    gap: 10px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  `;const e=document.createElement("div");e.style.cssText=`
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  `,ee=document.createElement("div"),ee.style.cssText=`
    font-size: 14px;
    font-weight: 700;
    color: #f8fafc;
  `;const o=document.createElement("button");o.type="button",o.textContent="×",o.style.cssText=`
    border: none;
    background: rgba(255, 255, 255, 0.08);
    color: #cbd5e1;
    width: 24px;
    height: 24px;
    border-radius: 999px;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
  `,o.addEventListener("click",()=>{ce=!0,Pe()}),te=document.createElement("div"),te.style.cssText=`
    font-size: 12px;
    color: #cbd5e1;
    line-height: 1.5;
  `;const t=document.createElement("div");return t.style.cssText=`
    width: 100%;
    height: 8px;
    border-radius: 999px;
    overflow: hidden;
    background: rgba(148, 163, 184, 0.24);
  `,ne=document.createElement("div"),ne.style.cssText=`
    width: 0%;
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, #4ade80 0%, #22c55e 100%);
    transition: width 0.2s ease;
  `,J=document.createElement("div"),J.style.cssText=`
    font-size: 12px;
    color: #e2e8f0;
    line-height: 1.5;
    word-break: break-word;
  `,oe=document.createElement("div"),oe.style.cssText=`
    font-size: 12px;
    color: #94a3b8;
    line-height: 1.5;
  `,e.appendChild(ee),e.appendChild(o),t.appendChild(ne),D.appendChild(e),D.appendChild(te),D.appendChild(t),D.appendChild(J),D.appendChild(oe),document.body.appendChild(D),D}function De(e={}){const o=e.phase||"progress";if(o==="starting"&&(ce=!1),ce&&o!=="done")return;nt();const t=Number(e.total)||0,r=Number(e.completed)||0,n=Number(e.successCount)||0,i=Number(e.failCount)||0,s=Number(e.activeCount)||0,f=Number(e.queuedCount)||0,p=Number(e.concurrency)||0,w=t>0?Math.min(100,Math.max(0,Math.round(r/t*100))):0;ee.textContent=o==="done"?"文章转存完成":"文章转存进行中",te.textContent=e.status||`已完成 ${r}/${t}，成功 ${n}，失败 ${i}`,ne.style.width=`${w}%`,J.textContent=e.currentTitle?`当前：${e.currentTitle}`:"正在准备...",oe.textContent=`进度 ${r}/${t} · 成功 ${n} · 失败 ${i}`+(p>0?` · 同时处理 ${s}/${p}`:"")+(f>0?` · 等待 ${f}`:""),o==="done"&&(ce=!1,J.textContent=i>0?"有部分文章未成功转存，可查看浏览器通知或控制台详情。":"本次文章已全部转存完成。",setTimeout(()=>{Pe()},5e3))}function fe(e,o){const t=document.createElement("option");return t.value=String(e??""),t.textContent=o||"未命名",t}function ot(e){if(!Array.isArray(e)||e.length===0)return!1;Q(),U=document.createElement("div"),U.id="wisemind-article-links-dialog",U.style.cssText=`
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 10000000;
    display: flex;
    align-items: center;
    justify-content: center;
  `;const o=document.createElement("div");o.style.cssText=`
    background: #ffffff;
    border-radius: 12px;
    padding: 20px 20px 16px;
    width: 680px;
    max-width: 94vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    gap: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
    position: relative;
  `;const t=document.createElement("div");t.innerHTML="×",t.style.cssText=`
    position: absolute;
    top: 10px;
    right: 12px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 20px;
    color: #6b7280;
    transition: all 0.2s;
    border-radius: 4px;
  `,t.addEventListener("mouseenter",()=>{t.style.background="#f3f4f6",t.style.color="#111827"}),t.addEventListener("mouseleave",()=>{t.style.background="transparent",t.style.color="#6b7280"}),t.addEventListener("click",()=>{Q()});const r=document.createElement("h3");r.textContent="选择要转存的文章",r.style.cssText=`
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    color: #111827;
    padding-right: 24px;
  `;const n=document.createElement("div");n.style.cssText=`
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    color: #374151;
  `;const i=document.createElement("input");i.type="checkbox",i.checked=!0,i.style.cssText=`
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: #57be72;
  `;const s=document.createElement("label");s.textContent=`全选（${e.length||0}）`,s.style.cssText=`
    cursor: pointer;
    margin: 0;
  `,s.addEventListener("click",()=>{i.click()}),n.appendChild(i),n.appendChild(s);const f=document.createElement("div");f.style.cssText=`
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 8px;
    max-height: 360px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: #f9fafb;
  `;const p=[];e.forEach((l,E)=>{const S=document.createElement("label");S.style.cssText=`
      display: flex;
      align-items: flex-start;
      gap: 10px;
      padding: 10px;
      background: #ffffff;
      border-radius: 8px;
      border: 1px solid #e5e7eb;
      cursor: pointer;
      transition: all 0.2s;
    `,S.addEventListener("mouseenter",()=>{S.style.borderColor="#c7d2fe",S.style.background="#f8fafc"}),S.addEventListener("mouseleave",()=>{S.style.borderColor="#e5e7eb",S.style.background="#ffffff"});const I=document.createElement("input");I.type="checkbox",I.checked=!0,I.style.cssText=`
      width: 16px;
      height: 16px;
      margin-top: 3px;
      cursor: pointer;
      accent-color: #57be72;
    `;const N=document.createElement("div");N.style.cssText=`
      display: flex;
      flex-direction: column;
      gap: 4px;
      flex: 1;
      min-width: 0;
    `;const m=document.createElement("div");m.textContent=(l==null?void 0:l.title)||`未命名文章 ${E+1}`,m.style.cssText=`
      font-size: 14px;
      font-weight: 600;
      color: #111827;
      line-height: 1.4;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      width: 100%;
    `;const P=document.createElement("div");P.textContent=(l==null?void 0:l.desc)||"",P.style.cssText=`
      font-size: 12px;
      color: #4b5563;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      width: 100%;
    `;const F=document.createElement("div");F.textContent=(l==null?void 0:l.url)||"",F.style.cssText=`
      font-size: 12px;
      color: #6b7280;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      width: 100%;
    `,N.appendChild(m),l!=null&&l.desc&&N.appendChild(P),l!=null&&l.url&&N.appendChild(F),S.appendChild(I),S.appendChild(N),f.appendChild(S),p.push(I)});const w=document.createElement("div");w.style.cssText=`
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
  `;const c=document.createElement("div");c.style.cssText=`
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1 1 360px;
    min-width: 0;
  `;const a=document.createElement("span");a.textContent="转存到",a.style.cssText=`
    flex: 0 0 auto;
    font-size: 13px;
    color: #4b5563;
  `;const d=document.createElement("select");d.style.cssText=`
    width: 124px;
    height: 36px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    background: #ffffff;
    color: #111827;
    padding: 0 10px;
    font-size: 13px;
    outline: none;
  `,d.appendChild(fe("file","文档列表")),d.appendChild(fe("knowledge","知识库"));const h=document.createElement("select");h.style.cssText=`
    flex: 1 1 220px;
    min-width: 180px;
    height: 36px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    background: #ffffff;
    color: #111827;
    padding: 0 10px;
    font-size: 13px;
    outline: none;
  `,c.appendChild(a),c.appendChild(d),c.appendChild(h);const x=document.createElement("div");x.style.cssText=`
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    flex: 0 0 auto;
  `;const b=document.createElement("button");b.textContent="取消",b.style.cssText=`
    padding: 8px 16px;
    border-radius: 8px;
    border: 1px solid #d1d5db;
    background: #ffffff;
    font-size: 14px;
    cursor: pointer;
    color: #374151;
  `,b.addEventListener("click",()=>{Q()});const C=document.createElement("button");C.textContent="保存",C.style.cssText=`
    padding: 8px 18px;
    border-radius: 8px;
    border: none;
    background: #57be72;
    font-size: 14px;
    cursor: pointer;
    color: #ffffff;
    font-weight: 600;
  `;let _=[{id:"",name:"--根目录--"}],W=[{id:"",name:"请选择知识库"}],T="",v="";const A=()=>{var N;const l=d.value==="knowledge"?"knowledge":"file",E=l==="knowledge"?W:_,S=l==="knowledge"?v:T;h.innerHTML="",E.forEach(m=>{h.appendChild(fe(m.id,m.name))});const I=E.some(m=>String(m.id)===String(S));h.value=String(I?S:((N=E[0])==null?void 0:N.id)??"")},k=async()=>{try{const l=await new Promise(m=>{L({type:"WISEMIND_GET_LINK_SAVE_TARGET_OPTIONS"},P=>{m(P!=null&&P.ok?P:null)})}),E=(l==null?void 0:l.config)||{},S=E.linkSaveTarget==="knowledge"?"knowledge":"file";T=String(E.linkSaveTargetFileFolderId||""),v=String(E.linkSaveTargetKnowledgeBaseId||""),d.value=S,A();const I=Array.isArray(l==null?void 0:l.fileFolders)?l.fileFolders:[],N=Array.isArray(l==null?void 0:l.knowledgeBases)?l.knowledgeBases:[];_=[{id:"",name:"--根目录--"},...I.filter(He).slice().sort((m,P)=>Number(P.id)-Number(m.id)).map(m=>({id:m.id,name:m.name||"未命名文件夹"}))],W=[{id:"",name:"请选择知识库"},...N.slice().sort((m,P)=>Number(P.id)-Number(m.id)).map(m=>({id:m.id,name:m.name||"未命名知识库"}))],_.some(m=>String(m.id)===String(T))||(T=""),W.some(m=>String(m.id)===String(v))||(v=""),A()}catch(l){console.warn("加载转存位置失败",l),A()}};d.addEventListener("change",()=>{A()});const O=()=>{const l=p.filter(E=>E.checked).length;i.checked=l===p.length,i.indeterminate=l>0&&l<p.length,C.disabled=l===0,C.style.opacity=l===0?"0.6":"1",C.style.cursor=l===0?"not-allowed":"pointer"};return i.addEventListener("change",()=>{const l=i.checked;p.forEach(E=>{E.checked=l}),O()}),p.forEach(l=>{l.addEventListener("change",O)}),C.addEventListener("click",()=>{const l=e.filter((I,N)=>{var m;return(m=p[N])==null?void 0:m.checked});if(l.length===0){O();return}const E=d.value==="knowledge"?"knowledge":"file",S=String(h.value||"");if(E==="knowledge"&&!S){L({type:"WISEMIND_SHOW_NOTIFICATION",message:"✗ 请选择知识库"});return}C.disabled=!0,b.disabled=!0,d.disabled=!0,h.disabled=!0,C.textContent="保存中...",C.style.cursor="default",L({type:"WISEMIND_BATCH_SAVE_WECHAT_ARTICLES",links:l,targetConfig:{target:E,fileFolderId:E==="file"?S:"",knowledgeBaseId:E==="knowledge"?S:""}},I=>{if(I&&I.ok)De({phase:"starting",status:`准备转存 ${l.length} 篇文章`,total:l.length,completed:0,successCount:0,failCount:0,activeCount:0,queuedCount:l.length,concurrency:0}),Q();else{const N=(I==null?void 0:I.error)||"转存失败";L({type:"WISEMIND_SHOW_NOTIFICATION",message:`✗ ${N}`}),C.disabled=!1,b.disabled=!1,d.disabled=!1,h.disabled=!1,C.textContent="保存",C.style.cursor="pointer"}})}),O(),k(),x.appendChild(b),x.appendChild(C),w.appendChild(c),w.appendChild(x),o.appendChild(t),o.appendChild(r),o.appendChild(n),o.appendChild(f),o.appendChild(w),U.appendChild(o),U.addEventListener("click",l=>{l.target===U&&Q()}),document.body.appendChild(U),!0}function it(){u||chrome.storage.local.get(["wisemindFloatingButtonPosition"],e=>{const o=e.wisemindFloatingButtonPosition||{bottom:20,right:20,side:"right"};e.wisemindFloatingButtonPosition||(o.bottom=20,o.right=20,o.side="right"),u=document.createElement("div"),u.id="wisemind-floating-button";const t=o.side==="left"?`left: ${o.left||0}px; right: auto;`:`right: ${o.right||20}px; left: auto;`;u.style.cssText=`
      position: fixed;
      bottom: ${o.bottom||20}px;
      ${t}
      width: 42px;
      height: 42px;
      border-radius: 50%;
      background: #57be72;
      box-shadow: 0 4px 12px rgba(87, 190, 114, 0.4);
      cursor: move;
      z-index: 999999;
      display: flex;
      align-items: center;
      justify-content: center;
      transition: all 0.3s;
      user-select: none;
      -webkit-user-select: none;
      -moz-user-select: none;
      -ms-user-select: none;
      -webkit-touch-callout: none;
      -webkit-tap-highlight-color: transparent;
    `,u.setAttribute("draggable","false");const r=document.createElement("img");r.src=chrome.runtime.getURL("icons/icon48.png"),r.style.cssText=`
      width: 30px;
      height: 30px;
      object-fit: contain;
      pointer-events: none;
    `,u.appendChild(r),qe(),We(),u.addEventListener("mouseenter",()=>{u.style.transform="scale(1.1)",u.style.boxShadow="0 6px 16px rgba(87, 190, 114, 0.5)",y&&(y.style.opacity="1",y.style.pointerEvents="auto"),gt()}),u.addEventListener("mouseleave",()=>{u.style.transform="scale(1)",u.style.boxShadow="0 4px 12px rgba(87, 190, 114, 0.4)",y&&(y.style.opacity="0",y.style.pointerEvents="none"),he()});let n=!1,i=0,s=0,f=0,p=0,w=null,c=null;u.addEventListener("mousedown",d=>{if(d.target===y||y!=null&&y.contains(d.target))return;n=!1,u.style.cursor="grabbing",u.style.transition="none";const h=u.getBoundingClientRect();i=d.clientX,s=d.clientY,f=h.left,p=h.top,d.preventDefault(),d.stopPropagation(),d.stopImmediatePropagation(),window.getSelection&&window.getSelection().removeAllRanges(),w=x=>{if(!u)return;x.preventDefault(),x.stopPropagation();const b=Math.abs(x.clientX-i),C=Math.abs(x.clientY-s);if(b>3||C>3){n||(n=!0);const _=x.clientX-i,W=x.clientY-s;let T=f+_,v=p+W;const A=window.innerWidth-42,k=window.innerHeight-42;T=Math.max(0,Math.min(T,A)),v=Math.max(0,Math.min(v,k)),u.style.left=T+"px",u.style.top=v+"px",u.style.right="auto",u.style.bottom="auto",window.getSelection&&window.getSelection().removeAllRanges()}},c=x=>{if(u){if(x.preventDefault(),x.stopPropagation(),w&&document.removeEventListener("mousemove",w),c&&document.removeEventListener("mouseup",c),w=null,c=null,n){q(!0),u.style.cursor="move",u.style.transition="all 0.3s";const b=C=>{if(!u)return;const _=u.getBoundingClientRect(),W=_.left+_.width/2,T=window.innerWidth/2;let v,A,k;W<T?k="left":k="right",C?(v=k==="left"?0:"auto",A=k==="right"?0:"auto"):(v=k==="left"?_.left:"auto",A=k==="right"?Math.max(0,window.innerWidth-_.right):"auto");let O=window.innerHeight-_.top-42;O=Math.max(0,Math.min(O,window.innerHeight-42)),u.style.left=v==="auto"?"auto":v+"px",u.style.right=A==="auto"?"auto":A+"px",u.style.top="auto",u.style.bottom=O+"px";const l={bottom:O,[k]:k==="left"?v:A,side:k};chrome.storage.local.set({wisemindFloatingButtonPosition:l})};chrome.storage&&chrome.storage.sync?chrome.storage.sync.get(["wisemindConfig"],C=>{const W=(C.wisemindConfig||{}).floatingButtonSnapToEdge!==!1;me=W,b(W)}):b(me)}n=!1}},document.addEventListener("mousemove",w),document.addEventListener("mouseup",c)});const a=()=>{if(!u)return;if(u.getBoundingClientRect().bottom>window.innerHeight){const h=Math.max(0,window.innerHeight-42);u.style.bottom=h+"px",chrome.storage.local.get(["wisemindFloatingButtonPosition"],x=>{const b=x.wisemindFloatingButtonPosition||o;b.bottom=h,chrome.storage.local.set({wisemindFloatingButtonPosition:b})})}};window.addEventListener("resize",a),document.body.appendChild(u)})}function V(){u&&u.parentNode&&(u.parentNode.removeChild(u),u=null),g&&g.parentNode&&(g.parentNode.removeChild(g),g=null),Je(),tt()}function rt(e){let o=e;if(typeof o=="string"&&(o=o.split(",").map(r=>r.trim()).filter(Boolean)),!Array.isArray(o))return[...ge];const t=o.filter(r=>Ae[r]);return t.length?t:[...ge]}function Be(e){_e=rt(e),g&&g.parentNode&&(g.parentNode.removeChild(g),g=null),u&&We()}function lt(){const e=pe();L({type:"WISEMIND_SAVE_PAGE_LINK",title:document.title||"",content:e},o=>{if(o!=null&&o.ok){xe(o.message||"✓ 页面已保存");return}xe(`✗ 保存失败: ${(o==null?void 0:o.error)||"未知错误"}`,"error")}),q(!0)}function st(){q(!0),ke()}function at(){L({type:"WISEMIND_OPEN_SIDE_PANEL"},e=>{(e==null?void 0:e.ok)===!1&&L({type:"WISEMIND_SHOW_NOTIFICATION",message:e.error||"打开 AI 对话侧边栏失败"})}),q(!0)}function ct(){L({type:"WISEMIND_REQUEST_SAVE_PDF"}),q(!0)}function dt(){L({type:"WISEMIND_REQUEST_CAPTURE_FULL_PAGE"}),q(!0)}function ut(){q(!0),pt()}function ft(){H||(H=document.createElement("div"),H.id="wisemind-custom-capture-overlay",H.style.cssText=`
    position: fixed;
    inset: 0;
    z-index: 10000010;
    background: rgba(15, 23, 42, 0.12);
    cursor: crosshair;
  `,document.body.appendChild(H),$=document.createElement("div"),$.id="wisemind-custom-capture-selection",$.style.cssText=`
    position: absolute;
    border: 2px solid #57be72;
    background: rgba(87, 190, 114, 0.15);
    box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.08);
    display: none;
  `,H.appendChild($),R=document.createElement("div"),R.id="wisemind-custom-capture-tip",R.textContent="拖动选择截图区域，按 Esc 取消",R.style.cssText=`
    position: fixed;
    bottom: 18px;
    left: 50%;
    transform: translateX(-50%);
    background: #111827;
    color: #ffffff;
    padding: 6px 10px;
    border-radius: 10px;
    font-size: 12px;
    z-index: 10000011;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
    pointer-events: none;
  `,document.body.appendChild(R))}function ye(){H&&H.parentNode&&H.parentNode.removeChild(H),R&&R.parentNode&&R.parentNode.removeChild(R),H=null,$=null,R=null}function we(e){$&&($.style.display="block",$.style.left=e.left+"px",$.style.top=e.top+"px",$.style.width=e.width+"px",$.style.height=e.height+"px")}function pt(){if(re)return;re=!0,ft();let e=0,o=0,t=!1;const r=(c,a,d,h)=>{const x=Math.max(0,Math.min(c,d)),b=Math.max(0,Math.min(a,h)),C=Math.min(window.innerWidth,Math.max(c,d)),_=Math.min(window.innerHeight,Math.max(a,h));return{left:x,top:b,width:Math.max(0,C-x),height:Math.max(0,_-b)}},n=c=>{ye(),re=!1,!(!c||c.width<6||c.height<6)&&mt(c)},i=c=>{c.button===0&&(c.preventDefault(),c.stopPropagation(),t=!0,e=c.clientX,o=c.clientY,we({left:e,top:o,width:0,height:0}))},s=c=>{if(!t)return;const a=r(e,o,c.clientX,c.clientY);we(a)},f=c=>{if(!t)return;t=!1;const a=r(e,o,c.clientX,c.clientY);n(a),w()},p=c=>{c.key==="Escape"&&(ye(),re=!1,w())},w=()=>{H&&H.removeEventListener("mousedown",i),window.removeEventListener("mousemove",s,!0),window.removeEventListener("mouseup",f,!0),window.removeEventListener("keydown",p,!0)};H.addEventListener("mousedown",i),window.addEventListener("mousemove",s,!0),window.addEventListener("mouseup",f,!0),window.addEventListener("keydown",p,!0)}function mt(e){L({type:"WISEMIND_CAPTURE_VISIBLE_TAB"},o=>{if(!o||!o.ok||!o.dataUrl){L({type:"WISEMIND_SHOW_NOTIFICATION",message:`✗ 截图失败: ${(o==null?void 0:o.error)||"无法获取截图"}`});return}const t=new Image;t.onload=()=>{const r=window.devicePixelRatio||1,n=document.createElement("canvas");n.width=Math.max(1,Math.round(e.width*r)),n.height=Math.max(1,Math.round(e.height*r));const i=n.getContext("2d");if(!i){L({type:"WISEMIND_SHOW_NOTIFICATION",message:"✗ 截图失败: 无法创建画布"});return}const s=Math.round(e.left*r),f=Math.round(e.top*r);i.drawImage(t,s,f,n.width,n.height,0,0,n.width,n.height);const p=n.toDataURL("image/png");L({type:"WISEMIND_DOWNLOAD_IMAGE",dataUrl:p,title:document.title||"screenshot"})},t.onerror=()=>{L({type:"WISEMIND_SHOW_NOTIFICATION",message:"✗ 截图失败: 图片加载错误"})},t.src=o.dataUrl})}function We(){if(g)return;g=document.createElement("div"),g.id="wisemind-floating-menu",g.style.cssText=`
    position: fixed;
    z-index: 10000000;
    display: none;
    background: #ffffff;
    color: #111827;
    border-radius: 12px;
    padding: 8px;
    gap: 6px;
    align-items: stretch;
    flex-direction: column;
    border: 1px solid #e2e8f0;
    box-shadow: 0 16px 40px rgba(15, 23, 42, 0.15);
  `;const e=(t,r)=>{const n=document.createElement("button");n.type="button",n.style.cssText=`
      display: flex;
      align-items: center;
      gap: 6px;
      background: #f8fafc;
      color: #0f172a;
      border: 1px solid #e2e8f0;
      border-radius: 8px;
      padding: 8px 10px;
      font-size: 12px;
      font-weight: 600;
      cursor: pointer;
      white-space: nowrap;
      transition: all 0.15s ease;
    `;const i=document.createElement("img");i.src=chrome.runtime.getURL("icons/icon16.png"),i.alt="WiseMindAI",i.style.cssText="width: 16px; height: 16px;";const s=document.createElement("span");return s.textContent=t,n.appendChild(i),n.appendChild(s),n.addEventListener("click",f=>{f.preventDefault(),f.stopPropagation(),r()}),n.addEventListener("mouseenter",()=>{n.style.background="#eef2f7",n.style.borderColor="#cbd5f5"}),n.addEventListener("mouseleave",()=>{n.style.background="#f8fafc",n.style.borderColor="#e2e8f0"}),n},o={"save-page":lt,"ai-chat":at,"pick-text":st,"capture-custom":ut,"capture-full-page":dt,"save-page-pdf":ct};_e.forEach(t=>{const r=Ae[t],n=o[t];if(!r||!n)return;const i=e(r,n);g.appendChild(i)}),g.addEventListener("mouseenter",()=>{G&&(clearTimeout(G),G=null)}),g.addEventListener("mouseleave",()=>{he()}),document.body.appendChild(g)}function be(){if(!g||!u)return;g.style.display="flex",g.style.visibility="hidden";const e=g.getBoundingClientRect(),o=u.getBoundingClientRect(),r=Math.max(8,o.top-e.height-10),n=Math.max(8,o.left-e.width+o.width);g.style.top=`${r}px`,g.style.left=`${n}px`,g.style.visibility="visible"}function gt(){g&&(G&&(clearTimeout(G),G=null),chrome.storage&&chrome.storage.sync?chrome.storage.sync.get(["wisemindConfig"],e=>{const o=e.wisemindConfig||{};Be(o.floatingMenuItems),be()}):be())}function q(e=!1){if(g){if(e){g.style.display="none";return}he()}}function he(){g&&(G&&clearTimeout(G),G=setTimeout(()=>{g&&(g.style.display="none")},150))}async function j(){chrome.storage.sync.get(["wisemindConfig"],async e=>{const o=e.wisemindConfig||{};if(Be(o.floatingMenuItems),me=o.floatingButtonSnapToEdge!==!1,!o.enableFloatingButton){V();return}if(Ne(window.location.href,o.floatingButtonWhitelist)){V();return}if(await Ve()){V();return}if(await je()){V();return}it()})}chrome.storage.onChanged.addListener((e,o)=>{o==="sync"&&(e.wisemindConfig&&(j(),Ie()),e.wisemindDisabledSites&&j())});let de=window.location.href;const ht=new MutationObserver(()=>{const e=window.location.href;e!==de&&(de=e,setTimeout(()=>{j()},100))});if(window.history&&window.history.pushState){const e=window.history.pushState;window.history.pushState=function(...o){e.apply(window.history,o),setTimeout(()=>{const t=window.location.href;t!==de&&(de=t,setTimeout(()=>{j()},100))},0)}}ht.observe(document.body,{childList:!0,subtree:!0});function xt(){window.print()}async function yt(){return new Promise(async(e,o)=>{let t=null;try{const r=window.scrollX||window.pageXOffset,n=window.scrollY||window.pageYOffset;t=document.createElement("div"),t.id="wisemind-capture-progress",t.style.cssText=`
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        background: rgba(0, 0, 0, 0.8);
        color: white;
        padding: 20px 40px;
        border-radius: 10px;
        font-size: 16px;
        z-index: 10000000;
        font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
        pointer-events: none;
      `,t.textContent="正在准备截图...",document.body.appendChild(t),window.scrollTo(0,0),await new Promise(T=>setTimeout(T,300));const i=document.body,s=document.documentElement;let f=0,p=Math.max(i.scrollHeight||0,s.scrollHeight||0);for(let T=0;T<3;T++){window.scrollTo(0,p),await new Promise(A=>setTimeout(A,500));const v=Math.max(i.scrollHeight||0,s.scrollHeight||0);if(v===f&&v===p)break;f=p,p=v}window.scrollTo(0,0),await new Promise(T=>setTimeout(T,300));const w=Math.max(i.scrollWidth||0,s.scrollWidth||0,i.offsetWidth||0,s.offsetWidth||0,s.clientWidth||0,window.innerWidth||0),c=Math.max(i.scrollHeight||0,s.scrollHeight||0,i.offsetHeight||0,s.offsetHeight||0,s.clientHeight||0,window.innerHeight||0,p),a=window.innerWidth||s.clientWidth,d=window.innerHeight||s.clientHeight,h=Math.ceil(c/d),x=document.createElement("canvas");x.width=w,x.height=c;const b=x.getContext("2d");b.fillStyle="#ffffff",b.fillRect(0,0,w,c);const C=document.documentElement.style.overflow,_=document.body.style.overflow;document.documentElement.style.overflow="hidden",document.body.style.overflow="hidden";for(let T=0;T<h;T++){const v=T*d,A=Math.round(T/h*100);t.textContent=`正在截图... ${A}%`,window.scrollTo(0,v),await new Promise(F=>setTimeout(F,400));let k=window.scrollY||window.pageYOffset,O=0;for(;Math.abs(k-v)>5&&O<3;)window.scrollTo(0,v),await new Promise(F=>setTimeout(F,200)),k=window.scrollY||window.pageYOffset,O++;t.style.display="none",await new Promise(F=>setTimeout(F,100));const l=await new Promise(F=>{L({type:"WISEMIND_CAPTURE_VISIBLE_TAB"},F)});if(!l||!l.ok)throw new Error((l==null?void 0:l.error)||"截图失败");const E=new Image;await new Promise((F,Oe)=>{E.onload=F,E.onerror=Oe,E.src=l.dataUrl});const S=c-v,I=Math.min(d,S),N=E.width,m=E.height,P=S<d?m*S/d:m;b.drawImage(E,0,0,N,P,0,v,a,I),t.style.display="block"}t.textContent="正在生成图片...",window.scrollTo(r,n),document.documentElement.style.overflow=C,document.body.style.overflow=_,t&&t.parentNode&&t.remove();const W=x.toDataURL("image/png");e({ok:!0,dataUrl:W})}catch(r){t&&t.parentNode&&t.remove();const n=document.documentElement.style.overflow,i=document.body.style.overflow;n!==void 0&&(document.documentElement.style.overflow=n),i!==void 0&&(document.body.style.overflow=i),o(r)}})}chrome.runtime.onMessage.addListener((e,o,t)=>{var r;if(e&&e.type==="WISEMIND_PING")return t({ok:!0,loaded:!0}),!0;if(e&&e.type==="WISEMIND_GET_SELECTION"){try{const{html:n,text:i}=ze();t({ok:!0,html:n,text:i})}catch(n){t({ok:!1,error:n&&n.message||String(n)})}return!0}if(e&&e.type==="WISEMIND_GET_PAGE_TEXT"){try{const n=pe();t({ok:!0,text:n})}catch(n){t({ok:!1,error:n&&n.message||String(n)})}return!0}if(e&&e.type==="WISEMIND_PICK_CONTENT_BLOCK")return ke(),t({ok:!0}),!0;if(e&&e.type==="WISEMIND_CONFIG_UPDATED"&&j(),e&&e.type==="WISEMIND_BATCH_SAVE_PROGRESS")return De(e.progress||{}),t({ok:!0}),!0;if(e&&e.type==="WISEMIND_SAVE_AS_PDF"){try{xt(),t({ok:!0})}catch(n){t({ok:!1,error:n&&n.message||String(n)})}return!0}if(e&&e.type==="WISEMIND_CAPTURE_FULL_PAGE")return yt().then(n=>t(n)).catch(n=>t({ok:!1,error:n&&n.message||String(n)})),!0;if(e&&e.type==="WISEMIND_GET_PAGE_INFO"){try{let n="";try{n=pe()}catch(s){console.warn("获取页面文本时出现错误（已忽略）:",s.message),n=""}let i="";try{i=((r=window.getSelection())==null?void 0:r.toString())||""}catch{i=""}t({ok:!0,text:n,selection:i})}catch{t({ok:!0,text:""})}return!0}if(e&&e.type==="WISEMIND_READ_CLIPBOARD")return(async()=>{try{if(navigator.clipboard&&navigator.clipboard.readText){const n=await navigator.clipboard.readText();t({ok:!0,data:n})}else{const n=document.createElement("textarea");n.style.position="fixed",n.style.left="-999999px",n.style.top="-999999px",document.body.appendChild(n),n.focus(),n.select();try{const i=document.execCommand("paste"),s=n.value;document.body.removeChild(n),t(i&&s?{ok:!0,data:s}:{ok:!1,error:"无法读取剪贴板"})}catch(i){document.body.removeChild(n),t({ok:!1,error:"无法读取剪贴板："+(i.message||String(i))})}}}catch(n){t({ok:!1,error:n&&n.message||String(n)})}})(),!0;if(console.log("[WiseMindAI message]",{message:e}),e&&e.type==="WISEMIND_COPY_WECHAT_LINKS")return(async()=>{try{const n={title:".msg-appmsg__title",url:".msg-appmsg__content",desc:".msg-appmsg__desc"};let i=Array.isArray(e==null?void 0:e.schemes)?e.schemes.filter(Boolean):[];if(console.log("[WISEMIND_COPY_WECHAT_LINKS]",{schemesToUse:i}),i.length===0){const a=await new Promise(x=>{chrome.storage.sync.get(["wisemindConfig"],b=>{x(b.wisemindConfig||{})})}),d=Array.isArray(a.wechatSchemes)?a.wechatSchemes.filter(Boolean):[],h=d.filter(x=>x.enabled!==!1);if(d.length>0&&h.length===0){t({ok:!1,error:"未启用任何方案，请先在设置中启用方案"});return}i=h.length>0?h:[{selectors:{title:a.wechatTitleSelector||n.title,url:a.wechatUrlSelector||n.url,desc:a.wechatDescSelector||n.desc}}]}const s=[],f=new Set;if(i.forEach(a=>{console.log("[WiseMindAI 解析方案]",{scheme:a});const d=(a==null?void 0:a.selectors)||{},h=d.title||n.title,x=d.url||n.url,b=d.desc||n.desc,C=(a==null?void 0:a.autoJoinDomain)===!0,_=h.trim(),W=b.trim(),T=_.startsWith(":scope")?[]:Array.from(document.querySelectorAll(h)),v=W.startsWith(":scope")?[]:Array.from(document.querySelectorAll(b)),A=document.querySelectorAll(x);A.forEach((k,O)=>{var I,N,m,P;let l=k.getAttribute("href")||"";if(l.startsWith("//")&&(l=`https:${l}`),C&&l)try{l=new URL(l,window.location.origin).toString()}catch{}if(!l||f.has(l))return;const E=_.startsWith(":scope")?((I=k.querySelector(h))==null?void 0:I.textContent.trim())||"":((N=T[O])==null?void 0:N.textContent.trim())||k.textContent.trim()||"",S=W.startsWith(":scope")?((m=k.querySelector(b))==null?void 0:m.textContent.trim())||"":((P=v[O])==null?void 0:P.textContent.trim())||"";s.push({title:E,url:l,desc:S}),f.add(l)}),console.log("[WiseMindAI 解析指定平台]",{urlEls:A,descNodes:v,titleNodes:T,seenUrls:f,result:s,scheme:a})}),console.log("[WiseMindAI 解析结果]",{result:s,seenUrls:f}),s.length===0){t({ok:!1,error:"未找到文章链接，请确保页面已加载完成"});return}const p=ot(s),w=JSON.stringify(s,null,2),c=()=>{const a=document.createElement("textarea");a.value=w,a.style.position="fixed",a.style.left="-999999px",a.style.top="-999999px",document.body.appendChild(a),a.focus(),a.select();try{const d=document.execCommand("copy");document.body.removeChild(a),t(d?{ok:!0,count:s.length,selectionUi:p}:{ok:!1,error:"复制失败，请手动复制"})}catch(d){document.body.removeChild(a),t({ok:!1,error:"复制失败："+(d.message||String(d))})}};if(navigator.clipboard&&navigator.clipboard.writeText)try{await navigator.clipboard.writeText(w),t({ok:!0,count:s.length,selectionUi:p})}catch{c()}else c()}catch(n){console.log("[WiseMindAI 链接解析失败]",n),t({ok:!1,error:n&&n.message||String(n)})}})(),!0});const wt="wisemind_current_visit_closed";sessionStorage.removeItem(wt);document.readyState==="loading"?document.addEventListener("DOMContentLoaded",j):j();Ie();
})()
