(()=>{"use strict";var e={322:(e,o,t)=>{t.d(o,{W:()=>s});var n=t(454),i=t(782),r=function(e,o,t,n){return new(t||(t=Promise))((function(i,r){function s(e){try{l(n.next(e))}catch(e){r(e)}}function d(e){try{l(n.throw(e))}catch(e){r(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof t?o:new t((function(e){e(o)}))).then(s,d)}l((n=n.apply(e,o||[])).next())}))};function s(){var e;return r(this,void 0,void 0,(function*(){(0,i.ig)();const o=document.querySelector("#omnivore-extension-root");if(!o||!o.shadowRoot)return void console.log("no statusBox to update");let t=yield(0,n.$)("labels").then((e=>{if(e&&e.length>0)return e}));(0,i.jC)("#omnivore-edit-labels-row"),null===(e=o.shadowRoot.querySelector("#omnivore-edit-label-input"))||void 0===e||e.focus();const r=o.shadowRoot.querySelector("#omnivore-edit-labels-list");if(!t)return console.error("No labels found, trying to update the cache."),void chrome.runtime.sendMessage({action:"enqueueTask",task:"updateLabelCache",clientRequestId:(0,i.mm)()});r&&(r.innerHTML="",t.sort(((e,o)=>e.name.localeCompare(o.name,void 0,{sensitivity:"base"}))).forEach((function(e,o){const t=function(e){const o=document.createElement("button"),t=document.createElement("span");t.style="width:10px;height:10px;border-radius:1000px;",t.style.setProperty("background-color",e.color);const n=document.createElement("span");n.style="margin-left: 10px;pointer-events: none;",n.innerText=e.name;const i=document.createElement("span");return i.style="margin-left: auto;pointer-events: none;",i.className="checkbox",i.innerHTML='\n \n ',o.appendChild(t),o.appendChild(n),o.appendChild(i),o.onclick=d,o.setAttribute("data-label-id",e.id),o.setAttribute("data-label-selected",e.selected?"on":"off"),o.setAttribute("tabIndex","-1"),o}(e);r.appendChild(t)})))}))}function d(e){var o;e.preventDefault();const t=null===(o=e.target)||void 0===o?void 0:o.getAttribute("data-label-id");t&&function(e,o){var t,s;r(this,void 0,void 0,(function*(){const r=null===(t=e.target)||void 0===t?void 0:t.getAttribute("data-label-selected");if(!o||!r)return;const d="on"!=r;null===(s=e.target)||void 0===s||s.setAttribute("data-label-selected",d?"on":"off");let l=yield(0,n.$)("labels").then((e=>{if(e&&e.length>0)return e}));if(!l)throw Error("No labels selected");l.find((e=>e.id===o))&&function(){var e;(0,i.PC)("#omnivore-edit-labels-status","waiting","Updating Labels...",void 0);const o=document.querySelector("#omnivore-extension-root"),t=null===(e=null==o?void 0:o.shadowRoot)||void 0===e?void 0:e.querySelector("#omnivore-edit-labels-list");if(t){const e=[...t.children].filter((e=>"on"===e.getAttribute("data-label-selected"))).map((e=>e.getAttribute("data-label-id")));chrome.runtime.sendMessage({action:"enqueueTask",task:"setLabels",clientRequestId:(0,i.mm)(),labels:e})}}()}))}(e,t)}},782:(e,o,t)=>{t.d(o,{Dz:()=>l,Jw:()=>m,PC:()=>f,Wj:()=>c,ig:()=>a,jC:()=>h,ll:()=>d,mm:()=>p});var n=t(454),i=t(322),r=function(e,o,t,n){return new(t||(t=Promise))((function(i,r){function s(e){try{l(n.next(e))}catch(e){r(e)}}function d(e){try{l(n.throw(e))}catch(e){r(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof t?o:new t((function(e){e(o)}))).then(s,d)}l((n=n.apply(e,o||[])).next())}))};const s={waiting:'
',success:'\n ',failure:'\n \n '},d=e=>r(void 0,void 0,void 0,(function*(){var o;let t=null!==(o=document.querySelector("#omnivore-extension-root"))&&void 0!==o?o:void 0;document.body&&(console.log("existing currentToastEl: ",t),t||(t=yield r(void 0,void 0,void 0,(function*(){console.log("===== CREATING TOAST CONTAINER ===== ");const e=yield fetch(chrome.runtime.getURL("views/toast.html")),o=yield e.text(),t=document.createElement("div");if(t.tabIndex=0,t.id="omnivore-extension-root",t.attachShadow({mode:"open"}),t.style.opacity="1.0",!t.shadowRoot)return void alert("Error opening Omnivore user interface.");t.shadowRoot.innerHTML="";const n=document.createElement("div");return n.id="#omnivore-toast",n.innerHTML=o,n.tabIndex=0,t.shadowRoot.appendChild(n),document.body.appendChild(t),u(t),l("waiting"),t}))),(yield(0,n.$)("disableAutoDismiss"))&&(null==t||t.setAttribute("data-disable-auto-dismiss","true")),null==t||t.setAttribute("data-omnivore-client-request-id",e),null==t||t.focus({preventScroll:!0}),l("waiting"))})),l=(e,o=void 0)=>r(void 0,void 0,void 0,(function*(){var t;const n=document.querySelector("#omnivore-extension-root"),i=null===(t=null==n?void 0:n.shadowRoot)||void 0===t?void 0:t.querySelector(".omnivore-toast-statusBox");if(console.log("updating",e,i),i)switch(e){case"success":i.innerHTML=s.success;break;case"failure":i.innerHTML=s.failure;break;case"waiting":i.innerHTML=s.waiting}o&&("addNote"==o&&"failure"==e&&f("#omnivore-add-note-status","failure","Error adding note...",void 0),"addNote"==o&&"success"==e&&(f("#omnivore-add-note-status","success","Note updated.",2500),setTimeout((()=>{h("#omnivore-add-note-status")}),3e3)),"setLabels"==o&&"success"==e&&f("#omnivore-edit-labels-status","success","Labels Updated",2500),"setLabels"==o&&"failure"==e&&f("#omnivore-edit-labels-status","failure","Error Updating Labels...",2500),"editTitle"==o&&"failure"==e&&f("#omnivore-add-note-status","failure","Error updating title...",void 0),"editTitle"==o&&"success"==e&&(f("omnivore-edit-title-status","success","Title updated.",2500),setTimeout((()=>{h("#omnivore-edit-title-status")}),3e3)),"archive"==o&&(f("#omnivore-extra-status",e,"success"==e?"Success":"Error","success"==e?2500:void 0),"success"==e&&q()))})),a=()=>{const e=document.querySelector("#omnivore-extension-root");e&&e.setAttribute("data-disable-auto-dismiss","true")},c=e=>r(void 0,void 0,void 0,(function*(){e.status&&l(e.status);const o=yield r(void 0,void 0,void 0,(function*(){var e;const o=null!==(e=yield(0,n.$)("autoDismissTime"))&&void 0!==e?e:"2500";return Number.isNaN(Number(o))?2500:Number(o)}));setTimeout((()=>{const e=document.querySelector("#omnivore-extension-root");e&&!e.getAttribute("data-disable-auto-dismiss")&&(e.style.transition="opacity 3.5s ease;",e.style.opacity="0",setTimeout((()=>{const e=document.querySelector("#omnivore-extension-root");e&&!e.getAttribute("data-disable-auto-dismiss")&&e.remove()}),500))}),o)})),u=e=>{var o,t,n;const r=[{id:"#omnivore-toast-add-note-btn",func:w},{id:"#omnivore-toast-edit-title-btn",func:v},{id:"#omnivore-toast-edit-labels-btn",func:i.W},{id:"#omnivore-toast-read-now-btn",func:L},{id:"#omnivore-open-menu-btn",func:y},{id:"#omnivore-toast-close-btn",func:R},{id:"#omnivore-toast-login-btn",func:b},{id:"#omnivore-toast-archive-btn",func:x},{id:"#omnivore-toast-delete-btn",func:C}];for(const t of r){const n=null===(o=e.shadowRoot)||void 0===o?void 0:o.querySelector(t.id);n&&(console.log(t.id),n.addEventListener("click",t.func))}if(window.matchMedia("(max-width: 500px)").matches){const o=null===(t=e.shadowRoot)||void 0===t?void 0:t.querySelectorAll(".omnivore-top-button-label");null==o||o.forEach((e=>{e.style.display="none"}));const i=null===(n=e.shadowRoot)||void 0===n?void 0:n.querySelector("#omnivore-toast-container");i&&(i.style.width="280px",i.style.top="unset",i.style.bottom="20px")}};function v(){var e,o,t;a(),h("#omnivore-edit-title-row");let n=null!==(e=document.querySelector("#omnivore-extension-root"))&&void 0!==e?e:void 0;if(!n)return void console.log("no statusBox to update");const i=null===(o=null==n?void 0:n.shadowRoot)||void 0===o?void 0:o.querySelector("#omnivore-edit-title-textarea");i&&(i.focus(),i.onkeydown=e=>{e.cancelBubble=!0});const r=null===(t=null==n?void 0:n.shadowRoot)||void 0===t?void 0:t.querySelector("#omnivore-edit-title-form");r?r.onsubmit=e=>{var o;f("#omnivore-edit-title-status","waiting","Updating title...",void 0);const t=null!==(o=null==i?void 0:i.value)&&void 0!==o?o:"";chrome.runtime.sendMessage({action:"enqueueTask",task:"editTitle",clientRequestId:p(),title:t}),e.preventDefault()}:console.log("no form to update")}const m=()=>{a(),l("failure"),h("#omnivore-logged-out-row"),g(),f("#omnivore-logged-out-status",void 0,"You are not logged in.",void 0)},f=(e,o,t,n)=>{var i;const r=document.querySelector("#omnivore-extension-root"),d=null===(i=null==r?void 0:r.shadowRoot)||void 0===i?void 0:i.querySelector(e),l=(()=>{switch(o){case"waiting":return s.animatedLoader;case"success":return s.success;case"failure":return s.failure;default:return}})();if(l&&d){const e="failure"==o?"red":"unset";d.innerHTML=`${l}${t}`}else d&&(d.innerHTML=t);n&&d&&setTimeout((()=>{d.innerHTML=""}),n)},g=()=>{let e=document.querySelector("#omnivore-extension-root");["#omnivore-toast-edit-title-btn","#omnivore-toast-edit-labels-btn","#omnivore-toast-read-now-btn","#omnivore-toast-add-note-btn","#omnivore-open-menu-btn"].forEach((o=>{var t;const n=null===(t=null==e?void 0:e.shadowRoot)||void 0===t?void 0:t.querySelector(o);n&&(n.disabled=!0)}))},h=e=>{var o,t;let n=document.querySelector("#omnivore-extension-root");if(!n)return void console.log("toggleRow: no row to toggle");const i=null===(o=null==n?void 0:n.shadowRoot)||void 0===o?void 0:o.querySelector(e),r=null==i?void 0:i.getAttribute("data-state"),s=null===(t=null==n?void 0:n.shadowRoot)||void 0===t?void 0:t.querySelectorAll(".omnivore-toast-func-row");if(null==s||s.forEach((e=>{e.setAttribute("data-state","closed")})),i&&r){const e="open"===r?"closed":"open";i.setAttribute("data-state",e)}},p=()=>{const e=document.querySelector("#omnivore-extension-root");return null==e?void 0:e.getAttribute("data-omnivore-client-request-id")},b=()=>{window.open(new URL("/login",process.env.OMNIVORE_URL),"_blank"),q()},y=()=>{a(),h("#omnivore-extra-buttons-row")},w=()=>r(void 0,void 0,void 0,(function*(){var e,o,t;console.log("[omnivore] adding note"),a();const i=document.querySelector("#omnivore-extension-root"),s=null==i?void 0:i.getAttribute("data-omnivore-client-request-id");if(console.log("client request id: ",s),!s)return void f("#omnivore-add-note-status","failure","Error adding note...",void 0);const d=`cached-note-${document.location.href}`;a(),h("#omnivore-add-note-row");const l=null===(e=null==i?void 0:i.shadowRoot)||void 0===e?void 0:e.querySelector("#omnivore-add-note-textarea");if(l){if(d){const e=null!==(o=yield(0,n.$)(d))&&void 0!==o?o:"";l.value=e}l.value?l.select():l.focus(),l.addEventListener("input",(e=>r(void 0,void 0,void 0,(function*(){const o={};o[d]=e.target.value,yield(0,n.c)(o)})))),l.onkeydown=e=>r(void 0,void 0,void 0,(function*(){e.stopPropagation(),console.log("handling the enter key: ",e.keyCode),13==e.keyCode&&(e.metaKey||e.ctrlKey)&&(f("#omnivore-add-note-status","waiting","Adding note...",void 0),yield T(s,l.value))}))}const c=null===(t=null==i?void 0:i.shadowRoot)||void 0===t?void 0:t.querySelector("#omnivore-add-note-form");c&&(c.onsubmit=e=>r(void 0,void 0,void 0,(function*(){console.log("handling form submit"),f("#omnivore-add-note-status","waiting","Adding note...",void 0),l&&(yield T(s,l.value)),e.preventDefault(),e.stopPropagation()})))})),x=e=>r(void 0,void 0,void 0,(function*(){const o=p();try{yield chrome.runtime.sendMessage({action:"enqueueTask",task:"archive",clientRequestId:o})}catch(e){console.log("error archiving item")}e.preventDefault()})),C=e=>r(void 0,void 0,void 0,(function*(){const o=p();try{yield chrome.runtime.sendMessage({action:"enqueueTask",task:"delete",clientRequestId:o})}catch(e){console.log("error archiving item")}e.preventDefault()})),L=()=>r(void 0,void 0,void 0,(function*(){var e;a();let o=document.querySelector("#omnivore-extension-root");const t=null===(e=null==o?void 0:o.shadowRoot)||void 0===e?void 0:e.querySelector("#omnivore-toast-container");null==t||t.setAttribute("data-state","open"),window.open(new URL(`/article?url=${encodeURI(document.location.href)}`,yield(0,n.$)("omnivoreUrl")),"_blank"),q()})),q=()=>{setTimeout((()=>{R()}),1e3)},R=()=>{const e=document.querySelector("#omnivore-extension-root");e&&e.remove()},T=(e,o)=>r(void 0,void 0,void 0,(function*(){try{yield chrome.runtime.sendMessage({action:"enqueueTask",task:"addNote",note:o,clientRequestId:e})}catch(e){console.log("error adding note: ",e)}}))},454:(e,o,t)=>{t.d(o,{$:()=>n,c:()=>i});const n=e=>{return o=void 0,t=void 0,i=function*(){return new Promise((o=>{chrome.storage.local.get(e,(t=>{const n=t&&t[e]||null;o(n)}))}))},new((n=void 0)||(n=Promise))((function(e,r){function s(e){try{l(i.next(e))}catch(e){r(e)}}function d(e){try{l(i.throw(e))}catch(e){r(e)}}function l(o){var t;o.done?e(o.value):(t=o.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,d)}l((i=i.apply(o,t||[])).next())}));var o,t,n,i},i=e=>chrome.storage.local.set(e)}},o={};function t(n){var i=o[n];if(void 0!==i)return i.exports;var r=o[n]={exports:{}};return e[n](r,r.exports,t),r.exports}t.d=(e,o)=>{for(var n in o)t.o(o,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:o[n]})},t.o=(e,o)=>Object.prototype.hasOwnProperty.call(e,o);var n=t(782),i=t(322),r=function(e,o,t,n){return new(t||(t=Promise))((function(i,r){function s(e){try{l(n.next(e))}catch(e){r(e)}}function d(e){try{l(n.throw(e))}catch(e){r(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof t?o:new t((function(e){e(o)}))).then(s,d)}l((n=n.apply(e,o||[])).next())}))};const s=(e,o,t)=>r(void 0,void 0,void 0,(function*(){switch(console.log("[omnivore] content script message:",e),e.message){case"showLoggedOutToolbar":(0,n.Jw)(),t({success:!0});break;case"updateToolbar":(0,n.Dz)(e.status,e.task),t({success:!0});break;case"startToolbarDismiss":return(0,n.Wj)(e),void t({success:!0});case"updateLabelCache":(0,i.W)();break;default:return void t({success:!1})}}));chrome.runtime.onMessage.addListener(((e,o,t)=>r(void 0,void 0,void 0,(function*(){if("savePage"===e.message)return yield(o=e.clientRequestId,r(void 0,void 0,void 0,(function*(){console.log("[omnivore] v3 extension triggered: ",o),yield(e=>r(void 0,void 0,void 0,(function*(){chrome.runtime.onMessage.hasListener(s)||chrome.runtime.onMessage.addListener(s),yield(0,n.ll)(e)})))(o);const e=yield r(void 0,void 0,void 0,(function*(){const e=document.documentElement.outerHTML;return console.log("[omnivore] captured mainContent"),e}));console.log("[omnivore] collected page content: ",e);try{const t={clientRequestId:o,title:document.title,url:document.location.href,originalContent:e};yield chrome.runtime.sendMessage(Object.assign({action:"savePage"},t))}catch(e){console.log("error sending content: ",e)}}))),void t({success:!0});var o}))))})();