From 8c047633763b882c2fd3e353f830f0b8ab2c83b5 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Thu, 16 Nov 2023 23:56:17 +0800 Subject: [PATCH 1/3] Add privacy opt-in for firefox extension --- pkg/extension/src/manifest.json | 4 +-- pkg/extension/src/scripts/background.js | 47 ++++++++++++++----------- pkg/extension/src/views/cta-popup.html | 3 +- 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/pkg/extension/src/manifest.json b/pkg/extension/src/manifest.json index 03dfcbc79..24dd13fe3 100644 --- a/pkg/extension/src/manifest.json +++ b/pkg/extension/src/manifest.json @@ -11,7 +11,7 @@ "url": "https://omnivore.app/" }, "homepage_url": "https://omnivore.app/", - "content_security_policy": "default-src 'none'; child-src 'none'; manifest-src 'none'; media-src 'none'; object-src 'none'; worker-src 'none'; connect-src https://storage.googleapis.com/ process.env.OMNIVORE_GRAPHQL_URL blob:; frame-src 'none'; font-src 'none'; img-src data:; script-src 'self'; script-src-elem 'self'; script-src-attr 'none'; style-src 'self'; style-src-elem 'self'; style-src-attr 'none'; base-uri 'none'; form-action 'none'; block-all-mixed-content; upgrade-insecure-requests; report-uri https://api.jeurissen.co/reports/csp/webext/omnivore/", + "content_security_policy": "default-src 'none'; child-src 'none'; manifest-src 'none'; media-src 'none'; object-src 'none'; worker-src 'none'; connect-src https://storage.googleapis.com/ process.env.OMNIVORE_GRAPHQL_URL blob:; frame-src 'none'; font-src 'none'; img-src data:; script-src 'self'; script-src-elem 'self' 'unsafe-inline'; script-src-attr 'unsafe-inline'; style-src 'self' 'unsafe-inline'; style-src-elem 'self' 'unsafe-inline'; style-src-attr 'none'; base-uri 'none'; form-action 'none'; block-all-mixed-content; upgrade-insecure-requests; report-uri https://api.jeurissen.co/reports/csp/webext/omnivore/", "icons": { "16": "/images/extension/icon-16.png", "24": "/images/extension/icon-24.png", @@ -95,4 +95,4 @@ "web_accessible_resources": [ "views/toast.html" ] -} +} \ No newline at end of file diff --git a/pkg/extension/src/scripts/background.js b/pkg/extension/src/scripts/background.js index 0fccd47c8..2a2833781 100644 --- a/pkg/extension/src/scripts/background.js +++ b/pkg/extension/src/scripts/background.js @@ -643,9 +643,16 @@ function checkAuthOnFirstClickPostInstall(tabId) { } function handleActionClick() { - executeAction(function (currentTab) { - extensionSaveCurrentPage(currentTab.id) - }) + getStorageItem('consentGranted') + .then((consentGranted) => { + console.log('consentGranted: ', consentGranted) + executeAction(function (currentTab) { + extensionSaveCurrentPage(currentTab.id) + }) + }) + .catch(() => { + console.log('extension consent not granted') + }) } function executeAction(action) { @@ -684,24 +691,6 @@ function executeAction(action) { }) } -function getActionableState(tab) { - if (tab.status !== 'complete') return false - - const tabUrl = tab.pendingUrl || tab.url - if (!tabUrl) return false - - if (!tabUrl.startsWith('https://') && !tabUrl.startsWith('http://')) - return false - - if ( - tabUrl.startsWith('https://omnivore.app/') && - tabUrl.startsWith('https://dev.omnivore.app/') - ) - return false - - return true -} - function init() { browserApi.tabs.onActivated.addListener(({ tabId }) => { // Due to a chrome bug, chrome.tabs.* may run into an error because onActivated is triggered too fast. @@ -820,6 +809,22 @@ function init() { }) }, }) + + browser.runtime.onInstalled.addListener(async ({ reason, temporary }) => { + // if (temporary) return // skip during development + console.log('onInstalled: ', reason, temporary) + switch (reason) { + case 'update': + case 'install': + { + const url = browser.runtime.getURL('views/installed.html') + await browser.tabs.create({ url }) + // or: await browser.windows.create({ url, type: "popup", height: 600, width: 600, }); + } + break + // see below + } + }) } init() diff --git a/pkg/extension/src/views/cta-popup.html b/pkg/extension/src/views/cta-popup.html index 94fe55621..682799154 100644 --- a/pkg/extension/src/views/cta-popup.html +++ b/pkg/extension/src/views/cta-popup.html @@ -7,6 +7,7 @@ + \n
\n '};function r(){a=!0,o&&clearTimeout(o)}function s(o){if(e)switch(o.ctx&&(t={...t,...o.ctx}),o.target){case"logged_out":r(),l("failure"),c("#omnivore-logged-out-row"),d("#omnivore-logged-out-status","empty","You are not logged in."),["#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((t=>{e.shadowRoot.querySelector(t).disabled=!0}));break;case"page":l(o.status);break;case"note":d("#omnivore-add-note-status",o.status,o.message,"success"==o.status?2500:void 0),"success"==o.status&&setTimeout((()=>{c("#omnivore-add-note-status")}),3e3);break;case"title":d("#omnivore-edit-title-status",o.status,o.message,"success"==o.status?2500:void 0),"success"==o.status&&setTimeout((()=>{c("#omnivore-edit-title-status")}),3e3);break;case"labels":d("#omnivore-edit-labels-status",o.status,o.message,"success"==o.status?2500:void 0);break;case"extra":d("#omnivore-extra-status",o.status,o.message,"success"==o.status?2500:void 0),"success"==o.status&&setTimeout((()=>{e.remove()}),3e3)}else console.log("no statusBox to update")}function l(t){const n=e.shadowRoot.querySelector(".omnivore-toast-statusBox");switch(t){case"loading":n.innerHTML=i.animatedLoader;break;case"success":const t=t=>{const n=t&&!Number.isNaN(Number(t))?Number(t):2500;console.log("setting dismiss time: ",n),o=setTimeout((function(){console.log("hiding toast timeout"),a||(e.remove(),e=void 0)}),n)};getStorageItem("autoDismissTime").then((e=>{t(e)})).catch((()=>{t("2500")})),getStorageItem("disableAutoDismiss").then((e=>{console.log("got disableAutoDismiss",e),e&&r()})),n.innerHTML=i.success;break;case"failure":n.innerHTML=i.failure}}function d(t,o,n,a){const r=e.shadowRoot.querySelector(t),s=(()=>{switch(o){case"loading":return i.animatedLoader;case"success":return i.success;case"failure":return i.failure;case"none":return"";default:return}})();r.innerHTML=s?`${s}${n}`:n,a&&setTimeout((()=>{r.innerHTML=""}),a)}function c(t){if(!e)return;const o=e.shadowRoot.querySelector(t),n=o?.getAttribute("data-state");if(e.shadowRoot.querySelectorAll(".omnivore-toast-func-row").forEach((e=>{e.setAttribute("data-state","closed")})),o&&n){const e="open"===n?"closed":"open";o.setAttribute("data-state",e)}}function u(e){const t=document.createElement("button"),o=document.createElement("span");o.style="width:10px;height:10px;border-radius:1000px;",o.style.setProperty("background-color",e.color);const n=document.createElement("span");n.style="margin-left: 10px;pointer-events: none;",n.innerText=e.name;const a=document.createElement("span");return a.style="margin-left: auto;pointer-events: none;",a.className="checkbox",a.innerHTML='\n \n \n \n ',t.appendChild(o),t.appendChild(n),t.appendChild(a),t.onclick=m,t.onkeydown=g,t.setAttribute("data-label-id",e.id),t.setAttribute("data-label-selected",e.selected?"on":"off"),t.setAttribute("tabIndex","-1"),t}function m(e){e.preventDefault();const t=e.target.getAttribute("data-label-id");b(e,t)}function b(e,t){const o=e.target.getAttribute("data-label-selected");if(!t||!o)return;const a="on"!=o;e.target.setAttribute("data-label-selected",a?"on":"off");const i=n.find((e=>e.id===t));i&&(i.selected=a);const r=e.target.form.querySelector("#label-list"),s=e.target.form.querySelector("#omnivore-edit-label-input");a?h(r,s,i.name):w(r,i.id)}function p(e){const t=e.target.querySelector("#omnivore-edit-label-input");t&&e.target!=t&&t.focus()}function g(e){switch(e.cancelBubble=!0,e.stopPropogation&&e.stopPropogation(),e.target.form&&"backspace"!==e.key.toLowerCase()&&e.target.form.querySelectorAll('.label[data-label-backspaced="on"]').forEach((e=>{e.removeAttribute("data-label-backspaced")})),e.key.toLowerCase()){case"arrowup":{if("omnivore-edit-label-input"==e.target.id)return;if(!e.target.getAttribute("data-label-id"))return;let t=e.target.previousElementSibling;t&&t.getAttribute("data-label-id")?t.focus():e.target.form.querySelector("#omnivore-edit-label-input")?.focus(),e.preventDefault();break}case"arrowdown":{let t;"omnivore-edit-label-input"==e.target.id?(idx=e.target.getAttribute("data-label-id"),t=e.target.closest("#omnivore-edit-labels-form").querySelector("#omnivore-edit-labels-list").querySelector("[data-label-id]")):t=e.target.nextElementSibling,t&&t.getAttribute("data-label-id")&&t.focus(),e.preventDefault();break}case"backspace":"omnivore-edit-label-input"==e.target.id&&0==e.target.value.length&&(e.target.form.querySelector("#label-list"),function(e,t){const o=t.closest("#label-entry-item").previousElementSibling;o&&(o.getAttribute("data-label-backspaced")?w(t.closest("#label-list"),o.getAttribute("data-label-id")):o.setAttribute("data-label-backspaced","on"))}(0,e.target));break;case"enter":{if("omnivore-edit-label-input"==e.target.id)return e.target.value&&h(e.target.form.querySelector("#label-list"),e.target,e.target.value),void e.preventDefault();const t=e.target.getAttribute("data-label-id");b(e,t),e.preventDefault();break}}}async function f(){const o=document.location?`cached-note-${document.location.href}`:void 0;r(),c("#omnivore-add-note-row");const n=e.shadowRoot.querySelector("#omnivore-add-note-textarea");if(n){if(o){const e=await getStorageItem(o);n.value=e}n.value?n.select():n.focus(),n.addEventListener("input",(e=>{(async()=>{const t={};t[o]=e.target.value,await setStorage(t)})()})),n.onkeydown=e=>{e.cancelBubble=!0,e.stopPropogation&&e.stopPropogation(),13==e.keyCode&&(e.metaKey||e.ctrlKey)&&(d("#omnivore-add-note-status","loading","Adding note..."),browserApi.runtime.sendMessage({action:ACTIONS.AddNote,payload:{ctx:t,note:n.value}}))}}e.shadowRoot.querySelector("#omnivore-add-note-form").onsubmit=e=>{d("#omnivore-add-note-status","loading","Adding note..."),browserApi.runtime.sendMessage({action:ACTIONS.AddNote,payload:{ctx:t,note:e.target.elements.title.value}}),e.preventDefault(),e.stopPropogation&&e.stopPropogation()}}function v(){r(),c("#omnivore-edit-title-row");const o=e.shadowRoot.querySelector("#omnivore-edit-title-textarea");o&&(o.focus(),o.onkeydown=e=>{e.cancelBubble=!0,e.stopPropogation&&e.stopPropogation()}),e.shadowRoot.querySelector("#omnivore-edit-title-form").onsubmit=e=>{d("#omnivore-edit-title-status","loading","Updating title..."),browserApi.runtime.sendMessage({action:ACTIONS.EditTitle,payload:{ctx:t,title:e.target.elements.title.value}}),e.preventDefault()}}function h(e,t,o){const a=n.find((e=>e.name===o)),i=a?a.id:([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,(e=>(e^crypto.getRandomValues(new Uint8Array(1))[0]&15>>e/4).toString(16))),r=e.querySelector("#label-entry-item"),s=r.querySelector("#omnivore-edit-label-input");if(a&&e.querySelector(`[data-label-id='${a.id}']`)){const t=e.querySelector(`[data-label-id='${a.id}']`);return t.setAttribute("data-item-highlighted","on"),setTimeout((()=>{t.style.borderColor="rgb(222, 222, 222)"}),500),void(s&&(s.value="",s.focus(),L(void 0)))}const l=a?a.color:function(){const e=["#FF5D99","#7CFF7B","#FFD234","#7BE4FF","#CE88EF","#EF8C43"];return e[Math.floor(Math.random()*e.length)]}(),d=document.createElement("li");d.classList.add("label"),d.innerHTML=`\n \n ${o}\n \n `,e.insertBefore(d,r),t.value="";const c=d.querySelector(".label-remove-button");c&&(c.onclick=t=>{w(e,i),t.preventDefault()});const m=e.closest("#omnivore-edit-labels-form");if(a){const e=m.querySelector(`[data-label-id='${a.id}']`);a.selected=!0,e.setAttribute("data-label-selected","on"),d.setAttribute("data-label-id",a.id)}else{const e=m.querySelector("#omnivore-edit-labels-list"),t={id:i,color:l,name:o,temporary:!0,selected:!0};n.push(t),d.setAttribute("data-label-id",t.id);const a=u(t),r=e.querySelector("button[data-label-id]");a.setAttribute("data-label-selected","on"),e.insertBefore(a,r)}s&&(s.focus(),L(void 0)),y()}function w(e,t){const o=e.closest("#omnivore-edit-labels-form"),a=e.querySelector(`[data-label-id='${t}']`);a&&a.remove();const i=o.querySelector(`[data-label-id='${t}']`);i&&i.setAttribute("data-label-selected","off");const r=n.find((e=>e.id===t));r&&(r.selected=!1),y()}function y(){d("#omnivore-edit-labels-status","loading","Updating Labels...",void 0);const e=n.filter((e=>e.selected)).map((e=>({name:e.name,color:e.color})));browserApi.runtime.sendMessage({action:ACTIONS.SetLabels,payload:{ctx:t,labels:e}})}async function C(){r(),await getStorageItem("labels").then((e=>{n=e})),c("#omnivore-edit-labels-row"),e.shadowRoot.querySelector("#omnivore-edit-label-input")?.focus();const t=e.shadowRoot.querySelector("#omnivore-edit-labels-list");e.shadowRoot.querySelector("#omnivore-edit-label-input").onkeydown=g,e.shadowRoot.querySelector("#omnivore-edit-label-editor").onclick=p,e.shadowRoot.querySelector("#omnivore-edit-label-input").addEventListener("input",(e=>{L(e.target.value)})),t&&(t.innerHTML="",n.sort(((e,t)=>e.name.localeCompare(t.name,void 0,{sensitivity:"base"}))).forEach((function(e,o){const n=u(e);t.appendChild(n)})))}async function L(t){const o=e.shadowRoot.querySelector("#omnivore-edit-labels-list");o&&(o.innerHTML="",t?n.filter((e=>e.name.toLowerCase().indexOf(t.toLowerCase())>-1)).sort(((e,t)=>e.name.localeCompare(t.name,void 0,{sensitivity:"base"}))).forEach((function(e){const t=u(e);o.appendChild(t)})):n.sort(((e,t)=>e.name.localeCompare(t.name,void 0,{sensitivity:"base"}))).forEach((function(e){const t=u(e);o.appendChild(t)})))}function S(){r(),e.shadowRoot.querySelector("#omnivore-toast-container").setAttribute("data-state","open"),t&&t.readerURL?window.open(t.readerURL,"_blank"):t?window.open(new URL(`/article?url=${encodeURI(t.originalURL)}`,t.omnivoreURL),"_blank"):alert("Error no URL found."),setTimeout((()=>{q()}),1e3)}function x(e){browserApi.runtime.sendMessage({action:ACTIONS.Archive,payload:{ctx:t}}),e.preventDefault()}function k(e){browserApi.runtime.sendMessage({action:ACTIONS.Delete,payload:{ctx:t}}),e.preventDefault()}function A(){r(),c("#omnivore-extra-buttons-row")}function q(){e.remove(),e=void 0}function R(){window.open(new URL("/login",t.omnivoreURL),"_blank"),setTimeout(q,2e3)}window.showToolbar=function(o){t=o.ctx,async function(t){document.body&&(e||(e=await async function(){const e=await fetch(browserApi.runtime.getURL("views/toast.html")),t=await e.text(),o=document.createElement("div");o.tabIndex=0,o.attachShadow({mode:"open"}),o.shadowRoot&&(o.shadowRoot.innerHTML="");const n=document.createElement("div");return n.id="#omnivore-toast",n.innerHTML=t,n.tabIndex=0,o.shadowRoot.appendChild(n),document.body.appendChild(o),function(e){const t=[{id:"#omnivore-toast-add-note-btn",func:f},{id:"#omnivore-toast-edit-title-btn",func:v},{id:"#omnivore-toast-edit-labels-btn",func:C},{id:"#omnivore-toast-read-now-btn",func:S},{id:"#omnivore-open-menu-btn",func:A},{id:"#omnivore-toast-close-btn",func:q},{id:"#omnivore-toast-login-btn",func:R},{id:"#omnivore-toast-archive-btn",func:x},{id:"#omnivore-toast-delete-btn",func:k}];for(const o of t){const t=e.shadowRoot.querySelector(o.id);t&&t.addEventListener("click",o.func)}if(window.matchMedia("(max-width: 500px)").matches){e.shadowRoot.querySelectorAll(".omnivore-top-button-label").forEach((e=>{e.style.display="none"}));const t=e.shadowRoot.querySelector("#omnivore-toast-container");t.style.width="280px",t.style.top="unset",t.style.bottom="20px"}}(o),function(e){e.addEventListener("keydown",(e=>{switch(e.key){case"r":S();break;case"l":C();break;case"m":A();break;case"t":v();break;case"n":e.preventDefault(),f()}e.cancelBubble=!0,e.stopPropogation&&e.stopPropogation()}))}(o),o}()),"loading"===t.type&&s({status:"loading",target:"page"}),document.querySelectorAll("#omnivore-toast").forEach((t=>{t!==e&&(console.log("removing current toast el: ",e),t.remove())})),e.focus({preventScroll:!0}))}(o).catch((e=>console.log("error showing toast",e)))},window.updateStatus=s,window.updateLabelsFromCache=function(e){(async()=>{await getStorageItem("labels").then((e=>{n&&n.filter((e=>e.selected)).forEach((t=>{const o=e.find((e=>e.name==t.name));o?o.selected=!0:e.push(t)})),n=e}))})()}}(); \ No newline at end of file +!function(){let e,t,o,n=[],a=!1;const i={spinner:'\n \n \n \n \n \n \n \n \n \n ',success:'\n \n \n \n ',failure:'\n \n \n \n ',close:'',animatedLoader:'\n \n
\n '};function r(){a=!0,o&&clearTimeout(o)}function s(o){if(e)switch(o.ctx&&(t={...t,...o.ctx}),o.target){case"logged_out":r(),l("failure"),c("#omnivore-logged-out-row"),d("#omnivore-logged-out-status","empty","You are not logged in."),["#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((t=>{e.shadowRoot.querySelector(t).disabled=!0}));break;case"page":l(o.status);break;case"note":d("#omnivore-add-note-status",o.status,o.message,"success"==o.status?2500:void 0),"success"==o.status&&setTimeout((()=>{c("#omnivore-add-note-status")}),3e3);break;case"title":d("#omnivore-edit-title-status",o.status,o.message,"success"==o.status?2500:void 0),"success"==o.status&&setTimeout((()=>{c("#omnivore-edit-title-status")}),3e3);break;case"labels":d("#omnivore-edit-labels-status",o.status,o.message,"success"==o.status?2500:void 0);break;case"extra":d("#omnivore-extra-status",o.status,o.message,"success"==o.status?2500:void 0),"success"==o.status&&setTimeout((()=>{e.remove()}),3e3)}else console.log("no statusBox to update")}function l(t){const n=e.shadowRoot.querySelector(".omnivore-toast-statusBox");switch(t){case"loading":n.innerHTML=i.animatedLoader;break;case"success":const t=t=>{const n=t&&!Number.isNaN(Number(t))?Number(t):2500;console.log("setting dismiss time: ",n),o=setTimeout((function(){console.log("hiding toast timeout"),a||(e.remove(),e=void 0)}),n)};getStorageItem("autoDismissTime").then((e=>{t(e)})).catch((()=>{t("2500")})),getStorageItem("disableAutoDismiss").then((e=>{console.log("got disableAutoDismiss",e),e&&r()})),n.innerHTML=i.success;break;case"failure":n.innerHTML=i.failure}}function d(t,o,n,a){const r=e.shadowRoot.querySelector(t),s=(()=>{switch(o){case"loading":return i.animatedLoader;case"success":return i.success;case"failure":return i.failure;case"none":return"";default:return}})();r.innerHTML=s?`${s}${n}`:n,a&&setTimeout((()=>{r.innerHTML=""}),a)}function c(t){if(!e)return;const o=e.shadowRoot.querySelector(t),n=o?.getAttribute("data-state");if(e.shadowRoot.querySelectorAll(".omnivore-toast-func-row").forEach((e=>{e.setAttribute("data-state","closed")})),o&&n){const e="open"===n?"closed":"open";o.setAttribute("data-state",e)}}function u(e){const t=document.createElement("button"),o=document.createElement("span");o.style="width:10px;height:10px;border-radius:1000px;",o.style.setProperty("background-color",e.color);const n=document.createElement("span");n.style="margin-left: 10px;pointer-events: none;",n.innerText=e.name;const a=document.createElement("span");return a.style="margin-left: auto;pointer-events: none;",a.className="checkbox",a.innerHTML='\n \n \n \n ',t.appendChild(o),t.appendChild(n),t.appendChild(a),t.onclick=m,t.onkeydown=g,t.setAttribute("data-label-id",e.id),t.setAttribute("data-label-selected",e.selected?"on":"off"),t.setAttribute("tabIndex","-1"),t}function m(e){e.preventDefault();const t=e.target.getAttribute("data-label-id");b(e,t)}function b(e,t){const o=e.target.getAttribute("data-label-selected");if(!t||!o)return;const a="on"!=o;e.target.setAttribute("data-label-selected",a?"on":"off");const i=n.find((e=>e.id===t));i&&(i.selected=a);const r=e.target.form.querySelector("#label-list"),s=e.target.form.querySelector("#omnivore-edit-label-input");a?h(r,s,i.name):w(r,i.id)}function p(e){const t=e.target.querySelector("#omnivore-edit-label-input");t&&e.target!=t&&t.focus()}function g(e){switch(e.cancelBubble=!0,e.stopPropogation&&e.stopPropogation(),e.target.form&&"backspace"!==e.key.toLowerCase()&&e.target.form.querySelectorAll('.label[data-label-backspaced="on"]').forEach((e=>{e.removeAttribute("data-label-backspaced")})),e.key.toLowerCase()){case"arrowup":{if("omnivore-edit-label-input"==e.target.id)return;if(!e.target.getAttribute("data-label-id"))return;let t=e.target.previousElementSibling;t&&t.getAttribute("data-label-id")?t.focus():e.target.form.querySelector("#omnivore-edit-label-input")?.focus(),e.preventDefault();break}case"arrowdown":{let t;"omnivore-edit-label-input"==e.target.id?(idx=e.target.getAttribute("data-label-id"),t=e.target.closest("#omnivore-edit-labels-form").querySelector("#omnivore-edit-labels-list").querySelector("[data-label-id]")):t=e.target.nextElementSibling,t&&t.getAttribute("data-label-id")&&t.focus(),e.preventDefault();break}case"backspace":"omnivore-edit-label-input"==e.target.id&&0==e.target.value.length&&(e.target.form.querySelector("#label-list"),function(e,t){const o=t.closest("#label-entry-item").previousElementSibling;o&&(o.getAttribute("data-label-backspaced")?w(t.closest("#label-list"),o.getAttribute("data-label-id")):o.setAttribute("data-label-backspaced","on"))}(0,e.target));break;case"enter":{if("omnivore-edit-label-input"==e.target.id)return e.target.value&&h(e.target.form.querySelector("#label-list"),e.target,e.target.value),void e.preventDefault();const t=e.target.getAttribute("data-label-id");b(e,t),e.preventDefault();break}}}async function f(){const o=document.location?`cached-note-${document.location.href}`:void 0;r(),c("#omnivore-add-note-row");const n=e.shadowRoot.querySelector("#omnivore-add-note-textarea");if(n){if(o){const e=await getStorageItem(o);n.value=e}n.value?n.select():n.focus(),n.addEventListener("input",(e=>{(async()=>{const t={};t[o]=e.target.value,await setStorage(t)})()})),n.onkeydown=e=>{e.cancelBubble=!0,e.stopPropogation&&e.stopPropogation(),13==e.keyCode&&(e.metaKey||e.ctrlKey)&&(d("#omnivore-add-note-status","loading","Adding note..."),browserApi.runtime.sendMessage({action:ACTIONS.AddNote,payload:{ctx:t,note:n.value}}))}}e.shadowRoot.querySelector("#omnivore-add-note-form").onsubmit=e=>{d("#omnivore-add-note-status","loading","Adding note..."),browserApi.runtime.sendMessage({action:ACTIONS.AddNote,payload:{ctx:t,note:e.target.elements.title.value}}),e.preventDefault(),e.stopPropogation&&e.stopPropogation()}}function v(){r(),c("#omnivore-edit-title-row");const o=e.shadowRoot.querySelector("#omnivore-edit-title-textarea");o&&(o.focus(),o.onkeydown=e=>{e.cancelBubble=!0,e.stopPropogation&&e.stopPropogation()}),e.shadowRoot.querySelector("#omnivore-edit-title-form").onsubmit=e=>{d("#omnivore-edit-title-status","loading","Updating title..."),browserApi.runtime.sendMessage({action:ACTIONS.EditTitle,payload:{ctx:t,title:e.target.elements.title.value}}),e.preventDefault()}}function h(e,t,o){const a=n.find((e=>e.name===o)),i=a?a.id:([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,(e=>(e^crypto.getRandomValues(new Uint8Array(1))[0]&15>>e/4).toString(16))),r=e.querySelector("#label-entry-item"),s=r.querySelector("#omnivore-edit-label-input");if(a&&e.querySelector(`[data-label-id='${a.id}']`)){const t=e.querySelector(`[data-label-id='${a.id}']`);return t.setAttribute("data-item-highlighted","on"),setTimeout((()=>{t.style.borderColor="rgb(222, 222, 222)"}),500),void(s&&(s.value="",s.focus(),L(void 0)))}const l=a?a.color:function(){const e=["#FF5D99","#7CFF7B","#FFD234","#7BE4FF","#CE88EF","#EF8C43"];return e[Math.floor(Math.random()*e.length)]}(),d=document.createElement("li");d.classList.add("label"),d.innerHTML=`\n \n ${o}\n \n `,e.insertBefore(d,r),t.value="";const c=d.querySelector(".label-remove-button");c&&(c.onclick=t=>{w(e,i),t.preventDefault()});const m=e.closest("#omnivore-edit-labels-form");if(a){const e=m.querySelector(`[data-label-id='${a.id}']`);a.selected=!0,e.setAttribute("data-label-selected","on"),d.setAttribute("data-label-id",a.id)}else{const e=m.querySelector("#omnivore-edit-labels-list"),t={id:i,color:l,name:o,temporary:!0,selected:!0};n.push(t),d.setAttribute("data-label-id",t.id);const a=u(t),r=e.querySelector("button[data-label-id]");a.setAttribute("data-label-selected","on"),e.insertBefore(a,r)}s&&(s.focus(),L(void 0)),y()}function w(e,t){const o=e.closest("#omnivore-edit-labels-form"),a=e.querySelector(`[data-label-id='${t}']`);a&&a.remove();const i=o.querySelector(`[data-label-id='${t}']`);i&&i.setAttribute("data-label-selected","off");const r=n.find((e=>e.id===t));r&&(r.selected=!1),y()}function y(){d("#omnivore-edit-labels-status","loading","Updating Labels...",void 0);const e=n.filter((e=>e.selected)).map((e=>({name:e.name,color:e.color})));browserApi.runtime.sendMessage({action:ACTIONS.SetLabels,payload:{ctx:t,labels:e}})}async function C(){r(),await getStorageItem("labels").then((e=>{n=e})),c("#omnivore-edit-labels-row"),e.shadowRoot.querySelector("#omnivore-edit-label-input")?.focus();const t=e.shadowRoot.querySelector("#omnivore-edit-labels-list");e.shadowRoot.querySelector("#omnivore-edit-label-input").onkeydown=g,e.shadowRoot.querySelector("#omnivore-edit-label-editor").onclick=p,e.shadowRoot.querySelector("#omnivore-edit-label-input").addEventListener("input",(e=>{L(e.target.value)})),t&&(t.innerHTML="",n.sort(((e,t)=>e.name.localeCompare(t.name,void 0,{sensitivity:"base"}))).forEach((function(e,o){const n=u(e);t.appendChild(n)})))}async function L(t){const o=e.shadowRoot.querySelector("#omnivore-edit-labels-list");o&&(o.innerHTML="",t?n.filter((e=>e.name.toLowerCase().indexOf(t.toLowerCase())>-1)).sort(((e,t)=>e.name.localeCompare(t.name,void 0,{sensitivity:"base"}))).forEach((function(e){const t=u(e);o.appendChild(t)})):n.sort(((e,t)=>e.name.localeCompare(t.name,void 0,{sensitivity:"base"}))).forEach((function(e){const t=u(e);o.appendChild(t)})))}function S(){r(),e.shadowRoot.querySelector("#omnivore-toast-container").setAttribute("data-state","open"),t&&t.readerURL?window.open(t.readerURL,"_blank"):t?window.open(new URL(`/article?url=${encodeURI(t.originalURL)}`,t.omnivoreURL),"_blank"):alert("Error no URL found."),setTimeout((()=>{q()}),1e3)}function k(e){browserApi.runtime.sendMessage({action:ACTIONS.Archive,payload:{ctx:t}}),e.preventDefault()}function x(e){browserApi.runtime.sendMessage({action:ACTIONS.Delete,payload:{ctx:t}}),e.preventDefault()}function A(){r(),c("#omnivore-extra-buttons-row")}function q(){e.remove(),e=void 0}function R(){window.open(new URL("/login",t.omnivoreURL),"_blank"),setTimeout(q,2e3)}window.showToolbar=function(o){t=o.ctx,async function(t){document.body&&(e||(e=await async function(){const e=await fetch(browserApi.runtime.getURL("views/toast.html")),t=await e.text(),o=document.createElement("div");o.tabIndex=0,o.attachShadow({mode:"open"}),o.shadowRoot&&(o.shadowRoot.innerHTML="");const n=document.createElement("div");return n.id="#omnivore-toast",n.innerHTML=t,n.tabIndex=0,o.shadowRoot.appendChild(n),document.body.appendChild(o),function(e){const t=[{id:"#omnivore-toast-add-note-btn",func:f},{id:"#omnivore-toast-edit-title-btn",func:v},{id:"#omnivore-toast-edit-labels-btn",func:C},{id:"#omnivore-toast-read-now-btn",func:S},{id:"#omnivore-open-menu-btn",func:A},{id:"#omnivore-toast-close-btn",func:q},{id:"#omnivore-toast-login-btn",func:R},{id:"#omnivore-toast-archive-btn",func:k},{id:"#omnivore-toast-delete-btn",func:x}];for(const o of t){const t=e.shadowRoot.querySelector(o.id);t&&t.addEventListener("click",o.func)}if(window.matchMedia("(max-width: 500px)").matches){e.shadowRoot.querySelectorAll(".omnivore-top-button-label").forEach((e=>{e.style.display="none"}));const t=e.shadowRoot.querySelector("#omnivore-toast-container");t.style.width="280px",t.style.top="unset",t.style.bottom="20px"}}(o),function(e){e.addEventListener("keydown",(e=>{switch(e.key){case"r":S();break;case"l":C();break;case"m":A();break;case"t":v();break;case"n":e.preventDefault(),f()}e.cancelBubble=!0,e.stopPropogation&&e.stopPropogation()})),e.addEventListener("keyup",(e=>{e.cancelBubble=!0,e.stopPropogation&&e.stopPropogation()}))}(o),o}()),"loading"===t.type&&s({status:"loading",target:"page"}),document.querySelectorAll("#omnivore-toast").forEach((t=>{t!==e&&(console.log("removing current toast el: ",e),t.remove())})),e.focus({preventScroll:!0}))}(o).catch((e=>console.log("error showing toast",e)))},window.updateStatus=s,window.updateLabelsFromCache=function(e){(async()=>{await getStorageItem("labels").then((e=>{n&&n.filter((e=>e.selected)).forEach((t=>{const o=e.find((e=>e.name==t.name));o?o.selected=!0:e.push(t)})),n=e}))})()}}(); \ No newline at end of file diff --git a/apple/Sources/SafariExtension/Resources/views/cta-popup.html b/apple/Sources/SafariExtension/Resources/views/cta-popup.html index 94fe55621..682799154 100644 --- a/apple/Sources/SafariExtension/Resources/views/cta-popup.html +++ b/apple/Sources/SafariExtension/Resources/views/cta-popup.html @@ -7,6 +7,7 @@ + + + + + + + + + +