var e=Object.defineProperty,t=Object.defineProperties,o=Object.getOwnPropertyDescriptors,r=Object.getOwnPropertySymbols,i=Object.prototype.hasOwnProperty,n=Object.prototype.propertyIsEnumerable,s=(t,o,r)=>o in t?e(t,o,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[o]=r,l=(e,t)=>{for(var o in t||(t={}))i.call(t,o)&&s(e,o,t[o]);if(r)for(var o of r(t))n.call(t,o)&&s(e,o,t[o]);return e},a=(e,r)=>t(e,o(r));import{f as c,C as d,S as p,i as h,t as u,U as m}from"./importFormatHelper.b3b79738.js";import{s as g,r as x,c as b,a as f,j as v,b as k,d as y,F as w,C,u as $,P as E,D as S,e as T,f as L,g as I,W as M,h as D,R as j}from"./vendor.6729457a.js";const O=g.div`
  width: calc(100% - 60px);
  height: 40px;
  margin: 4px 10px 4px 50px;
  position: relative;
  display: inline-block;
  border: 1px dashed ${e=>e.theme.color.yallow};
  border-radius: ${e=>e.theme.borderRadius.lg};
  background: ${e=>e.theme.color.scriptItemBoxBg};
  box-sizing: border-box;
  transition: ${e=>e.theme.transitionTime};
  overflow: hidden;

  .mask {
    width: 100%;
    height: 100%;
    background: ${e=>e.theme.color.maskBg};
    opacity: 0;
    position: absolute;
    transition: ${e=>e.theme.transitionTime};
  }

  &:hover {
    border: 1px solid ${e=>e.theme.color.hoverLine};
    box-shadow: 0 0 5px 0 ${e=>x(e.theme.color.hoverLine,.35)};

    .mask {
      opacity: 1;
    }
  }
`,R=g(O)`
  width: calc(100% - 20px);
  margin: 4px 10px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  border-color: ${e=>x(e.theme.color.yallow,.5)};
  margin-bottom: 10px;

  img {
    opacity: 0.3;
    pointer-events: none;
  }

  &:hover {
    border: 1px solid ${e=>x(e.theme.color.hoverLine,.4)};
    box-shadow: 0 0 5px 0 ${e=>x(e.theme.color.hoverLine,.35)};

    img {
      opacity: 1;
    }
  }
`,P=g.label`
  position: absolute;
  display: inline-block;
  width: 34px;
  height: 14px;
  pointer-events: auto;

  .switch-input {
    display:none;
  }
  .slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #8f8f8f;
    transition: .4s;
    box-shadow: 0px 0px 4px rgba(0,0,0,0.15) inset;
  }
  .switch-input:checked + .slider {
    background-color: ${e=>b(.2,f(.35,e.theme.color.red))};
  }
  .switch-input:focus + .slider {
    box-shadow: 0 0 1px ${e=>b(.2,f(.35,e.theme.color.red))};
  }
  .slider:before {
    position: absolute;
    content: "";
    height: 21px;
    width: 21px;
    left: -1px;
    bottom: -3px;
    background-color: white;
    transition: .3s;
    box-shadow: 0px 2px 5px rgba(0,0,0,0.20)
  }
  .slider.round {
    border-radius: 12px;
  }
  .slider.round:before {
    border-radius: 50%;
  }
  .switch-input:checked + .slider:before {
    transform: translateX(15px);
    background-color: ${e=>e.theme.color.red};
  }
`,A=({checked:e,title:t,style:o,onChange:r})=>v(P,{style:o,title:t,children:[k("input",{className:"switch-input",type:"checkbox",checked:e,onChange:r}),k("span",{className:"slider round"})]});A.defaultProps={title:"",style:{}};const z=g.div`
  width: 100%;
  position: relative;
`,N=g.div`
  width: 1px;
  height: 23px;
  background-image: linear-gradient(${e=>e.theme.color.hoverLine} 60%, transparent 0%);
  background-position: right;
  background-size: 1px 5px;
  background-repeat: repeat-y;
  position: absolute;
  left: 50%;
  top: 8px;
`,H=g.div`
  width: 50%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0.35;
  position: absolute;
  cursor: pointer;
  transition: ${e=>e.theme.transitionTime};

  &:nth-child(3) {
    margin-left: 50%;
  }

  &:hover {
    opacity: 1;
  }

  img {
    pointer-events: none;
  }
`,B=g.div`
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;

  img {
    pointer-events: none;
  }
`,F=g.img`
  position: absolute;
  pointer-events: none;
  top: 7px;
  right: 8px;
`,W=g.div`
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  position: absolute;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 35px 0 10px;

  .title {
    width: 100%;
    color: ${e=>e.theme.color.yallow};
    font-size: 14px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: ${e=>e.theme.fontWeight.bold};
  }
`,_=({title:e,code:t,autoExecute:o,scriptIndex:r,onEdit:i,onEmitCode:n,onToggleAutoExecute:s})=>{const l=y.exports.useCallback((()=>{n&&n(r)}),[r,n]),a=y.exports.useCallback((()=>{i&&i(r)}),[r,i]),c=y.exports.useCallback((()=>{s&&s(r)}),[r,s]),d=y.exports.useMemo((()=>v(w,{children:[k(N,{}),k(H,{onClick:l,children:k("img",{alt:"",src:"../imgs/play.svg"})}),k(H,{onClick:a,children:k("img",{alt:"",src:"../imgs/settings.svg"})})]})),[l,a]),p=y.exports.useMemo((()=>k(w,{children:k(B,{onClick:a,children:k("img",{alt:"",src:"../imgs/settings.svg"})})})),[a]);return v(z,{children:[k(A,{title:"Auto Execute",style:{left:8,top:17},checked:o,onChange:c}),v(O,{title:e,children:[k(F,{alt:"",src:t?"../imgs/code.svg":"../imgs/no-code.svg"}),k(W,{children:k("div",{className:"title",children:e})}),k("div",{className:"mask",children:t?d:p})]})]})};var q=g.section`
  width: 100%;
  position: absolute;
  display: block;
  background-color: ${e=>e.theme.color.bg};
  top: 0;
  left: 0;
  height: calc(100vh - 31px);
  box-sizing: border-box;
  outline: none;

  ${e=>e.$list&&C`
    overflow-y: auto;
    user-select: none;
    padding-top: 5px;
  `}

  ${e=>e.$editor&&C`
    padding: 10px;
  `}
`;const G=g.div`
  pointer-events: none;
  position: fixed;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  z-index: 100;
  background-color: ${e=>e.theme.dropMask.bg};

  .drop-mask-line {
    width: calc(100% - 40px);
    height: calc(100% - 40px);
    display: flex;
    border: 3px dashed ${e=>e.theme.color.yallow};
    justify-content: center;
    align-items: center;
    border-radius: 20px;
  }
`,K=g.div`
  & > div {
    display: flex;
  }
`,U=({scripts:e,scrollTop:t,setListScrollTop:o,onMoveSort:r,onEdit:i,onEmitCode:n,onToggleAutoExecute:s,onImportScripts:d,onAdd:p})=>{const h=y.exports.useRef(null);y.exports.useLayoutEffect((()=>(h.current&&(h.current.scrollTop=t),()=>{const{current:e}=h;e&&o(e.scrollTop)})),[h,t,o]);const u=y.exports.useCallback((async e=>{const t=await c(e);d(t)}),[d]),{getRootProps:m,isDragActive:g}=$({onDrop:u}),x=y.exports.useCallback((e=>{if(e.destination){const t=e.source.index,o=e.destination.index;r(t,o)}}),[r]),b=y.exports.useMemo((()=>g?k(G,{children:k("div",{className:"drop-mask-line",children:k("img",{width:"80",height:"80",alt:"",src:"../imgs/drop.svg"})})}):k(w,{})),[g]),f=y.exports.useMemo((()=>e.map(((e,t)=>k(E,{draggableId:`script_${t}`,index:t,children:o=>k("div",a(l(l({ref:o.innerRef},o.draggableProps),o.dragHandleProps),{children:k(_,{title:e.title,code:e.code,autoExecute:e.autoExecute,scriptIndex:t,onEdit:i,onEmitCode:n,onToggleAutoExecute:s},t)}))},`${e.title}_${t}`)))),[e,i,n,s]);return v(q,a(l({$list:!0},m()),{ref:h,children:[k(S,{onDragEnd:x,children:k(T,{droppableId:"droppable",children:e=>v(K,a(l({ref:e.innerRef},e.droppableProps),{children:[f,e.placeholder]}))})}),k(R,{onClick:p,children:k("img",{alt:"add",src:"../imgs/add.svg"})},"add"),b]}))};var X=g.input`
  background: ${e=>e.theme.input.bg};
  border: 1px solid ${e=>e.theme.color.line};
  box-shadow: ${e=>e.theme.boxShadow};
  border-radius: ${e=>e.theme.borderRadius.lg};
  outline: none;
  display: block;
  width: 100%;
  padding: 0 6px;
`;const J=g.button`
  margin-left: 8px;
  width: 60px;
  height: 26px;
  border-radius: ${e=>e.theme.borderRadius.sm};
  background-color: ${e=>e.theme.button.bg};
  outline: none;
  cursor: pointer;
  font-weight: ${e=>e.theme.fontWeight.normal};
  font-size: 14px;
  transition: ${e=>e.theme.transitionTime};

  ${e=>e.red&&C`
    border: 1px solid ${e.theme.button.red};
    color: ${e.theme.button.red};

    &:hover {
      background-color: ${e.theme.button.red};
      color: white;
    }
  `}

  ${e=>e.gray&&C`
    border: 1px solid ${e.theme.button.gray};
    color: ${e.theme.button.gray};

    &:hover {
      background-color: ${e.theme.button.gray};
      color: white;
    }
  `}
`,Q=g(J)`
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  background: transparent;
  fill: ${e=>e.theme.button.fill};
  margin-left: 4px;

  svg {
    vertical-align: middle;
    ${e=>e.scale&&C`
      transform: scale(${e.scale});
    `};
  }

  &:hover {
    fill: ${e=>e.hoverColor?e.hoverColor:e.theme.color.yallow};
  }
`,V={lineNumbers:!1,mode:"javascript",theme:"neo"},Y=g(X)`
  width: calc(100% - 246px);
  height: 26px;
  margin-bottom: 8px;
  display: inline-block;
  color: ${e=>e.theme.color.yallow};
  border: 1px dashed ${e=>e.theme.color.hoverLine};
  font-weight: ${e=>e.theme.fontWeight.bold};
  font-size: 14px;

  &::placeholder {
    font-weight: ${e=>e.theme.fontWeight.normal};
    color:rgba(80, 80, 80, 0.35);
  }
`,Z=g.div`
  right: 10px;
  position: absolute;
  display: inline-flex;
`,ee=g(L)`
  width: 100%;
  height: calc(100% - 36px);

  .CodeMirror-vscrollbar,
  .CodeMirror-hscrollbar {
    outline: none;
  }

  .CodeMirror {
    height: 100%;
    box-shadow: ${e=>e.theme.boxShadow};
    border-radius: ${e=>e.theme.borderRadius.lg};
    padding: 0 ${e=>e.fullscreen?0:6}px;
    border: 1px dashed ${e=>e.theme.color.hoverLine};
  }
  .CodeMirror-focused .CodeMirror-selected,
  .CodeMirror-line::selection,
  .CodeMirror-line > span::selection,
  .CodeMirror-line > span > span::selection {
    background: ${e=>e.theme.color.selection} !important;
  }
`,te=({scriptData:e,dark:t,onSave:o,onDel:r,onCancel:i})=>{const[n,s]=y.exports.useState(e&&e.title||""),[c,p]=y.exports.useState(e&&e.code||""),[h,u]=y.exports.useState(!1),[m,g]=y.exports.useState(a(l({},V),{theme:t?"mbo":"neo"})),x=y.exports.useCallback((()=>{const t={title:n?n.trim():"",code:c?c.trim():"",autoExecute:(null==e?void 0:e.autoExecute)||!1};o&&o(t)}),[e,n,c,o]),b=y.exports.useCallback((()=>{s(""),p(""),r&&r()}),[r]),f=y.exports.useCallback((()=>{p(I.exports.js(c,{indent_size:2}))}),[c]),w=y.exports.useCallback((()=>{u(!h),g(a(l({},m),{lineNumbers:!h}))}),[h,m]),C=y.exports.useCallback((e=>{s(e.target.value||"")}),[]),$=y.exports.useCallback(((e,t,o)=>{p(o)}),[]);return y.exports.useEffect((()=>{const[e,t]=[800,600];return h?(document.body.style.width=`${e}px`,document.body.style.height=`${t}px`,null===document.fullscreenElement&&document.documentElement.requestFullscreen()):(null!==document.fullscreenElement&&document.exitFullscreen(),document.body.removeAttribute("style")),()=>{null!==document.fullscreenElement&&document.exitFullscreen(),document.body.removeAttribute("style")}}),[h]),v(q,{$editor:!0,children:[k(Y,{type:"text",maxLength:100,placeholder:"Please enter a script title",value:n,onChange:C,autoFocus:!0}),v(Z,{children:[k(Q,{type:"button",hoverColor:d.LIGHT_RED,title:"delete",onClick:b,children:k("svg",{width:"24px",height:"24px",children:k("use",{xlinkHref:"../imgs/icons.svg#del"})})}),k(Q,{type:"button",title:"format",onClick:f,children:k("svg",{width:"24px",height:"24px",children:k("use",{xlinkHref:"../imgs/icons.svg#format"})})}),k(Q,{scale:.9,type:"button",title:h?"exit fullscreen":"fullscreen",onClick:w,children:k("svg",{width:"24px",height:"24px",children:k("use",{xlinkHref:"../imgs/icons.svg#"+(h?"close_fullscreen":"fullscreen")})})}),k(J,{type:"button",red:!0,onClick:x,children:"Save"}),k(J,{type:"button",gray:!0,onClick:i,children:"Cancel"})]}),k(ee,{value:c,fullscreen:h,onBeforeChange:$,options:m})]})};te.defaultProps={scriptData:void 0,dark:!1};var oe,re,ie=M`
  .CodeMirror {
    &.cm-s-neo {
      .CodeMirror-cursor {
        width: 1px;
        background: rgba(155,157,162,0.8);
      }
      .CodeMirror-linenumber {
        color: #bdbebf;
      }
    }
  }
`;(re=oe||(oe={})).LIST="LIST",re.EDITOR="EDITOR";const ne=({scripts:e,dark:t,onSave:o,onEmitCode:r})=>{const[i,n]=y.exports.useState(0),[s]=y.exports.useState(t?p.DARK:p.LIGHT),[l,a]=y.exports.useState(e||[]),[c,d]=y.exports.useState(oe.LIST),[m,g]=y.exports.useState(void 0),x=y.exports.useCallback((e=>{d(oe.EDITOR),g(e)}),[]),b=y.exports.useCallback((e=>void 0===e?void 0:l[e]),[l]),f=y.exports.useCallback((e=>{if(!r)return;const t=b(e);t&&r(t)}),[b,r]),w=y.exports.useCallback((e=>{a(e),o&&o(e),d(oe.LIST),g(void 0)}),[o]),C=y.exports.useCallback((e=>{const t=[...l];t[e].autoExecute=!t[e].autoExecute,w(t)}),[l,w]),$=y.exports.useCallback((e=>{if(!Array.isArray(e))return;const t=h(e);w(t)}),[w]),E=y.exports.useCallback((()=>{d(oe.LIST),g(void 0)}),[]),S=y.exports.useCallback((()=>{if(void 0===m)return;let e=[...l];e.splice(m,1),e=e.filter((e=>e)),w(e)}),[l,m,w]),T=y.exports.useCallback((e=>{if(void 0===m)return;let t=[...l];t[m]=e,t=t.filter((e=>e)),w(t)}),[l,m,w]),L=y.exports.useCallback((()=>{d(oe.EDITOR),g(l.length)}),[l]),I=y.exports.useCallback(((e,t)=>{const o=[...l],[r]=o.splice(e,1);o.splice(t,0,r),w(o)}),[l,w]),M=c===oe.LIST?k(U,{scripts:l,scrollTop:i,setListScrollTop:n,onMoveSort:I,onEdit:x,onEmitCode:f,onImportScripts:$,onAdd:L,onToggleAutoExecute:C}):k(te,{dark:t,onSave:T,onDel:S,onCancel:E,scriptData:b(m)});return v(D,{theme:u[s],children:[k(ie,{}),M]})};ne.defaultProps={scripts:[],dark:!1};let se={dark:!0,notice:!1};const le=e=>{chrome.storage&&chrome.storage.local.set({scripts:e})},ae=e=>{chrome.tabs&&chrome.tabs.query({active:!0,currentWindow:!0},(t=>{const{id:o}=t[0];void 0!==o&&chrome.tabs.sendMessage(o,{type:m.EMIT_CODE,code:e.code},(t=>{chrome.runtime.lastError&&console.log("lastError:",chrome.runtime.lastError),"ok"===t&&se.notice&&new Notification(`Execute Script: ${e.title}`,{icon:"../icon48.png"})}))}))};function ce(e){const{scripts:t}=e;j.render(k(ne,{scripts:t,dark:se.dark,onSave:le,onEmitCode:ae}),document.getElementById("root"))}chrome.storage?chrome.storage.local.get(["scripts","setting"],(e=>{const{setting:t}=e;t&&(se=l(l({},se),t)),se&&se.dark&&document.documentElement.classList.add("dark");const o=()=>{document.removeEventListener("DOMContentLoaded",o,!1),ce(e)};document.getElementById("root")?ce(e):document.addEventListener("DOMContentLoaded",o,!1)})):ce({scripts:[],setting:se});
