var V=Object.defineProperty;var K=(o,t,e)=>t in o?V(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var w=(o,t,e)=>K(o,typeof t!="symbol"?t+"":t,e);import{u as D,w as Q}from"./xlsx-ejz-vvm2.js";class W{constructor(t={}){this.defaultOptions={duration:2e3,position:"top-right",maxToasts:3,...t},this.container=null,this.toasts=new Set,this.init()}init(){if(document.getElementById("simple-toast-container")){this.container=document.getElementById("simple-toast-container");return}this.injectStyles(),this.createContainer()}injectStyles(){if(document.getElementById("simple-toast-styles"))return;const t=document.createElement("style");t.id="simple-toast-styles",t.textContent=`
      #simple-toast-container {
        position: fixed;
        top: 20px;
        right: 20px;
        z-index: 2147483647;
        display: flex;
        flex-direction: column;
        gap: 10px;
        pointer-events: none;
      }
      
      .simple-toast {
        pointer-events: auto;
        background: rgba(0, 0, 0, 0.85);
        color: white;
        padding: 12px 20px;
        border-radius: 8px;
        font-size: 14px;
        max-width: 300px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
        animation: toast-fade-in 0.3s ease;
        font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
        backdrop-filter: blur(10px);
        border: 1px solid rgba(255, 255, 255, 0.1);
        overflow: hidden;
        position: relative;
      }
      
      .simple-toast-success {
        background: rgba(34, 197, 94, 0.9) !important;
        border-color: rgba(34, 197, 94, 0.3) !important;
      }
      
      .simple-toast-error {
        background: rgba(239, 68, 68, 0.9) !important;
        border-color: rgba(239, 68, 68, 0.3) !important;
      }
      
      .simple-toast-warning {
        background: rgba(245, 158, 11, 0.9) !important;
        border-color: rgba(245, 158, 11, 0.3) !important;
      }
      
      .simple-toast-info {
        background: rgba(59, 130, 246, 0.9) !important;
        border-color: rgba(59, 130, 246, 0.3) !important;
      }
      
      .simple-toast-progress {
        position: absolute;
        bottom: 0;
        left: 0;
        height: 3px;
        background: rgba(255, 255, 255, 0.5);
        width: 100%;
        animation: toast-progress linear forwards;
      }
      
      @keyframes toast-fade-in {
        from {
          opacity: 0;
          transform: translateY(-20px) scale(0.95);
        }
        to {
          opacity: 1;
          transform: translateY(0) scale(1);
        }
      }
      
      @keyframes toast-fade-out {
        from {
          opacity: 1;
          transform: translateY(0) scale(1);
        }
        to {
          opacity: 0;
          transform: translateY(-20px) scale(0.95);
        }
      }
      
      @keyframes toast-progress {
        from { width: 100%; }
        to { width: 0%; }
      }
    `,document.head.appendChild(t)}createContainer(){this.container=document.createElement("div"),this.container.id="simple-toast-container",this.updatePosition(this.defaultOptions.position),document.body.appendChild(this.container)}updatePosition(t){const e={"top-right":{top:"20px",right:"20px",left:"auto",bottom:"auto",alignItems:"flex-end"},"top-left":{top:"20px",left:"20px",right:"auto",bottom:"auto",alignItems:"flex-start"},"bottom-right":{bottom:"20px",right:"20px",left:"auto",top:"auto",alignItems:"flex-end"},"bottom-left":{bottom:"20px",left:"20px",right:"auto",top:"auto",alignItems:"flex-start"},"top-center":{top:"20px",left:"50%",transform:"translateX(-50%)",right:"auto",bottom:"auto",alignItems:"center"},"bottom-center":{bottom:"20px",left:"50%",transform:"translateX(-50%)",right:"auto",top:"auto",alignItems:"center"}};e[t]&&this.container&&Object.assign(this.container.style,{position:"fixed",display:"flex",flexDirection:"column",gap:"10px",zIndex:"2147483647",...e[t]})}show(t,e={}){const r={...this.defaultOptions,...e};this.cleanup();const n=document.createElement("div");if(n.className=`simple-toast simple-toast-${r.type}`,n.textContent=t,r.showProgress){const i=document.createElement("div");i.className="simple-toast-progress",i.style.animationDuration=`${r.duration}ms`,n.appendChild(i)}return this.container.appendChild(n),this.toasts.add(n),r.duration>0&&setTimeout(()=>{this.remove(n)},r.duration),r.clickToClose&&n.addEventListener("click",()=>this.remove(n)),{element:n,remove:()=>this.remove(n),updateMessage:i=>{n.textContent=i}}}success(t,e={}){return this.show(t,{...e,type:"success"})}error(t,e={}){return this.show(t,{...e,type:"error"})}warning(t,e={}){return this.show(t,{...e,type:"warning"})}info(t,e={}){return this.show(t,{...e,type:"info"})}remove(t){!t||!this.toasts.has(t)||(t.style.animation="toast-fade-out 0.3s ease forwards",setTimeout(()=>{t.parentNode===this.container&&this.container.removeChild(t),this.toasts.delete(t)},300))}cleanup(){if(this.toasts.size>=this.defaultOptions.maxToasts){const t=Array.from(this.toasts)[0];this.remove(t)}}clearAll(){this.toasts.forEach(t=>{t.parentNode===this.container&&this.container.removeChild(t)}),this.toasts.clear()}destroy(){this.clearAll(),this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container),this.container=null}}let k=null;function T(){return k||(k=new W),k}const A={show:(o,t)=>T().show(o,t),success:(o,t)=>T().success(o,t),error:(o,t)=>T().error(o,t),warning:(o,t)=>T().warning(o,t),info:(o,t)=>T().info(o,t),clearAll:()=>T().clearAll(),destroy:()=>{k&&(k.destroy(),k=null)},create:o=>new W(o),config:o=>{const t=T();Object.assign(t.defaultOptions,o),o.position&&t.updatePosition(o.position)}};async function H(){var o;try{const t=await new Promise((e,r)=>{chrome.storage.sync.get(["profile"],n=>{chrome.runtime.lastError?r(chrome.runtime.lastError):e(n)})});return!!((o=t==null?void 0:t.profile)!=null&&o.license)}catch{return A.error("检查许可证失败",{duration:3e3}),!1}}async function X(){var o;try{const t=await new Promise((r,n)=>{chrome.storage.local.get(["options"],i=>{chrome.runtime.lastError?n(chrome.runtime.lastError):r(i)})}),e=["copy_txt","copy_csv","copy_json","download_csv","download_excel"];return t!=null&&t.options||(t.options={awesome:!0,counter:0,walk_all_windows:!1,ignore_cell_img:!0,ignore_blank_table:!0,ignore_one_row_table:!1,ignore_display_none_table:!0,ignore_display_none_contained_table:!0,in_page_show_toolbar_above_table:!1,in_page_buttons:e,history_max_length:1e3}),(o=t==null?void 0:t.options)!=null&&o.in_page_buttons||(t.options.in_page_buttons=e),(t==null?void 0:t.options)??{}}catch{return A.error("获取配置失败",{duration:3e3}),!1}}async function Z(){let o=await X();return o==null?void 0:o.in_page_buttons}const N="__tc_copy_btn_wrap";function tt(o,t){if(!o)return;let e=o.previousElementSibling,r=null,n=0;for(;e;){const i=e;e=i.previousElementSibling,i.tagName.toLowerCase()==="div"&&i.classList.contains(t)&&(r?(i.remove(),n++):r=i)}return n>0&&console.log(`删除了 ${n} 个重复的table-bar`),r}function et(o){return window.getComputedStyle(o).display==="none"}function ot(o){let t=o.parentNode;for(;t&&t!==document;){if(window.getComputedStyle(t).display==="none")return!0;t=t.parentNode}return!1}function I(){document.querySelectorAll("table").forEach(async(t,e)=>{var M;const r=await X();if(t.previousElementSibling&&t.previousElementSibling.classList.contains(N)){tt(t,N);return}if(r.ignore_blank_table&&!(t&&t.rows&&t.rows.length&&Array.from(t.rows).some(m=>Array.from(m.cells).some(p=>(p.textContent||"").trim()!=="")))){console.log("空白表格，就不要显示工具栏了");return}if(r.ignore_one_row_table&&t.rows.length===1){console.log("只有1行，就不要显示工具栏了");return}if(r.ignore_display_none_table&&et(t)){console.log("隐藏的表格，就不要显示工具栏了");return}if(r.ignore_display_none_contained_table&&ot(t)){console.log("包含隐藏的表格，就不要显示工具栏了");return}const n=document.createElement("div");n.className=N,n.style.display="flex",n.style.justifyContent="flex-start",n.style.flexWrap="wrap",n.style.gap="4px",n.style.alignItems="center",n.style.margin="4px 0",n.style.zIndex="999999";const i=document.createElement("button");i.innerText="复制txt",i.style.background="#2563eb",i.style.color="#fff",i.style.border="none",i.style.borderRadius="4px",i.style.padding="2px 10px",i.style.cursor="pointer",i.style.fontSize="12px",i.onclick=d=>{const p=S(t,{ignore_cell_img:!0}).map(h=>h.join("	")).join(`
`);navigator.clipboard.writeText(p).then(()=>{i.innerText="已复制",setTimeout(()=>{i.innerText="复制txt"},1200)}),d.stopPropagation(),d.preventDefault()};const l=document.createElement("button");l.innerText="复制csv",l.style.background="#059669",l.style.color="#fff",l.style.border="none",l.style.borderRadius="4px",l.style.padding="2px 10px",l.style.cursor="pointer",l.style.fontSize="12px",l.onclick=d=>{const p=S(t,{ignore_cell_img:!0}).map(h=>h.map(f=>`"${f.replace(/"/g,'""')}"`).join(",")).join(`
`);navigator.clipboard.writeText(p).then(()=>{l.innerText="已复制",setTimeout(()=>{l.innerText="复制csv"},1200)}),d.stopPropagation(),d.preventDefault()};const c=document.createElement("button");c.innerText="下载txt",c.style.background="#6366f1",c.style.color="#fff",c.style.border="none",c.style.borderRadius="4px",c.style.padding="2px 10px",c.style.cursor="pointer",c.style.fontSize="12px",c.onclick=d=>{const p=S(t,{ignore_cell_img:!0}).map(g=>g.join("	")).join(`
`),h=new Blob([p],{type:"text/plain"}),f=document.createElement("a");f.href=URL.createObjectURL(h),f.download=`table_${e+1}.txt`,document.body.appendChild(f),f.click(),document.body.removeChild(f),d.stopPropagation(),d.preventDefault()};const s=document.createElement("button");s.innerText="下载csv",s.style.background="#f59e42",s.style.color="#fff",s.style.border="none",s.style.borderRadius="4px",s.style.padding="2px 10px",s.style.cursor="pointer",s.style.fontSize="12px",s.onclick=d=>{const p=S(t,{ignore_cell_img:!0}).map(g=>g.map(C=>`"${C.replace(/"/g,'""')}"`).join(",")).join(`
`),h=new Blob([p],{type:"text/csv"}),f=document.createElement("a");f.href=URL.createObjectURL(h),f.download=`table_${e+1}.csv`,document.body.appendChild(f),f.click(),document.body.removeChild(f),d.stopPropagation(),d.preventDefault()};const a=document.createElement("button");a.innerText="复制json",a.style.background="#059669",a.style.color="#fff",a.style.border="none",a.style.borderRadius="4px",a.style.padding="2px 10px",a.style.cursor="pointer",a.style.fontSize="12px",a.onclick=d=>{const m=S(t,{ignore_cell_img:!0}),p=nt(m),h=JSON.stringify(p);navigator.clipboard.writeText(h).then(()=>{a.innerText="已复制",setTimeout(()=>{a.innerText="复制json"},1200)}),d.stopPropagation(),d.preventDefault()};const u=document.createElement("button");u.innerText="下载excel(高级功能)",u.style.background="#10b981",u.style.color="#fff",u.style.border="none",u.style.borderRadius="4px",u.style.padding="2px 10px",u.style.cursor="pointer",u.style.fontSize="12px",u.onclick=d=>{if(d.stopPropagation(),d.preventDefault(),!t){console.error("表格不存在");return}(async()=>{try{if(!await H()){A.warning("请升级到高级版解锁该功能",{duration:4e3,position:"top-center"});return}const p=[];t.querySelectorAll("tr").forEach(q=>{const B=[];q.querySelectorAll("td, th").forEach(G=>{B.push(G.textContent.trim())}),p.push(B)});const f=D.book_new(),g=D.aoa_to_sheet(p),C=p[0].map((q,B)=>({wch:Math.max(...p.map(P=>(P[B]||"").length))}));g["!cols"]=C,D.book_append_sheet(f,g,"Sheet1");const Y=Q(f,{bookType:"xlsx",type:"array"}),J=new Blob([Y],{type:"application/octet-stream"}),O=URL.createObjectURL(J),j=document.createElement("a");j.href=O,j.download=`table_${e+1}.xlsx`,j.click(),setTimeout(()=>URL.revokeObjectURL(O),100)}catch(m){console.error(m)}})()};const y=document.createElement("button");y.innerText="下载markdown(高级功能)",y.style.background="#64748b",y.style.color="#fff",y.style.border="none",y.style.borderRadius="4px",y.style.padding="2px 10px",y.style.cursor="pointer",y.style.fontSize="12px",y.onclick=d=>{if(d.stopPropagation(),d.preventDefault(),!t){console.error("表格不存在");return}(async()=>{try{if(!await H()){A.warning("请升级到高级版解锁该功能",{duration:4e3,position:"top-center"});return}const p=S(t,{ignore_cell_img:!0});let h="";if(p.length>0){h+="| "+p[0].join(" | ")+` |
`,h+="| "+p[0].map(()=>"---").join(" | ")+` |
`;for(let C=1;C<p.length;C++)h+="| "+p[C].join(" | ")+` |
`}const f=new Blob([h],{type:"text/markdown"}),g=document.createElement("a");g.href=URL.createObjectURL(f),g.download=`table_${e+1}.md`,document.body.appendChild(g),g.click(),document.body.removeChild(g)}catch(m){console.error(m)}})()};const _=document.createElement("button");_.innerText="去编辑",_.style.background="#f43f5e",_.style.color="#fff",_.style.border="none",_.style.borderRadius="4px",_.style.padding="2px 10px",_.style.cursor="pointer",_.style.fontSize="12px",_.onclick=d=>{const m=S(t,{ignore_cell_img:!0}),p=chrome.runtime.getURL("src/ui/editor/index.html"),h=window.open(p,"_blank"),f=setInterval(()=>{h&&h.postMessage&&(h.postMessage({type:"TABLE_DATA",data:m},"*"),clearInterval(f))},300);d.stopPropagation(),d.preventDefault()};const x=document.createElement("button");x.innerText="关闭",x.style.background="#e11d48",x.style.color="#fff",x.style.border="none",x.style.borderRadius="4px",x.style.padding="2px 10px",x.style.cursor="pointer",x.style.fontSize="12px",x.onclick=d=>{var m;(m=n.parentNode)==null||m.removeChild(n),d.stopPropagation(),d.preventDefault()};const E=await Z();E.includes("copy_txt")&&n.appendChild(i),E.includes("copy_csv")&&n.appendChild(l),E.includes("copy_json")&&n.appendChild(a),E.includes("download_txt")&&n.appendChild(c),E.includes("download_csv")&&n.appendChild(s),E.includes("download_excel")&&n.appendChild(u),E.includes("download_markdown")&&n.appendChild(y),(M=t.parentNode)==null||M.insertBefore(n,t)})}function S(o,t){const e=o.cloneNode(!0),r=[],n=e.rows;for(let i=0;i<n.length;i++){const l=[],c=n[i].querySelectorAll("td, th");for(let s=0;s<c.length;s++){let a=F(c[s]).replace(/"/g,'""');a=a.replace(/(\r\n\t|\n|\r\t)/gm," ").trim(),a=a.replace(/^\|+/g,"").replace(/\|+$/g,"").replace(/\|+/g,"|"),t.ignore_cell_img||c[s].querySelectorAll("img").forEach(u=>{a=a+(a.length>0?" ":"")+u.src}),c[s].querySelectorAll("input, textarea").forEach(u=>{a=a+(a.length>0?" ":"")+u.value+" (i)"}),l.push(""+a);for(let u=1;u<c[s].colSpan;u++)l.push("");for(let u=1;u<c[s].rowSpan;u++)n[i+u].insertBefore(document.createElement("td"),n[i+u].children[s])}r.push(l)}return r}function nt(o,t=[]){if(o.length==0)return[];let e=[],r=[];t.length?(e=t,r=o):(e=o[0],r=o.slice(1));const n=[];return r.forEach(i=>{const l={};e.forEach((c,s)=>{l[c]=i[s]}),n.push(l)}),n}function F(o){let t="";return o.childNodes.forEach(e=>{var r;e.nodeType===Node.TEXT_NODE?t+=((r=e.textContent)==null?void 0:r.trim())+"|":e.nodeType===Node.ELEMENT_NODE&&(t+=F(e)+"|")}),t.trim()}function rt(){document.querySelectorAll(`.${N}`).forEach(t=>{var e;(e=t.parentNode)==null||e.removeChild(t)})}class it{constructor(t){w(this,"observer",null);w(this,"started",!1);this.addCopyButtonToTables=t}start(){this.started||(this.started=!0,document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{setTimeout(()=>this.addCopyButtonToTables(),1e3)}):setTimeout(()=>this.addCopyButtonToTables(),1e3),this.observer=new MutationObserver(()=>{this.addCopyButtonToTables()}),this.observer.observe(document.body,{childList:!0,subtree:!0}))}stop(){var t;(t=this.observer)==null||t.disconnect(),this.started=!1}}class st{constructor(){w(this,"highlightBox",null);w(this,"infoBox",null);w(this,"capturing",!1);w(this,"__TC_infobox_tip_id","__TC_infobox_tip");w(this,"onMouseMove",t=>{if(!this.capturing)return;const e=document.elementFromPoint(t.clientX,t.clientY);e&&e.id!=="__TC_infobox"&&this.showHighlight(e)});w(this,"onClick",t=>{t.preventDefault(),t.stopPropagation(),this.stop();const e=document.elementFromPoint(t.clientX,t.clientY);chrome.runtime.sendMessage({action:"set-captured-temporary",data:this.buildCaptureResult(e)})})}start(){this.capturing||(this.capturing=!0,document.addEventListener("mousemove",this.onMouseMove,!0),document.addEventListener("click",this.onClick,!0))}stop(){this.capturing=!1;const t=document.querySelector(`#${this.__TC_infobox_tip_id}`);t&&(t.innerText="（元素已选中，请打开扩展面板，检查是否绑定翻页按钮成功）"),document.removeEventListener("mousemove",this.onMouseMove,!0),document.removeEventListener("click",this.onClick,!0)}clear(){this.removeHighlight()}buildCaptureResult(t){let e="";if(t.id)e=`#${t.id}`;else if(t.className){const i=Array.from(t.classList).map(l=>CSS.escape(l));e=t.tagName.toLowerCase()+"."+i.join(".")}else e=t.tagName.toLowerCase();const n=Array.from(document.querySelectorAll(`${e}`)).indexOf(t);return{flag:!0,selector:e,index:n}}showHighlight(t){var a;let e=this.highlightBox;e||(e=document.createElement("div"),this.highlightBox=e,e.id="__TC_hl_element",e.style.position="fixed",e.style.zIndex="999999",e.style.pointerEvents="none",e.style.border="1px solid #f00",e.style.background="rgba(255,0,0,0.1)",document.body.appendChild(e));const r=t.getBoundingClientRect();e.style.left=r.left+"px",e.style.top=r.top+"px",e.style.width=r.width+"px",e.style.height=r.height+"px";let n=this.infoBox;n||(n=document.createElement("div"),this.infoBox=n,n.id="__TC_infobox",n.style.zIndex="1000000",n.style.background="#f5f6fa",n.style.border="1px dashed #666",n.style.borderRadius="2px",n.style.color="#333",n.style.fontSize="12px",n.style.padding="2px 6px",document.body.appendChild(n));const i=108;r.left;let l=r.bottom+8;l+i>window.innerHeight&&(l=r.top-i-8,l<0&&(l=8));const c=((a=String(t==null?void 0:t.className))==null?void 0:a.replace("__TC_el_captured",""))??"";n.innerHTML=`
  <div>
    <div class="__TC_btn_close" style="position:absolute;right:0;top:5px;width:18px;height:px;cursor:pointer;pointer-events:all;">X</div>
    <h4>元素选择器</h4>
    <div style="pointer-events:all;">
      <b>tag: </b> ${t.tagName.toLowerCase()}<br>
      <b>id: </b> ${t.id||""}<br>
      <b>class: </b> ${c}
      <div id="${this.__TC_infobox_tip_id}" style="color:#fcb700;font-size:12px;margin-top:2px;">
        （点击鼠标以便选中元素）
      </div>
    </div>
  </div>
`,this.showInfoBox(r,n);const s=n.querySelector(".__TC_btn_close");s&&s.addEventListener("click",u=>{u.stopPropagation(),this.removeHighlight()})}showInfoBox(t,e){e.style.visibility="hidden",e.style.position="fixed",e.style.left="0px",e.style.top="0px",e.style.width="200px",document.body.appendChild(e);const r=e.getBoundingClientRect(),n=t,i=e.offsetWidth,l=e.offsetHeight;let c=n.left,s=n.top-r.height-8;c+i>window.innerWidth&&(c=window.innerWidth-i-8),c<0&&(c=8),s<0&&(s=n.bottom+8,s+l>window.innerHeight&&(s=window.innerHeight-l-8)),s+l>window.innerHeight&&(s=n.top-l-8,s<0&&(s=8)),e.style.left=c+"px",e.style.top=s+"px",e.style.visibility="visible"}removeHighlight(){var t,e;(t=this.highlightBox)==null||t.remove(),(e=this.infoBox)==null||e.remove(),this.highlightBox=null,this.infoBox=null,document.body.style.cursor=""}}const v="__TC_el_captured";function lt(o,t=0){if(!o)return!1;console.log("highlightSelectorEl",o,t),document.querySelectorAll(`.${v}`).forEach((r,n)=>{r.classList.remove(v)});const e=document.querySelectorAll(`${o}`);return e&&e.length>t?(console.log("高亮这个元素： ",e[t]),e[t].classList.add(v),!0):!1}function at(o,t=0){console.log("checkSelectorExistEl",o,t);const e=document.querySelectorAll(`${o}`);return!!(e&&e.length>t)}function ct(o,t=0,e=500){if(console.log("reHighlightSelectorEl",o,t),!o)return!1;document.querySelectorAll(`.${v}`).forEach((n,i)=>{n.classList.remove(v)});const r=document.querySelectorAll(`${o}`);return r&&r.length>t?(setTimeout(()=>{console.log("高亮这个元素： ",r[t]),r[t].classList.add(v)},e),!0):!1}function ut(){const o=document.querySelectorAll(`.${v}`);return o.length===0?!1:(o.forEach((t,e)=>{t.classList.remove(v)}),!0)}const $="__TC_table_highlighted";function R(o){let t="";return o.childNodes.forEach(e=>{var r;e.nodeType===Node.TEXT_NODE?t+=((r=e.textContent)==null?void 0:r.trim())+"|":e.nodeType===Node.ELEMENT_NODE&&(t+=R(e)+"|")}),t.trim()}function dt(o,t){const e=o.cloneNode(!0),r=[],n=e.rows;for(let i=0;i<n.length;i++){const l=[],c=n[i].querySelectorAll("td, th");for(let s=0;s<c.length;s++){let a=R(c[s]).replace(/"/g,'""');a=a.replace(/(\r\n\t|\n|\r\t)/gm," ").trim(),a=a.replace(/^\|+/g,"").replace(/\|+$/g,"").replace(/\|+/g,"|"),t.ignore_cell_img||c[s].querySelectorAll("img").forEach(u=>{a=a+(a.length>0?" ":"")+u.src}),c[s].querySelectorAll("input, textarea").forEach(u=>{a=a+(a.length>0?" ":"")+u.value+" (i)"}),l.push(""+a);for(let u=1;u<c[s].colSpan;u++)l.push("");for(let u=1;u<c[s].rowSpan;u++)n[i+u].insertBefore(document.createElement("td"),n[i+u].children[s])}r.push(l)}return r}function pt(o){return window.getComputedStyle(o).display==="none"}function ft(o){let t=o.parentNode;for(;t&&t!==document;){if(window.getComputedStyle(t).display==="none")return!0;t=t.parentNode}return!1}function ht(o){o&&o.scrollIntoView({behavior:"smooth",block:"start"})}const b={success:!1,total_count:0,ok_count:0,data:[],msg:""};let L=[];function mt(o){const t=document.querySelectorAll("table");if(b.success=!0,b.total_count=t.length,b.ok_count=0,t&&t.length){for(let e=0;e<t.length;e++){const r=t[e];if(o.ignore_blank_table&&!(r&&r.rows&&r.rows.length&&Array.from(r.rows).some(l=>Array.from(l.cells).some(c=>(c.textContent||"").trim()!=="")))){console.log("空白表格，就不要显示工具栏了");continue}if(o.ignore_one_row_table&&r.rows.length===1){console.log("只有1行，就不要显示工具栏了");continue}if(o.ignore_display_none_table&&pt(r)){console.log("隐藏的表格，就不要显示工具栏了");continue}if(o.ignore_display_none_contained_table&&ft(r)){console.log("包含隐藏的表格，就不要显示工具栏了");continue}const n=dt(r,o);b.data.push(n),b.ok_count++,L.push(r)}b.msg="ok"}else b.msg="页面中没有发现符合条件的<table>标签"}const gt=(o,t)=>{o&&(t?(L.forEach(e=>{e.classList.remove($)}),o.classList.add($)):o.classList.remove($))},z=new it(I);function yt(o){o&&(typeof o.click=="function"?o.click():o.dispatchEvent(new MouseEvent("click",{view:window,bubbles:!0,cancelable:!0})))}const U=new st;chrome.runtime.onMessage.addListener((o,t,e)=>{if(o.action==="get-all-tables"){const r=o.data||{ignore_cell_img:!0,ignore_blank_table:!0,ignore_one_row_table:!1,ignore_display_none_table:!0,ignore_display_none_contained_table:!0};b.data=[],L=[],mt(r),console.info("------context script: get-all-tables",r,location.href,document.title,window==window.top,b),e(b)}else if(o.action==="scroll-to-table"){const r=o.data;ht(L[r]),e(!0)}else if(o.action==="highlight-table"){const r=o.data,n=o.value;gt(L[r],n),e(!0)}else if(o.action==="click-element"){const r=o.data;if(!r){e({success:!1,msg:"no message.data"});return}const{selector:n,index:i=0}=r;if(!n){e({success:!1,msg:"no data.selector"});return}const l=document.querySelectorAll(n);if(l.length)yt(l==null?void 0:l[i]);else{e({success:!1,msg:"no elements"});return}e({status:"success"})}else if(o.action==="highlight-element"){const{selector:r,index:n}=o.data;r||e({success:!1,msg:"no selector"});const i=lt(r,n);e({success:i,msg:""})}else if(o.action==="check-element-exist"){const{selector:r,index:n}=o.data;r||e({flag:!1,msg:"no selector"}),at(r,n),e({success:!0,msg:""})}else if(o.action==="rehighlight-element"){const{selector:r,index:n,delay:i}=o.data;r||e({success:!1,msg:"no selector"}),ct(r,n,i),e({success:!0,msg:""})}else if(o.action==="unhighlight-elements"){const r=ut();e(r?{success:!0,msg:""}:{success:!1,msg:"no selector"})}else o.action==="start-capture"?(U.start(),e({success:!0})):o.action==="clear-capture"?(U.clear(),e({success:!0})):o.action=="ok"?e({success:!0,msg:"action ok for test"}):o.action==="enable-table-toolbar"?(I(),z.start(),e({success:!0})):o.action==="disable-table-toolbar"?(z.stop(),rt(),e({success:!0})):o.action==="capy-all-tables"?e({success:!0,msg:"action capy-all-tables"}):e({success:!0,msg:"action no match:"+o.action})});chrome.storage.local.get(["options"],o=>{var t;(t=o==null?void 0:o.options)!=null&&t.in_page_show_toolbar_above_table&&I()});chrome.storage.sync.get(["profile"],o=>{var t;(t=o==null?void 0:o.profile)!=null&&t.license});console.debug("tablecopy extension content-script js loaded");
