diff --git a/apple/Sources/SafariExtension/Resources/manifest.json b/apple/Sources/SafariExtension/Resources/manifest.json index aa672f639..7c9e909a7 100644 --- a/apple/Sources/SafariExtension/Resources/manifest.json +++ b/apple/Sources/SafariExtension/Resources/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/ https://api-prod.omnivore.app/api/ 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/ https://api-prod.omnivore.app/api/ 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", diff --git a/apple/Sources/SafariExtension/Resources/scripts/background.js b/apple/Sources/SafariExtension/Resources/scripts/background.js index 4fc2a0b9d..d0b838226 100644 --- a/apple/Sources/SafariExtension/Resources/scripts/background.js +++ b/apple/Sources/SafariExtension/Resources/scripts/background.js @@ -1 +1 @@ -(()=>{"use strict";var e,t=new Uint8Array(16);function n(){if(!e&&!(e="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return e(t)}const s=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;for(var a=[],o=0;o<256;++o)a.push((o+256).toString(16).substr(1));const r=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=(a[e[t+0]]+a[e[t+1]]+a[e[t+2]]+a[e[t+3]]+"-"+a[e[t+4]]+a[e[t+5]]+"-"+a[e[t+6]]+a[e[t+7]]+"-"+a[e[t+8]]+a[e[t+9]]+"-"+a[e[t+10]]+a[e[t+11]]+a[e[t+12]]+a[e[t+13]]+a[e[t+14]]+a[e[t+15]]).toLowerCase();if(!function(e){return"string"==typeof e&&s.test(e)}(n))throw TypeError("Stringified UUID is invalid");return n},i=function(e,t,s){var a=(e=e||{}).random||(e.rng||n)();if(a[6]=15&a[6]|64,a[8]=63&a[8]|128,t){s=s||0;for(var o=0;o<16;++o)t[s+o]=a[o];return t}return r(a)};let c=(e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce(((e,t)=>e+((t&=63)<36?t.toString(36):t<62?(t-26).toString(36).toUpperCase():t>62?"-":"_")),"");const u=new class{constructor(){this.queue=[],this.isRunning=!1,this.isReady=!1}enqueue(e){this.queue.push(e),this.isReady&&this.runNext()}async runNext(){if(this.isRunning||0===this.queue.length||!this.isReady)return;this.isRunning=!0;const e=this.queue.shift();try{await e()}catch(e){console.error("Task failed:",e)}finally{this.isRunning=!1,this.isReady&&this.runNext()}}setReady(){this.isReady=!0,this.runNext()}},d="https://omnivore.app",l="https://api-prod.omnivore.app/api/";let p={};async function g(e,t){const n=JSON.stringify({query:"mutation UploadFileRequest($input: UploadFileRequestInput!) {\n uploadFileRequest(input:$input) {\n ... on UploadFileRequestError {\n errorCodes\n }\n ... on UploadFileRequestSuccess {\n id\n createdPageId\n uploadSignedUrl\n }\n }\n }",variables:{input:{url:e,contentType:t,createPageEntry:!0}}}),s="uploadFileRequest",a=await gqlRequest(l+"graphql",n);if(!a[s].errorCodes)return a.uploadFileRequest;"UNAUTHORIZED"===a[s].errorCodes[0]?(browserApi.tabs.sendMessage(currentTab.id,{action:ACTIONS.UpdateStatus,payload:{target:"logged_out",status:"logged_out",message:"You are not logged in.",ctx:toolbarCtx}}),b()):browserApi.tabs.sendMessage(currentTab.id,{action:ACTIONS.UpdateStatus,payload:{status:"failure",message:"Unable to save page.",ctx:toolbarCtx}})}function b(){getStorageItem("postInstallClickComplete").then((e=>{e&&removeStorage("postInstallClickComplete")}))}async function f(e,t){const n=i();await I(e,SAVE_URL_QUERY,"saveUrl",{source:"extension",clientRequestId:n,url:encodeURI(t)})}async function I(e,t,n,s){const a={omnivoreURL:d,originalURL:s.url,requestId:s.clientRequestId};p[a.requestId]=void 0;const o=JSON.stringify({query:t,variables:{input:s}});browserApi.tabs.sendMessage(e.id,{action:ACTIONS.ShowToolbar,payload:{type:"loading",ctx:a}});try{const t=await gqlRequest(l+"graphql",o);if(t[n].errorCodes)return void("UNAUTHORIZED"===t[n].errorCodes[0]?(browserApi.tabs.sendMessage(e.id,{action:ACTIONS.UpdateStatus,payload:{target:"logged_out",status:"logged_out",message:"You are not logged in.",ctx:a}}),b()):browserApi.tabs.sendMessage(e.id,{action:ACTIONS.UpdateStatus,payload:{status:"failure",message:"Unable to save page.",ctx:a}}));const s=t[n]?t[n].url:void 0,r=t[n]?t[n].clientRequestId:void 0;browserApi.tabs.sendMessage(e.id,{action:ACTIONS.UpdateStatus,payload:{status:"success",target:"page",ctx:{readerURL:s,responseId:r,requestId:a.requestId}}}),p[a.requestId]={readerURL:s,responseId:r,requestId:a.requestId}}catch(e){console.log("error saving: ",e)}u.setReady()}function y(e,t,n,s){browserApi.tabs.sendMessage(e,{action:ACTIONS.UpdateStatus,payload:{target:t,status:n,message:s}})}async function h(e,t){browserApi.tabs.sendMessage(e.id,{action:ACTIONS.GetContent,payload:{createHighlight:t}},(async t=>{if(!t||"object"!=typeof t)return void await f(e,e.url);const n=i();var{type:s}=t;const{pageInfo:a,doc:o,uploadContentObjUrl:r}=t;switch("html"==s&&handleBackendUrl(e.url)&&(s="url"),s){case"html":await I(e,SAVE_PAGE_QUERY,"savePage",{source:"extension",clientRequestId:n,originalContent:o,title:a.title,url:encodeURI(e.url)});break;case"url":await I(e,SAVE_URL_QUERY,"saveUrl",{source:"extension",clientRequestId:n,url:encodeURI(e.url)});break;case"pdf":{const t=await async function(e,t,n,s,a){const o={omnivoreURL:d,originalURL:t,requestId:n};p[o.requestId]=void 0,browserApi.tabs.sendMessage(e.id,{action:ACTIONS.ShowToolbar,payload:{type:"loading",ctx:o}});const r=await g(t,s);console.log("done uploading pdf",r);const i=await function({id:e,uploadSignedUrl:t},n,s){return fetch(s).then((e=>e.blob())).then((e=>fetch(t,{method:"PUT",headers:{"Content-Type":n},body:e}))).catch((e=>{console.error("error uploading file",e)}))}(r,s,a);return URL.revokeObjectURL(a),i&&r.createdPageId&&(p[o.requestId]={requestId:o.requestId,responseId:r.createdPageId},browserApi.tabs.sendMessage(e.id,{action:ACTIONS.UpdateStatus,payload:{status:"success",target:"page",ctx:{requestId:o.requestId,responseId:r.createdPageId}}})),i}(e,encodeURI(e.url),n,a.contentType,r);if(!t||!t.id)return void await I(e,SAVE_URL_QUERY,"saveUrl",{source:"extension",clientRequestId:n,url:encodeURI(e.url)});break}}}))}async function q(e){const t=await getStorageItem(e+"_saveInProgress");if(!t)return;clearInterval(t);const n=await getStorageItem(e+"_saveInProgressTimeoutId_"+t);n&&clearTimeout(n)}function R(e,t){function n(n,s){browserApi.tabs.get(e,(async e=>{if("complete"!==e.status)browserApi.tabs.sendMessage(e.id,{action:ACTIONS.ShowMessage,payload:{type:"loading",text:"Page loading..."}}),s&&"function"==typeof s&&s();else{n&&"function"==typeof n&&n(),await h(e,t);try{await updateLabelsCache(l+"graphql",e),browserApi.tabs.sendMessage(e.id,{action:ACTIONS.LabelCacheUpdated,payload:{}})}catch(e){return void console.error("error fetching labels",e,l)}}}))}t=!!t,q(e),n(null,(()=>{!function(e,t,n,s=1e3,a=10500){const o=setInterval(e,s),r=setTimeout((()=>{clearInterval(o),t()}),a);n&&"function"==typeof n&&n(o,r)}((()=>{n((()=>{q(e)}))}),(()=>{q(e),browserApi.tabs.get(e,(async e=>{await h(e,t)}))}),((t,n)=>{const s={};s[e+"_saveInProgress"]=t,s[e+"_saveInProgressTimeoutId_"+t]=n,setStorage(s)}))}))}function w(e){return Promise.resolve(!0)}function A(e){new Promise((e=>{browserApi.tabs.query({active:!0,currentWindow:!0},(function(t){e(t[0]||null)}))})).then((t=>{browserApi.tabs.sendMessage(t.id,{action:ACTIONS.Ping},(async function(n){if(n&&n.pong)await w(t.id)&&e(t);else{const n=browserApi.runtime.getManifest().content_scripts,s=[...n[0].js,...n[1].js];!function(n,s,a){function o(e,t,n){return function(){browserScriptingApi.executeScript(e,t,n)}}let r=async function(){await w(t.id)&&e(t)};for(let e=s.length-1;e>=0;--e)r=o(n,{file:s[e]},r);null!==r&&r()}(t.id,s)}}))}))}browserApi.tabs.onActivated.addListener((({tabId:e})=>{!function t(){browserApi.tabs.get(e,(function(e){browserApi.runtime.lastError&&setTimeout(t,150)}))}()})),browserApi.tabs.onRemoved.addListener((e=>{!function(e){getStorage().then((function(t){const n=[],s=Object.keys(t),a=e+"_saveInProgress";for(let e=0;e{if(e.forwardToTab)return delete e.forwardToTab,void browserApi.tabs.sendRequest(t.tab.id,e);e.action===ACTIONS.EditTitle&&u.enqueue((()=>async function(e,t){const n=p[t.clientRequestId];return handled=await async function(e,t,n){return updatePageTitle(l+"graphql",n.responseId,t.title).then((()=>(y(e,"title","success","Title updated."),!0))).catch((t=>(console.log("caught error updating title: ",t),y(e,"title","failure","Error updating title."),!0)))}(e,t,n),console.log("processEditTitleRequest: ",handled),handled}(t.tab.id,{id:i(),type:"EDIT_TITLE",tabId:t.tab.id,title:e.payload.title,clientRequestId:e.payload.ctx.requestId}))),e.action===ACTIONS.Archive&&u.enqueue((()=>async function(e,t){const n=p[t.clientRequestId],s=await async function(e,t,n){return archive(l+"graphql",n.responseId).then((()=>(y(e,"extra","success","Archived"),!0))).catch((()=>(y(e,"extra","failure","Error archiving"),!0)))}(e,0,n);return console.log("processArchiveRequest: ",s),s}(t.tab.id,{id:i(),type:"ARCHIVE",tabId:t.tab.id,clientRequestId:e.payload.ctx.requestId}))),e.action===ACTIONS.Delete&&u.enqueue((()=>async function(e,t){const n=p[t.clientRequestId],s=await async function(e,t,n){return deleteItem(l+"graphql",n.responseId).then((()=>(y(e,"extra","success","Deleted"),!0))).catch((()=>(y(e,"extra","failure","Error deleting"),!0)))}(e,0,n);return console.log("processDeleteRequest: ",s),s}(t.tab.id,{type:"DELETE",tabId:t.tab.id,clientRequestId:e.payload.ctx.requestId}))),e.action===ACTIONS.AddNote&&u.enqueue((()=>async function(e,t){const n=p[t.clientRequestId],s=await async function(e,t,n){const s=i(),a=c(8);return addNote(l+"graphql",n.responseId,s,a,t.note).then((()=>(y(e,"note","success","Note updated."),!0))).catch((t=>(console.log("caught error updating title: ",t),y(e,"note","failure","Error adding note."),!0)))}(e,t,n);return console.log("processAddNoteRequest: ",s),s}(t.tab.id,{id:i(),type:"ADD_NOTE",tabId:t.tab.id,note:e.payload.note,clientRequestId:e.payload.ctx.requestId}))),e.action===ACTIONS.SetLabels&&u.enqueue((()=>async function(e,t){const n=p[t.clientRequestId],s=await async function(e,t,n){return setLabels(l+"graphql",n.responseId,t.labels).then((()=>(y(e,"labels","success","Labels updated."),!0))).then((()=>{browserApi.tabs.sendMessage(e,{action:ACTIONS.LabelCacheUpdated,payload:{}})})).catch((()=>(y(e,"labels","failure","Error updating labels."),!0)))}(e,t,n);return console.log("processSetLabelsRequest: ",s),s}(t.tab.id,{id:i(),type:"SET_LABELS",tabId:t.tab.id,labels:e.payload.labels,clientRequestId:e.payload.ctx.requestId})))})),browserApi.contextMenus.create({id:"save-link-selection",title:"Save this link to Omnivore",contexts:["link"],onclick:async function(e){A((async function(t){await f(t,e.linkUrl)}))}}),browserApi.contextMenus.create({id:"save-page-selection",title:"Save this page to Omnivore",contexts:["page"],onclick:async function(e){A((function(e){R(e.id)}))}}),browserApi.contextMenus.create({id:"save-text-selection",title:"Create Highlight and Save to Omnivore",contexts:["selection"],onclick:async function(e){A((function(e){R(e.id,!0)}))}})})(); \ No newline at end of file +(()=>{"use strict";var e,t=new Uint8Array(16);function n(){if(!e&&!(e="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return e(t)}const s=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;for(var a=[],o=0;o<256;++o)a.push((o+256).toString(16).substr(1));const r=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=(a[e[t+0]]+a[e[t+1]]+a[e[t+2]]+a[e[t+3]]+"-"+a[e[t+4]]+a[e[t+5]]+"-"+a[e[t+6]]+a[e[t+7]]+"-"+a[e[t+8]]+a[e[t+9]]+"-"+a[e[t+10]]+a[e[t+11]]+a[e[t+12]]+a[e[t+13]]+a[e[t+14]]+a[e[t+15]]).toLowerCase();if(!function(e){return"string"==typeof e&&s.test(e)}(n))throw TypeError("Stringified UUID is invalid");return n},i=function(e,t,s){var a=(e=e||{}).random||(e.rng||n)();if(a[6]=15&a[6]|64,a[8]=63&a[8]|128,t){s=s||0;for(var o=0;o<16;++o)t[s+o]=a[o];return t}return r(a)};let c=(e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce(((e,t)=>e+((t&=63)<36?t.toString(36):t<62?(t-26).toString(36).toUpperCase():t>62?"-":"_")),"");const d=new class{constructor(){this.queue=[],this.isRunning=!1,this.isReady=!1}enqueue(e){this.queue.push(e),this.isReady&&this.runNext()}async runNext(){if(this.isRunning||0===this.queue.length||!this.isReady)return;this.isRunning=!0;const e=this.queue.shift();try{await e()}catch(e){console.error("Task failed:",e)}finally{this.isRunning=!1,this.isReady&&this.runNext()}}setReady(){this.isReady=!0,this.runNext()}},u="https://omnivore.app",l="https://api-prod.omnivore.app/api/";let p={};async function g(e,t){const n=JSON.stringify({query:"mutation UploadFileRequest($input: UploadFileRequestInput!) {\n uploadFileRequest(input:$input) {\n ... on UploadFileRequestError {\n errorCodes\n }\n ... on UploadFileRequestSuccess {\n id\n createdPageId\n uploadSignedUrl\n }\n }\n }",variables:{input:{url:e,contentType:t,createPageEntry:!0}}}),s="uploadFileRequest",a=await gqlRequest(l+"graphql",n);if(!a[s].errorCodes)return a.uploadFileRequest;"UNAUTHORIZED"===a[s].errorCodes[0]?(browserApi.tabs.sendMessage(currentTab.id,{action:ACTIONS.UpdateStatus,payload:{target:"logged_out",status:"logged_out",message:"You are not logged in.",ctx:toolbarCtx}}),b()):browserApi.tabs.sendMessage(currentTab.id,{action:ACTIONS.UpdateStatus,payload:{status:"failure",message:"Unable to save page.",ctx:toolbarCtx}})}function b(){getStorageItem("postInstallClickComplete").then((e=>{e&&removeStorage("postInstallClickComplete")}))}async function I(e,t){const n=i();await f(e,SAVE_URL_QUERY,"saveUrl",{source:"extension",clientRequestId:n,url:encodeURI(t)})}async function f(e,t,n,s){const a={omnivoreURL:u,originalURL:s.url,requestId:s.clientRequestId};p[a.requestId]=void 0;const o=JSON.stringify({query:t,variables:{input:s}});browserApi.tabs.sendMessage(e.id,{action:ACTIONS.ShowToolbar,payload:{type:"loading",ctx:a}});try{const t=await gqlRequest(l+"graphql",o);if(t[n].errorCodes)return void("UNAUTHORIZED"===t[n].errorCodes[0]?(browserApi.tabs.sendMessage(e.id,{action:ACTIONS.UpdateStatus,payload:{target:"logged_out",status:"logged_out",message:"You are not logged in.",ctx:a}}),b()):browserApi.tabs.sendMessage(e.id,{action:ACTIONS.UpdateStatus,payload:{status:"failure",message:"Unable to save page.",ctx:a}}));const s=t[n]?t[n].url:void 0,r=t[n]?t[n].clientRequestId:void 0;browserApi.tabs.sendMessage(e.id,{action:ACTIONS.UpdateStatus,payload:{status:"success",target:"page",ctx:{readerURL:s,responseId:r,requestId:a.requestId}}}),p[a.requestId]={readerURL:s,responseId:r,requestId:a.requestId}}catch(e){console.log("error saving: ",e)}d.setReady()}function y(e,t,n,s){browserApi.tabs.sendMessage(e,{action:ACTIONS.UpdateStatus,payload:{target:t,status:n,message:s}})}async function h(e,t){browserApi.tabs.sendMessage(e.id,{action:ACTIONS.GetContent,payload:{createHighlight:t}},(async t=>{if(!t||"object"!=typeof t)return void await I(e,e.url);const n=i();var{type:s}=t;const{pageInfo:a,doc:o,uploadContentObjUrl:r}=t;switch("html"==s&&handleBackendUrl(e.url)&&(s="url"),s){case"html":await f(e,SAVE_PAGE_QUERY,"savePage",{source:"extension",clientRequestId:n,originalContent:o,title:a.title,url:encodeURI(e.url)});break;case"url":await f(e,SAVE_URL_QUERY,"saveUrl",{source:"extension",clientRequestId:n,url:encodeURI(e.url)});break;case"pdf":{const t=await async function(e,t,n,s,a){const o={omnivoreURL:u,originalURL:t,requestId:n};p[o.requestId]=void 0,browserApi.tabs.sendMessage(e.id,{action:ACTIONS.ShowToolbar,payload:{type:"loading",ctx:o}});const r=await g(t,s);console.log("done uploading pdf",r);const i=await function({id:e,uploadSignedUrl:t},n,s){return fetch(s).then((e=>e.blob())).then((e=>fetch(t,{method:"PUT",headers:{"Content-Type":n},body:e}))).catch((e=>{console.error("error uploading file",e)}))}(r,s,a);return URL.revokeObjectURL(a),i&&r.createdPageId&&(p[o.requestId]={requestId:o.requestId,responseId:r.createdPageId},browserApi.tabs.sendMessage(e.id,{action:ACTIONS.UpdateStatus,payload:{status:"success",target:"page",ctx:{requestId:o.requestId,responseId:r.createdPageId}}})),i}(e,encodeURI(e.url),n,a.contentType,r);if(!t||!t.id)return void await f(e,SAVE_URL_QUERY,"saveUrl",{source:"extension",clientRequestId:n,url:encodeURI(e.url)});break}}}))}async function w(e){const t=await getStorageItem(e+"_saveInProgress");if(!t)return;clearInterval(t);const n=await getStorageItem(e+"_saveInProgressTimeoutId_"+t);n&&clearTimeout(n)}function R(e,t){function n(n,s){browserApi.tabs.get(e,(async e=>{if("complete"!==e.status)browserApi.tabs.sendMessage(e.id,{action:ACTIONS.ShowMessage,payload:{type:"loading",text:"Page loading..."}}),s&&"function"==typeof s&&s();else{n&&"function"==typeof n&&n(),await h(e,t);try{await updateLabelsCache(l+"graphql",e),browserApi.tabs.sendMessage(e.id,{action:ACTIONS.LabelCacheUpdated,payload:{}})}catch(e){return void console.error("error fetching labels",e,l)}}}))}t=!!t,w(e),n(null,(()=>{!function(e,t,n,s=1e3,a=10500){const o=setInterval(e,s),r=setTimeout((()=>{clearInterval(o),t()}),a);n&&"function"==typeof n&&n(o,r)}((()=>{n((()=>{w(e)}))}),(()=>{w(e),browserApi.tabs.get(e,(async e=>{await h(e,t)}))}),((t,n)=>{const s={};s[e+"_saveInProgress"]=t,s[e+"_saveInProgressTimeoutId_"+t]=n,setStorage(s)}))}))}function q(e){return Promise.resolve(!0)}function A(e){new Promise((e=>{browserApi.tabs.query({active:!0,currentWindow:!0},(function(t){e(t[0]||null)}))})).then((t=>{browserApi.tabs.sendMessage(t.id,{action:ACTIONS.Ping},(async function(n){if(n&&n.pong)await q(t.id)&&e(t);else{const n=browserApi.runtime.getManifest().content_scripts,s=[...n[0].js,...n[1].js];!function(n,s,a){function o(e,t,n){return function(){browserScriptingApi.executeScript(e,t,n)}}let r=async function(){await q(t.id)&&e(t)};for(let e=s.length-1;e>=0;--e)r=o(n,{file:s[e]},r);null!==r&&r()}(t.id,s)}}))}))}browserApi.tabs.onActivated.addListener((({tabId:e})=>{!function t(){browserApi.tabs.get(e,(function(e){browserApi.runtime.lastError&&setTimeout(t,150)}))}()})),browserApi.tabs.onRemoved.addListener((e=>{!function(e){getStorage().then((function(t){const n=[],s=Object.keys(t),a=e+"_saveInProgress";for(let e=0;e{e?A((function(e){R(e.id)})):browserApi.tabs.sendMessage(currentTab.id,{action:ACTIONS.ShowToolbar,payload:{type:"noConsent",ctx:toolbarCtx}})})).catch((()=>{console.log("extension consent not granted"),browserApi.tabs.sendMessage(currentTab.id,{action:ACTIONS.ShowToolbar,payload:{type:"noConsent",ctx:toolbarCtx}})}))})),browserApi.runtime.onMessage.addListener(((e,t,n)=>{if(e.forwardToTab)return delete e.forwardToTab,void browserApi.tabs.sendRequest(t.tab.id,e);e.action===ACTIONS.EditTitle&&d.enqueue((()=>async function(e,t){const n=p[t.clientRequestId];return handled=await async function(e,t,n){return updatePageTitle(l+"graphql",n.responseId,t.title).then((()=>(y(e,"title","success","Title updated."),!0))).catch((t=>(console.log("caught error updating title: ",t),y(e,"title","failure","Error updating title."),!0)))}(e,t,n),console.log("processEditTitleRequest: ",handled),handled}(t.tab.id,{id:i(),type:"EDIT_TITLE",tabId:t.tab.id,title:e.payload.title,clientRequestId:e.payload.ctx.requestId}))),e.action===ACTIONS.Archive&&d.enqueue((()=>async function(e,t){const n=p[t.clientRequestId],s=await async function(e,t,n){return archive(l+"graphql",n.responseId).then((()=>(y(e,"extra","success","Archived"),!0))).catch((()=>(y(e,"extra","failure","Error archiving"),!0)))}(e,0,n);return console.log("processArchiveRequest: ",s),s}(t.tab.id,{id:i(),type:"ARCHIVE",tabId:t.tab.id,clientRequestId:e.payload.ctx.requestId}))),e.action===ACTIONS.Delete&&d.enqueue((()=>async function(e,t){const n=p[t.clientRequestId],s=await async function(e,t,n){return deleteItem(l+"graphql",n.responseId).then((()=>(y(e,"extra","success","Deleted"),!0))).catch((()=>(y(e,"extra","failure","Error deleting"),!0)))}(e,0,n);return console.log("processDeleteRequest: ",s),s}(t.tab.id,{type:"DELETE",tabId:t.tab.id,clientRequestId:e.payload.ctx.requestId}))),e.action===ACTIONS.AddNote&&d.enqueue((()=>async function(e,t){const n=p[t.clientRequestId],s=await async function(e,t,n){const s=i(),a=c(8);return addNote(l+"graphql",n.responseId,s,a,t.note).then((()=>(y(e,"note","success","Note updated."),!0))).catch((t=>(console.log("caught error updating title: ",t),y(e,"note","failure","Error adding note."),!0)))}(e,t,n);return console.log("processAddNoteRequest: ",s),s}(t.tab.id,{id:i(),type:"ADD_NOTE",tabId:t.tab.id,note:e.payload.note,clientRequestId:e.payload.ctx.requestId}))),e.action===ACTIONS.SetLabels&&d.enqueue((()=>async function(e,t){const n=p[t.clientRequestId],s=await async function(e,t,n){return setLabels(l+"graphql",n.responseId,t.labels).then((()=>(y(e,"labels","success","Labels updated."),!0))).then((()=>{browserApi.tabs.sendMessage(e,{action:ACTIONS.LabelCacheUpdated,payload:{}})})).catch((()=>(y(e,"labels","failure","Error updating labels."),!0)))}(e,t,n);return console.log("processSetLabelsRequest: ",s),s}(t.tab.id,{id:i(),type:"SET_LABELS",tabId:t.tab.id,labels:e.payload.labels,clientRequestId:e.payload.ctx.requestId})))})),browserApi.contextMenus.create({id:"save-link-selection",title:"Save this link to Omnivore",contexts:["link"],onclick:async function(e){A((async function(t){await I(t,e.linkUrl)}))}}),browserApi.contextMenus.create({id:"save-page-selection",title:"Save this page to Omnivore",contexts:["page"],onclick:async function(e){A((function(e){R(e.id)}))}}),browserApi.contextMenus.create({id:"save-text-selection",title:"Create Highlight and Save to Omnivore",contexts:["selection"],onclick:async function(e){A((function(e){R(e.id,!0)}))}}),browser.runtime.onInstalled.addListener((async({reason:e,temporary:t})=>{switch(console.log("onInstalled: ",e,t),e){case"update":case"install":{const e=browser.runtime.getURL("views/installed.html");await browser.tabs.create({url:e})}}}))})(); \ No newline at end of file diff --git a/apple/Sources/SafariExtension/Resources/scripts/content/toast.js b/apple/Sources/SafariExtension/Resources/scripts/content/toast.js index 7ee799643..3802c64ff 100644 --- a/apple/Sources/SafariExtension/Resources/scripts/content/toast.js +++ b/apple/Sources/SafariExtension/Resources/scripts/content/toast.js @@ -1 +1 @@ -!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 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 @@ + + + + + + + + + + diff --git a/pkg/extension/src/views/options.html b/pkg/extension/src/views/options.html index 6d94b26c6..81f10c6f1 100644 --- a/pkg/extension/src/views/options.html +++ b/pkg/extension/src/views/options.html @@ -46,6 +46,26 @@

+

 

+ +

Privacy

+ + + + +
    +
  • Tab Data: When you invoke the extension, we access the content of the page you are currently viewing. This allows us to save the full content of the page, exactly how you are viewing it. That data is then transmitted to our servers and added to your library
  • +
  • Authentication cookie: When you invoke the extension we access the auth cookie you used to authenticate at https://omnivore.app. This cookie identifies you as an Omnivore user and ties the saving operation to your Omnivore account.
  • +
+ + + + + + +