var J=Object.defineProperty;var G=(o,t,e)=>t in o?J(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var x=(o,t,e)=>G(o,typeof t!="symbol"?t+"":t,e);import{u as j,w as V}from"./xlsx-ejz-vvm2.js";class U{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 n={...this.defaultOptions,...e};this.cleanup();const r=document.createElement("div");if(r.className=`simple-toast simple-toast-${n.type}`,r.textContent=t,n.showProgress){const i=document.createElement("div");i.className="simple-toast-progress",i.style.animationDuration=`${n.duration}ms`,r.appendChild(i)}return this.container.appendChild(r),this.toasts.add(r),n.duration>0&&setTimeout(()=>{this.remove(r)},n.duration),n.clickToClose&&r.addEventListener("click",()=>this.remove(r)),{element:r,remove:()=>this.remove(r),updateMessage:i=>{r.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 U),k}const N={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 U(o),config:o=>{const t=T();Object.assign(t.defaultOptions,o),o.position&&t.updatePosition(o.position)}};async function P(){var o;try{const t=await new Promise((e,n)=>{chrome.storage.sync.get(["profile"],r=>{chrome.runtime.lastError?n(chrome.runtime.lastError):e(r)})});return!!((o=t==null?void 0:t.profile)!=null&&o.license)}catch{return N.error("检查许可证失败",{duration:3e3}),!1}}async function K(){var o;try{const t=await new Promise((n,r)=>{chrome.storage.local.get(["options"],i=>{chrome.runtime.lastError?r(chrome.runtime.lastError):n(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,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 N.error("获取配置失败",{duration:3e3}),!1}}async function Q(){let o=await K();return o==null?void 0:o.in_page_buttons}const B="__tc_copy_btn_wrap";function Z(o,t){if(!o)return;let e=o.previousElementSibling,n=null,r=0;for(;e;){const i=e;e=i.previousElementSibling,i.tagName.toLowerCase()==="div"&&i.classList.contains(t)&&(n?(i.remove(),r++):n=i)}return r>0&&console.log(`删除了 ${r} 个重复的table-bar`),n}function D(){document.querySelectorAll("table").forEach(async(t,e)=>{var $;if(t.previousElementSibling&&t.previousElementSibling.classList.contains(B)){Z(t,B);return}if(t.rows.length===1||t.rows.length>1&&t.rows[1].innerText.trim()=="")return;const n=document.createElement("div");n.className=B,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 r=document.createElement("button");r.innerText="复制txt",r.style.background="#2563eb",r.style.color="#fff",r.style.border="none",r.style.borderRadius="4px",r.style.padding="2px 10px",r.style.cursor="pointer",r.style.fontSize="12px",r.onclick=d=>{const p=C(t,{ignore_cell_img:!0}).map(h=>h.join("	")).join(`
`);navigator.clipboard.writeText(p).then(()=>{r.innerText="已复制",setTimeout(()=>{r.innerText="复制txt"},1200)}),d.stopPropagation(),d.preventDefault()};const i=document.createElement("button");i.innerText="复制csv",i.style.background="#059669",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=C(t,{ignore_cell_img:!0}).map(h=>h.map(f=>`"${f.replace(/"/g,'""')}"`).join(",")).join(`
`);navigator.clipboard.writeText(p).then(()=>{i.innerText="已复制",setTimeout(()=>{i.innerText="复制csv"},1200)}),d.stopPropagation(),d.preventDefault()};const l=document.createElement("button");l.innerText="下载txt",l.style.background="#6366f1",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=C(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 u=document.createElement("button");u.innerText="下载csv",u.style.background="#f59e42",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=>{const p=C(t,{ignore_cell_img:!0}).map(g=>g.map(E=>`"${E.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 s=document.createElement("button");s.innerText="复制json",s.style.background="#059669",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 m=C(t,{ignore_cell_img:!0}),p=tt(m),h=JSON.stringify(p);navigator.clipboard.writeText(h).then(()=>{s.innerText="已复制",setTimeout(()=>{s.innerText="复制json"},1200)}),d.stopPropagation(),d.preventDefault()};const c=document.createElement("button");c.innerText="下载excel(高级功能)",c.style.background="#10b981",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=>{if(d.stopPropagation(),d.preventDefault(),!t){console.error("表格不存在");return}(async()=>{try{if(!await P()){N.warning("请升级到高级版解锁该功能",{duration:4e3,position:"top-center"});return}const p=[];t.querySelectorAll("tr").forEach(O=>{const L=[];O.querySelectorAll("td, th").forEach(Y=>{L.push(Y.textContent.trim())}),p.push(L)});const f=j.book_new(),g=j.aoa_to_sheet(p),E=p[0].map((O,L)=>({wch:Math.max(...p.map(q=>(q[L]||"").length))}));g["!cols"]=E,j.book_append_sheet(f,g,"Sheet1");const F=V(f,{bookType:"xlsx",type:"array"}),R=new Blob([F],{type:"application/octet-stream"}),M=URL.createObjectURL(R),A=document.createElement("a");A.href=M,A.download=`table_${e+1}.xlsx`,A.click(),setTimeout(()=>URL.revokeObjectURL(M),100)}catch(m){console.error(m)}})()};const a=document.createElement("button");a.innerText="下载markdown(高级功能)",a.style.background="#64748b",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=>{if(d.stopPropagation(),d.preventDefault(),!t){console.error("表格不存在");return}(async()=>{try{if(!await P()){N.warning("请升级到高级版解锁该功能",{duration:4e3,position:"top-center"});return}const p=C(t,{ignore_cell_img:!0});let h="";if(p.length>0){h+="| "+p[0].join(" | ")+` |
`,h+="| "+p[0].map(()=>"---").join(" | ")+` |
`;for(let E=1;E<p.length;E++)h+="| "+p[E].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 y=document.createElement("button");y.innerText="去编辑",y.style.background="#f43f5e",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=>{const m=C(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 b=document.createElement("button");b.innerText="关闭",b.style.background="#e11d48",b.style.color="#fff",b.style.border="none",b.style.borderRadius="4px",b.style.padding="2px 10px",b.style.cursor="pointer",b.style.fontSize="12px",b.onclick=d=>{var m;(m=n.parentNode)==null||m.removeChild(n),d.stopPropagation(),d.preventDefault()};const v=await Q();v.includes("copy_txt")&&n.appendChild(r),v.includes("copy_csv")&&n.appendChild(i),v.includes("copy_json")&&n.appendChild(s),v.includes("download_txt")&&n.appendChild(l),v.includes("download_csv")&&n.appendChild(u),v.includes("download_excel")&&n.appendChild(c),v.includes("download_markdown")&&n.appendChild(a),($=t.parentNode)==null||$.insertBefore(n,t)})}function C(o,t){const e=o.cloneNode(!0),n=[],r=e.rows;for(let i=0;i<r.length;i++){const l=[],u=r[i].querySelectorAll("td, th");for(let s=0;s<u.length;s++){let c=W(u[s]).replace(/"/g,'""');c=c.replace(/(\r\n\t|\n|\r\t)/gm," ").trim(),c=c.replace(/^\|+/g,"").replace(/\|+$/g,"").replace(/\|+/g,"|"),t.ignore_cell_img||u[s].querySelectorAll("img").forEach(a=>{c=c+(c.length>0?" ":"")+a.src}),u[s].querySelectorAll("input, textarea").forEach(a=>{c=c+(c.length>0?" ":"")+a.value+" (i)"}),l.push(""+c);for(let a=1;a<u[s].colSpan;a++)l.push("");for(let a=1;a<u[s].rowSpan;a++)r[i+a].insertBefore(document.createElement("td"),r[i+a].children[s])}n.push(l)}return n}function tt(o,t=[]){if(o.length==0)return[];let e=[],n=[];t.length?(e=t,n=o):(e=o[0],n=o.slice(1));const r=[];return n.forEach(i=>{const l={};e.forEach((u,s)=>{l[u]=i[s]}),r.push(l)}),r}function W(o){let t="";return o.childNodes.forEach(e=>{var n;e.nodeType===Node.TEXT_NODE?t+=((n=e.textContent)==null?void 0:n.trim())+"|":e.nodeType===Node.ELEMENT_NODE&&(t+=W(e)+"|")}),t.trim()}function et(){document.querySelectorAll(`.${B}`).forEach(t=>{var e;(e=t.parentNode)==null||e.removeChild(t)})}class ot{constructor(t){x(this,"observer",null);x(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 nt{constructor(){x(this,"highlightBox",null);x(this,"infoBox",null);x(this,"capturing",!1);x(this,"__TC_infobox_tip_id","__TC_infobox_tip");x(this,"onMouseMove",t=>{if(!this.capturing)return;const e=document.elementFromPoint(t.clientX,t.clientY);e&&e.id!=="__TC_infobox"&&this.showHighlight(e)});x(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 r=Array.from(document.querySelectorAll(`${e}`)).indexOf(t);return{flag:!0,selector:e,index:r}}showHighlight(t){var c;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 n=t.getBoundingClientRect();e.style.left=n.left+"px",e.style.top=n.top+"px",e.style.width=n.width+"px",e.style.height=n.height+"px";let r=this.infoBox;r||(r=document.createElement("div"),this.infoBox=r,r.id="__TC_infobox",r.style.zIndex="1000000",r.style.background="#f5f6fa",r.style.border="1px dashed #666",r.style.borderRadius="2px",r.style.color="#333",r.style.fontSize="12px",r.style.padding="2px 6px",document.body.appendChild(r));const i=108;n.left;let l=n.bottom+8;l+i>window.innerHeight&&(l=n.top-i-8,l<0&&(l=8));const u=((c=String(t==null?void 0:t.className))==null?void 0:c.replace("__TC_el_captured",""))??"";r.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> ${u}
      <div id="${this.__TC_infobox_tip_id}" style="color:#fcb700;font-size:12px;margin-top:2px;">
        （点击鼠标以便选中元素）
      </div>
    </div>
  </div>
`,this.showInfoBox(n,r);const s=r.querySelector(".__TC_btn_close");s&&s.addEventListener("click",a=>{a.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 n=e.getBoundingClientRect(),r=t,i=e.offsetWidth,l=e.offsetHeight;let u=r.left,s=r.top-n.height-8;u+i>window.innerWidth&&(u=window.innerWidth-i-8),u<0&&(u=8),s<0&&(s=r.bottom+8,s+l>window.innerHeight&&(s=window.innerHeight-l-8)),s+l>window.innerHeight&&(s=r.top-l-8,s<0&&(s=8)),e.style.left=u+"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 w="__TC_el_captured";function rt(o,t=0){if(!o)return!1;console.log("highlightSelectorEl",o,t),document.querySelectorAll(`.${w}`).forEach((n,r)=>{n.classList.remove(w)});const e=document.querySelectorAll(`${o}`);return e&&e.length>t?(console.log("高亮这个元素： ",e[t]),e[t].classList.add(w),!0):!1}function it(o,t=0){console.log("checkSelectorExistEl",o,t);const e=document.querySelectorAll(`${o}`);return!!(e&&e.length>t)}function st(o,t=0,e=500){if(console.log("reHighlightSelectorEl",o,t),!o)return!1;document.querySelectorAll(`.${w}`).forEach((r,i)=>{r.classList.remove(w)});const n=document.querySelectorAll(`${o}`);return n&&n.length>t?(setTimeout(()=>{console.log("高亮这个元素： ",n[t]),n[t].classList.add(w)},e),!0):!1}function lt(){const o=document.querySelectorAll(`.${w}`);return o.length===0?!1:(o.forEach((t,e)=>{t.classList.remove(w)}),!0)}const I="__TC_table_highlighted";function X(o){let t="";return o.childNodes.forEach(e=>{var n;e.nodeType===Node.TEXT_NODE?t+=((n=e.textContent)==null?void 0:n.trim())+"|":e.nodeType===Node.ELEMENT_NODE&&(t+=X(e)+"|")}),t.trim()}function ct(o,t){const e=o.cloneNode(!0),n=[],r=e.rows;for(let i=0;i<r.length;i++){const l=[],u=r[i].querySelectorAll("td, th");for(let s=0;s<u.length;s++){let c=X(u[s]).replace(/"/g,'""');c=c.replace(/(\r\n\t|\n|\r\t)/gm," ").trim(),c=c.replace(/^\|+/g,"").replace(/\|+$/g,"").replace(/\|+/g,"|"),t.ignore_cell_img||u[s].querySelectorAll("img").forEach(a=>{c=c+(c.length>0?" ":"")+a.src}),u[s].querySelectorAll("input, textarea").forEach(a=>{c=c+(c.length>0?" ":"")+a.value+" (i)"}),l.push(""+c);for(let a=1;a<u[s].colSpan;a++)l.push("");for(let a=1;a<u[s].rowSpan;a++)r[i+a].insertBefore(document.createElement("td"),r[i+a].children[s])}n.push(l)}return n}function at(o){return window.getComputedStyle(o).display==="none"}function ut(o){let t=o.parentNode;for(;t&&t!==document;){if(window.getComputedStyle(t).display==="none")return!0;t=t.parentNode}return!1}function dt(o){o&&o.scrollIntoView({behavior:"smooth",block:"start"})}const _={success:!1,total_count:0,ok_count:0,data:[],msg:""};let S=[];function pt(o){const t=document.querySelectorAll("table");if(_.success=!0,_.total_count=t.length,_.ok_count=0,t&&t.length){for(let e=0;e<t.length;e++){const n=t[e];if(n.rows.length!==1&&!(n.rows.length>1&&n.rows[1].innerText.trim()=="")&&!at(n)&&!ut(n)){const r=ct(n,o);_.data.push(r),_.ok_count++,S.push(n)}}_.msg="ok"}else _.msg="页面中没有发现符合条件的<table>标签"}const ft=(o,t)=>{o&&(t?(S.forEach(e=>{e.classList.remove(I)}),o.classList.add(I)):o.classList.remove(I))},H=new ot(D);function ht(o){o&&(typeof o.click=="function"?o.click():o.dispatchEvent(new MouseEvent("click",{view:window,bubbles:!0,cancelable:!0})))}const z=new nt;chrome.runtime.onMessage.addListener((o,t,e)=>{if(o.action==="get-all-tables"){const n=o.data||{ignore_cell_img:!0};_.data=[],S=[],pt(n),e(_)}else if(o.action==="scroll-to-table"){const n=o.data;dt(S[n]),e(!0)}else if(o.action==="highlight-table"){const n=o.data,r=o.value;ft(S[n],r),e(!0)}else if(o.action==="click-element"){const n=o.data;if(!n){e({success:!1,msg:"no message.data"});return}const{selector:r,index:i=0}=n;if(!r){e({success:!1,msg:"no data.selector"});return}const l=document.querySelectorAll(r);if(l.length)ht(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:n,index:r}=o.data;n||e({success:!1,msg:"no selector"});const i=rt(n,r);e({success:i,msg:""})}else if(o.action==="check-element-exist"){const{selector:n,index:r}=o.data;n||e({flag:!1,msg:"no selector"}),it(n,r),e({success:!0,msg:""})}else if(o.action==="rehighlight-element"){const{selector:n,index:r,delay:i}=o.data;n||e({success:!1,msg:"no selector"}),st(n,r,i),e({success:!0,msg:""})}else if(o.action==="unhighlight-elements"){const n=lt();e(n?{success:!0,msg:""}:{success:!1,msg:"no selector"})}else o.action==="start-capture"?(z.start(),e({success:!0})):o.action==="clear-capture"?(z.clear(),e({success:!0})):o.action=="ok"?e({success:!0,msg:"action ok for test"}):o.action==="enable-table-toolbar"?(D(),H.start(),e({success:!0})):o.action==="disable-table-toolbar"?(H.stop(),et(),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&&D()});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");
