From fb3e64e1b5684809acdd1f78f212eb967da3be27 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Thu, 1 Jun 2023 09:15:10 +0800 Subject: [PATCH] Update Safari extension --- .../SafariExtension/Resources/images/toolbar/icon_firefox.svg | 2 +- .../Resources/images/toolbar/icon_firefox_dark.svg | 2 +- .../Resources/images/toolbar/icon_firefox_inactive.svg | 2 +- .../Resources/images/toolbar/icon_firefox_inactive_dark.svg | 2 +- apple/Sources/SafariExtension/Resources/manifest.json | 2 +- apple/Sources/SafariExtension/Resources/scripts/background.js | 2 +- .../Sources/SafariExtension/Resources/scripts/content/toast.js | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/apple/Sources/SafariExtension/Resources/images/toolbar/icon_firefox.svg b/apple/Sources/SafariExtension/Resources/images/toolbar/icon_firefox.svg index eba1dfd71..1917916ce 100644 --- a/apple/Sources/SafariExtension/Resources/images/toolbar/icon_firefox.svg +++ b/apple/Sources/SafariExtension/Resources/images/toolbar/icon_firefox.svg @@ -1,4 +1,4 @@ - + diff --git a/apple/Sources/SafariExtension/Resources/images/toolbar/icon_firefox_dark.svg b/apple/Sources/SafariExtension/Resources/images/toolbar/icon_firefox_dark.svg index e61a624e2..49dcf5e8b 100644 --- a/apple/Sources/SafariExtension/Resources/images/toolbar/icon_firefox_dark.svg +++ b/apple/Sources/SafariExtension/Resources/images/toolbar/icon_firefox_dark.svg @@ -1,4 +1,4 @@ - + diff --git a/apple/Sources/SafariExtension/Resources/images/toolbar/icon_firefox_inactive.svg b/apple/Sources/SafariExtension/Resources/images/toolbar/icon_firefox_inactive.svg index e739d8b47..49dcf5e8b 100644 --- a/apple/Sources/SafariExtension/Resources/images/toolbar/icon_firefox_inactive.svg +++ b/apple/Sources/SafariExtension/Resources/images/toolbar/icon_firefox_inactive.svg @@ -1,4 +1,4 @@ - + diff --git a/apple/Sources/SafariExtension/Resources/images/toolbar/icon_firefox_inactive_dark.svg b/apple/Sources/SafariExtension/Resources/images/toolbar/icon_firefox_inactive_dark.svg index a66b17c2a..49dcf5e8b 100644 --- a/apple/Sources/SafariExtension/Resources/images/toolbar/icon_firefox_inactive_dark.svg +++ b/apple/Sources/SafariExtension/Resources/images/toolbar/icon_firefox_inactive_dark.svg @@ -1,4 +1,4 @@ - + diff --git a/apple/Sources/SafariExtension/Resources/manifest.json b/apple/Sources/SafariExtension/Resources/manifest.json index fb0288f9a..de9fe4d60 100644 --- a/apple/Sources/SafariExtension/Resources/manifest.json +++ b/apple/Sources/SafariExtension/Resources/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 2, "name": "Omnivore", "short_name": "Omnivore", - "version": "2.0.2", + "version": "2.2.0", "description": "Save PDFs and Articles to your Omnivore library", "author": "Omnivore Media, Inc", "default_locale": "en", diff --git a/apple/Sources/SafariExtension/Resources/scripts/background.js b/apple/Sources/SafariExtension/Resources/scripts/background.js index 0e759196d..2622ae52e 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 a(){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 n=[],o=0;o<256;++o)n.push((o+256).toString(16).substr(1));const r=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,a=(n[e[t+0]]+n[e[t+1]]+n[e[t+2]]+n[e[t+3]]+"-"+n[e[t+4]]+n[e[t+5]]+"-"+n[e[t+6]]+n[e[t+7]]+"-"+n[e[t+8]]+n[e[t+9]]+"-"+n[e[t+10]]+n[e[t+11]]+n[e[t+12]]+n[e[t+13]]+n[e[t+14]]+n[e[t+15]]).toLowerCase();if(!function(e){return"string"==typeof e&&s.test(e)}(a))throw TypeError("Stringified UUID is invalid");return a},i=function(e,t,s){var n=(e=e||{}).random||(e.rng||a)();if(n[6]=15&n[6]|64,n[8]=63&n[8]|128,t){s=s||0;for(var o=0;o<16;++o)t[s+o]=n[o];return t}return r(n)},d="https://omnivore.app",c="https://api-prod.omnivore.app/api/";let u=[],l={};async function p(e,t){const a=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",n=await gqlRequest(c+"graphql",a);if(!n[s].errorCodes)return n.uploadFileRequest;"UNAUTHORIZED"===n[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}}),g()):browserApi.tabs.sendMessage(currentTab.id,{action:ACTIONS.UpdateStatus,payload:{status:"failure",message:"Unable to save page.",ctx:toolbarCtx}})}function g(){getStorageItem("postInstallClickComplete").then((e=>{e&&removeStorage("postInstallClickComplete")}))}async function f(e,t){const a=i();await b(e,SAVE_URL_QUERY,"saveUrl",{source:"extension",clientRequestId:a,url:encodeURI(t)})}async function b(e,t,a,s){const n={omnivoreURL:d,originalURL:s.url,requestId:s.clientRequestId};l[n.requestId]=void 0;const o=JSON.stringify({query:t,variables:{input:s}});browserApi.tabs.sendMessage(e.id,{action:ACTIONS.ShowToolbar,payload:{type:"loading",ctx:n}});try{const t=await gqlRequest(c+"graphql",o);if(t[a].errorCodes)return void("UNAUTHORIZED"===t[a].errorCodes[0]?(browserApi.tabs.sendMessage(e.id,{action:ACTIONS.UpdateStatus,payload:{target:"logged_out",status:"logged_out",message:"You are not logged in.",ctx:n}}),g()):browserApi.tabs.sendMessage(e.id,{action:ACTIONS.UpdateStatus,payload:{status:"failure",message:"Unable to save page.",ctx:n}}));const s=t[a]?t[a].url:void 0,r=t[a]?t[a].clientRequestId:void 0;browserApi.tabs.sendMessage(e.id,{action:ACTIONS.UpdateStatus,payload:{status:"success",target:"page",ctx:{readerURL:s,responseId:r,requestId:n.requestId}}}),l[n.requestId]={readerURL:s,responseId:r,requestId:n.requestId}}catch(e){console.log("error saving: ",e)}y(e.id)}function I(e,t,a,s){browserApi.tabs.sendMessage(e,{action:ACTIONS.UpdateStatus,payload:{target:t,status:a,message:s}})}async function y(e){u.filter((t=>t.tabId===e)).forEach((async t=>{let a=!1;const s=l[t.clientRequestId];if(s)switch(t.type){case"EDIT_TITLE":a=await async function(e,t,a){return updatePageTitle(c+"graphql",a.responseId,t.title).then((()=>(I(e,"title","success","Title updated."),!0))).catch((t=>(console.log("caught error updating title: ",t),I(e,"title","failure","Error updating title."),!0)))}(e,t,s);break;case"SET_LABELS":a=await async function(e,t,a){return setLabels(c+"graphql",a.responseId,t.labelIds).then((()=>(I(e,"labels","success","Labels updated."),!0))).catch((()=>(I(e,"labels","failure","Error updating labels."),!0)))}(e,t,s)}if(a){const e=u.findIndex((e=>t.id===e.id));e>-1&&u.splice(e,1)}}))}async function h(e){browserApi.tabs.sendMessage(e.id,{action:ACTIONS.GetContent},(async t=>{if(!t||"object"!=typeof t)return void await f(e,e.url);const a=i();var{type:s}=t;const{pageInfo:n,doc:o,uploadContentObjUrl:r}=t;switch("html"==s&&handleBackendUrl(e.url)&&(s="url"),s){case"html":await b(e,SAVE_PAGE_QUERY,"savePage",{source:"extension",clientRequestId:a,originalContent:o,title:n.title,url:encodeURI(e.url)});break;case"url":await b(e,SAVE_URL_QUERY,"saveUrl",{source:"extension",clientRequestId:a,url:encodeURI(e.url)});break;case"pdf":{const t=await async function(e,t,a,s,n){const o={omnivoreURL:d,originalURL:t,requestId:a};l[o.requestId]=void 0,browserApi.tabs.sendMessage(e.id,{action:ACTIONS.ShowToolbar,payload:{type:"loading",ctx:o}});const r=await p(t,s);console.log("done uploading pdf",r);const i=await function({id:e,uploadSignedUrl:t},a,s){return fetch(s).then((e=>e.blob())).then((e=>fetch(t,{method:"PUT",headers:{"Content-Type":a},body:e}))).catch((e=>{console.error("error uploading file",e)}))}(r,s,n);return console.log(" uploadFileResult: ",i),URL.revokeObjectURL(n),i&&r.createdPageId&&(l[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),a,n.contentType,r);if(!t||!t.id)return void await b(e,SAVE_URL_QUERY,"saveUrl",{source:"extension",clientRequestId:a,url:encodeURI(e.url)});break}}}))}async function w(e){const t=await getStorageItem(e+"_saveInProgress");if(!t)return;clearInterval(t);const a=await getStorageItem(e+"_saveInProgressTimeoutId_"+t);a&&clearTimeout(a)}function A(e){return getStorageItem("postInstallClickComplete").then((async e=>!0))}function S(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(a){if(a&&a.pong)await A(t.id)&&e(t);else{const a=browserApi.runtime.getManifest().content_scripts,s=[...a[0].js,...a[1].js];!function(a,s,n){function o(e,t,a){return function(){browserScriptingApi.executeScript(e,t,a)}}let r=async function(){await A(t.id)&&e(t)};for(let e=s.length-1;e>=0;--e)r=o(a,{file:s[e]},r);null!==r&&r()}(t.id,s)}}))}))}function v(e,t){let a="/images/toolbar/icon";if(ENV_IS_FIREFOX?a+="_firefox":ENV_IS_EDGE&&(a+="_edge"),e||(a+="_inactive"),("boolean"==typeof t?t:window.matchMedia("(prefers-color-scheme: dark)").matches)&&(a+="_dark"),ENV_IS_FIREFOX)return a+".svg";const s=["16","24","32","48"];ENV_IS_EDGE||s.push("19","38");const n={};for(let e=0;e{!function t(){browserApi.tabs.get(e,(function(e){browserApi.runtime.lastError&&setTimeout(t,150),U(e)}))}()})),browserApi.tabs.onUpdated.addListener(((e,t,a)=>{t.status&&a&&a.active&&U(a)})),browserApi.tabs.onRemoved.addListener((e=>{!function(e){getStorage().then((function(t){const a=[],s=Object.keys(t),n=e+"_saveInProgress";for(let e=0;e{if("complete"!==e.status)browserApi.tabs.sendMessage(e.id,{action:ACTIONS.ShowMessage,payload:{type:"loading",text:"Page loading..."}}),a&&"function"==typeof a&&a();else{t&&"function"==typeof t&&t(),await h(e);try{await updateLabelsCache(c+"graphql",e),browserApi.tabs.sendMessage(e.id,{action:ACTIONS.LabelCacheUpdated,payload:{}})}catch(e){return void console.error("error fetching labels",e,c)}}}))}w(e),t(null,(()=>{!function(e,t,a,s=1e3,n=10500){const o=setInterval(e,s),r=setTimeout((()=>{clearInterval(o),t()}),n);a&&"function"==typeof a&&a(o,r)}((()=>{t((()=>{w(e)}))}),(()=>{w(e),browserApi.tabs.get(e,(async e=>{await h(e)}))}),((t,a)=>{const s={};s[e+"_saveInProgress"]=t,s[e+"_saveInProgressTimeoutId_"+t]=a,setStorage(s)}))}))}(e.id)}))})),browserApi.runtime.onMessage.addListener(((e,t,a)=>{if(e.forwardToTab)return delete e.forwardToTab,void browserApi.tabs.sendRequest(t.tab.id,e);e.action===ACTIONS.RefreshDarkMode&&m(t.tab.id,e.payload.value),e.action===ACTIONS.EditTitle&&(u.push({id:i(),type:"EDIT_TITLE",tabId:t.tab.id,title:e.payload.title,clientRequestId:e.payload.ctx.requestId}),y(t.tab.id)),e.action===ACTIONS.SetLabels&&(u.push({id:i(),type:"SET_LABELS",tabId:t.tab.id,labelIds:e.payload.labelIds,clientRequestId:e.payload.ctx.requestId}),y(t.tab.id))})),browserActionApi.setIcon({path:v(!0)}),browserApi.contextMenus.create({id:"save-selection",title:"Save to Omnivore",contexts:["link"],onclick:async function(e){S((async function(t){await f(t,e.linkUrl)}))}})})(); \ No newline at end of file +(()=>{"use strict";var e,t=new Uint8Array(16);function a(){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 n=/^(?:[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 s=[],o=0;o<256;++o)s.push((o+256).toString(16).substr(1));const r=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,a=(s[e[t+0]]+s[e[t+1]]+s[e[t+2]]+s[e[t+3]]+"-"+s[e[t+4]]+s[e[t+5]]+"-"+s[e[t+6]]+s[e[t+7]]+"-"+s[e[t+8]]+s[e[t+9]]+"-"+s[e[t+10]]+s[e[t+11]]+s[e[t+12]]+s[e[t+13]]+s[e[t+14]]+s[e[t+15]]).toLowerCase();if(!function(e){return"string"==typeof e&&n.test(e)}(a))throw TypeError("Stringified UUID is invalid");return a},i=function(e,t,n){var s=(e=e||{}).random||(e.rng||a)();if(s[6]=15&s[6]|64,s[8]=63&s[8]|128,t){n=n||0;for(var o=0;o<16;++o)t[n+o]=s[o];return t}return r(s)};let d=(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 c="https://omnivore.app",u="https://api-prod.omnivore.app/api/";let l=[],p={};async function g(e,t){const a=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}}}),n="uploadFileRequest",s=await gqlRequest(u+"graphql",a);if(!s[n].errorCodes)return s.uploadFileRequest;"UNAUTHORIZED"===s[n].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 a=i();await f(e,SAVE_URL_QUERY,"saveUrl",{source:"extension",clientRequestId:a,url:encodeURI(t)})}async function f(e,t,a,n){const s={omnivoreURL:c,originalURL:n.url,requestId:n.clientRequestId};p[s.requestId]=void 0;const o=JSON.stringify({query:t,variables:{input:n}});browserApi.tabs.sendMessage(e.id,{action:ACTIONS.ShowToolbar,payload:{type:"loading",ctx:s}});try{const t=await gqlRequest(u+"graphql",o);if(t[a].errorCodes)return void("UNAUTHORIZED"===t[a].errorCodes[0]?(browserApi.tabs.sendMessage(e.id,{action:ACTIONS.UpdateStatus,payload:{target:"logged_out",status:"logged_out",message:"You are not logged in.",ctx:s}}),b()):browserApi.tabs.sendMessage(e.id,{action:ACTIONS.UpdateStatus,payload:{status:"failure",message:"Unable to save page.",ctx:s}}));const n=t[a]?t[a].url:void 0,r=t[a]?t[a].clientRequestId:void 0;browserApi.tabs.sendMessage(e.id,{action:ACTIONS.UpdateStatus,payload:{status:"success",target:"page",ctx:{readerURL:n,responseId:r,requestId:s.requestId}}}),p[s.requestId]={readerURL:n,responseId:r,requestId:s.requestId}}catch(e){console.log("error saving: ",e)}h(e.id)}function y(e,t,a,n){browserApi.tabs.sendMessage(e,{action:ACTIONS.UpdateStatus,payload:{target:t,status:a,message:n}})}async function h(e){l.filter((t=>t.tabId===e)).forEach((async t=>{let a=!1;const n=p[t.clientRequestId];if(n)switch(t.type){case"EDIT_TITLE":a=await async function(e,t,a){return updatePageTitle(u+"graphql",a.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);break;case"ADD_NOTE":a=await async function(e,t,a){const n=i(),s=d(8);return addNote(u+"graphql",a.responseId,n,s,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);break;case"SET_LABELS":a=await async function(e,t,a){return setLabels(u+"graphql",a.responseId,t.labelIds).then((()=>(y(e,"labels","success","Labels updated."),!0))).catch((()=>(y(e,"labels","failure","Error updating labels."),!0)))}(e,t,n);break;case"ARCHIVE":a=await async function(e,t,a){return archive(u+"graphql",a.responseId).then((()=>(y(e,"extra","success","Archived"),!0))).catch((()=>(y(e,"extra","failure","Error archiving"),!0)))}(e,0,n);break;case"DELETE":a=await async function(e,t,a){return deleteItem(u+"graphql",a.responseId).then((()=>(y(e,"extra","success","Deleted"),!0))).catch((()=>(y(e,"extra","failure","Error deleting"),!0)))}(e,0,n)}if(a){const e=l.findIndex((e=>t.id===e.id));e>-1&&l.splice(e,1)}}))}async function A(e){browserApi.tabs.sendMessage(e.id,{action:ACTIONS.GetContent},(async t=>{if(!t||"object"!=typeof t)return void await I(e,e.url);const a=i();var{type:n}=t;const{pageInfo:s,doc:o,uploadContentObjUrl:r}=t;switch("html"==n&&handleBackendUrl(e.url)&&(n="url"),n){case"html":await f(e,SAVE_PAGE_QUERY,"savePage",{source:"extension",clientRequestId:a,originalContent:o,title:s.title,url:encodeURI(e.url)});break;case"url":await f(e,SAVE_URL_QUERY,"saveUrl",{source:"extension",clientRequestId:a,url:encodeURI(e.url)});break;case"pdf":{const t=await async function(e,t,a,n,s){const o={omnivoreURL:c,originalURL:t,requestId:a};p[o.requestId]=void 0,browserApi.tabs.sendMessage(e.id,{action:ACTIONS.ShowToolbar,payload:{type:"loading",ctx:o}});const r=await g(t,n);console.log("done uploading pdf",r);const i=await function({id:e,uploadSignedUrl:t},a,n){return fetch(n).then((e=>e.blob())).then((e=>fetch(t,{method:"PUT",headers:{"Content-Type":a},body:e}))).catch((e=>{console.error("error uploading file",e)}))}(r,n,s);return console.log(" uploadFileResult: ",i),URL.revokeObjectURL(s),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),a,s.contentType,r);if(!t||!t.id)return void await f(e,SAVE_URL_QUERY,"saveUrl",{source:"extension",clientRequestId:a,url:encodeURI(e.url)});break}}}))}async function w(e){const t=await getStorageItem(e+"_saveInProgress");if(!t)return;clearInterval(t);const a=await getStorageItem(e+"_saveInProgressTimeoutId_"+t);a&&clearTimeout(a)}function S(e){return Promise.resolve(!0)}function v(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(a){if(a&&a.pong)await S(t.id)&&e(t);else{const a=browserApi.runtime.getManifest().content_scripts,n=[...a[0].js,...a[1].js];!function(a,n,s){function o(e,t,a){return function(){browserScriptingApi.executeScript(e,t,a)}}let r=async function(){await S(t.id)&&e(t)};for(let e=n.length-1;e>=0;--e)r=o(a,{file:n[e]},r);null!==r&&r()}(t.id,n)}}))}))}function R(e,t){let a="/images/toolbar/icon";if(ENV_IS_FIREFOX?a+="_firefox":ENV_IS_EDGE&&(a+="_edge"),e||(a+="_inactive"),("boolean"==typeof t?t:window.matchMedia("(prefers-color-scheme: dark)").matches)&&(a+="_dark"),ENV_IS_FIREFOX)return a+".svg";const n=["16","24","32","48"];ENV_IS_EDGE||n.push("19","38");const s={};for(let e=0;e{!function t(){browserApi.tabs.get(e,(function(e){browserApi.runtime.lastError&&setTimeout(t,150),q(e)}))}()})),browserApi.tabs.onUpdated.addListener(((e,t,a)=>{t.status&&a&&a.active&&q(a)})),browserApi.tabs.onRemoved.addListener((e=>{!function(e){getStorage().then((function(t){const a=[],n=Object.keys(t),s=e+"_saveInProgress";for(let e=0;e{if("complete"!==e.status)browserApi.tabs.sendMessage(e.id,{action:ACTIONS.ShowMessage,payload:{type:"loading",text:"Page loading..."}}),a&&"function"==typeof a&&a();else{t&&"function"==typeof t&&t(),await A(e);try{await updateLabelsCache(u+"graphql",e),browserApi.tabs.sendMessage(e.id,{action:ACTIONS.LabelCacheUpdated,payload:{}})}catch(e){return void console.error("error fetching labels",e,u)}}}))}w(e),t(null,(()=>{!function(e,t,a,n=1e3,s=10500){const o=setInterval(e,n),r=setTimeout((()=>{clearInterval(o),t()}),s);a&&"function"==typeof a&&a(o,r)}((()=>{t((()=>{w(e)}))}),(()=>{w(e),browserApi.tabs.get(e,(async e=>{await A(e)}))}),((t,a)=>{const n={};n[e+"_saveInProgress"]=t,n[e+"_saveInProgressTimeoutId_"+t]=a,setStorage(n)}))}))}(e.id)}))})),browserApi.runtime.onMessage.addListener(((e,t,a)=>{if(e.forwardToTab)return delete e.forwardToTab,void browserApi.tabs.sendRequest(t.tab.id,e);e.action===ACTIONS.RefreshDarkMode&&m(t.tab.id,e.payload.value),e.action===ACTIONS.EditTitle&&(l.push({id:i(),type:"EDIT_TITLE",tabId:t.tab.id,title:e.payload.title,clientRequestId:e.payload.ctx.requestId}),h(t.tab.id)),e.action===ACTIONS.Archive&&(l.push({id:i(),type:"ARCHIVE",tabId:t.tab.id,clientRequestId:e.payload.ctx.requestId}),h(t.tab.id)),e.action===ACTIONS.Delete&&(l.push({type:"DELETE",tabId:t.tab.id,clientRequestId:e.payload.ctx.requestId}),h(t.tab.id)),e.action===ACTIONS.AddNote&&(l.push({id:i(),type:"ADD_NOTE",tabId:t.tab.id,note:e.payload.note,clientRequestId:e.payload.ctx.requestId}),h(t.tab.id)),e.action===ACTIONS.SetLabels&&(l.push({id:i(),type:"SET_LABELS",tabId:t.tab.id,labelIds:e.payload.labelIds,clientRequestId:e.payload.ctx.requestId}),h(t.tab.id))})),browserActionApi.setIcon({path:R(!0)}),browserApi.contextMenus.create({id:"save-selection",title:"Save to Omnivore",contexts:["link"],onclick:async function(e){v((async function(t){await I(t,e.linkUrl)}))}})})(); \ 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 e2eba1bd7..000920040 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 r={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 i(){a=!0,o&&clearTimeout(o)}function s(o){if(e)switch(o.ctx&&(t={...t,...o.ctx}),o.target){case"logged_out":i(),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"].forEach((t=>{e.shadowRoot.querySelector(t).disabled=!0}));break;case"page":l(o.status);break;case"title":d("#omnivore-edit-title-status",o.status,o.message,"success"==o.status?2500:void 0);break;case"labels":d("#omnivore-edit-labels-status",o.status,o.message,"success"==o.status?2500:void 0)}else console.log("no statusBox to update")}function l(t){const n=e.shadowRoot.querySelector(".omnivore-toast-statusBox");switch(t){case"loading":n.innerHTML=r.animatedLoader;break;case"success":o=setTimeout((function(){console.log("hiding: ",e,a),a||(e.remove(),e=void 0)}),2500),n.innerHTML=r.success;break;case"failure":n.innerHTML=r.failure}}function d(t,o,n,a){const i=e.shadowRoot.querySelector(t),s=(()=>{switch(o){case"loading":return r.animatedLoader;case"success":return r.success;case"failure":return r.failure;case"none":return"";default:return}})();i.innerHTML=s?`${s}${n}`:n,a&&setTimeout((()=>{i.innerHTML=null}),a)}function c(t){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,t){const o=document.createElement("button"),n=document.createElement("span");n.style="width:10px;height:10px;border-radius:1000px;",n.style.setProperty("background-color",e.color);const a=document.createElement("span");a.style="margin-left: 10px;pointer-events: none;",a.innerText=e.name;const r=document.createElement("span");return r.style="margin-left: auto;pointer-events: none;",r.className="checkbox",r.innerHTML='\n \n \n \n ',o.appendChild(n),o.appendChild(a),o.appendChild(r),o.onclick=f,o.onkeydown=p,o.setAttribute("data-label-id",e.id),o.setAttribute("data-label-idx",t),o.setAttribute("data-label-selected",e.selected?"on":"off"),o.setAttribute("tabIndex","-1"),o}function f(e){e.preventDefault();const t=e.target.getAttribute("data-label-id");m(e,t)}function m(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 r=n.find((e=>e.id===t));r&&(r.selected=a)}function p(e){switch(e.key.toLowerCase()){case"arrowup":{if(e.target==e.target.form.querySelector("#omnivore-edit-label-text"))return;const t=e.target.getAttribute("data-label-idx");let o=t&&NaN!=Number(t)?Number(t)-1:0;if(e.target==e.target.form.querySelector("#omnivore-save-button")){const t=Math.max(...Array.from(e.target.form.querySelectorAll("button[data-label-idx]")).map((e=>Number(e.getAttribute("data-label-idx")))));NaN!=t&&(o=t)}const n=e.target.form.querySelector(`button[data-label-idx='${o}']`);n?n.focus():e.target.form.querySelector("#omnivore-edit-label-text")?.focus(),e.preventDefault();break}case"arrowdown":{const t=e.target.getAttribute("data-label-idx"),o=t&&NaN!=Number(t)?Number(t)+1:0,n=e.target.form.querySelector(`button[data-label-idx='${o}']`);n?n.focus():e.target.form.querySelector(".omnivore-save-button")?.focus(),e.preventDefault();break}case"enter":{const t=e.target.getAttribute("data-label-id");m(e,t),e.preventDefault();break}}}function b(){i(),c("#omnivore-edit-title-row"),e.shadowRoot.querySelector("#omnivore-edit-title-textarea")?.focus(),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()}}async function g(){i(),await getStorageItem("labels").then((e=>{n=e})),c("#omnivore-edit-labels-row"),e.shadowRoot.querySelector("#omnivore-edit-label-text")?.focus();const o=e.shadowRoot.querySelector("#omnivore-edit-labels-list");e.shadowRoot.querySelector("#omnivore-edit-label-text").addEventListener("input",(function(){!async function(t){const o=e.shadowRoot.querySelector("#omnivore-edit-labels-list");o&&(o.innerHTML="",t?n.filter((e=>e.name.toLowerCase().indexOf(t.toLowerCase())>-1)).forEach((function(e,t){const n=u(e,t);o.appendChild(n)})):n.forEach((function(e,t){const n=u(e,t);o.appendChild(n)})))}(this.value)})),e.shadowRoot.querySelector("#omnivore-edit-label-text").onkeydown=p,o&&(o.innerHTML="",n.forEach((function(e,t){const n=u(e,t);o.appendChild(n)}))),e.shadowRoot.querySelector("#omnivore-edit-labels-form").onsubmit=o=>{o.preventDefault(),e.shadowRoot.querySelector("#omnivore-edit-labels-status").innerText="Updating labels...";const a=n.filter((e=>e.selected)).map((e=>e.id));browserApi.runtime.sendMessage({action:ACTIONS.SetLabels,payload:{ctx:t,labelIds:a}})}}function w(){i(),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((()=>{v()}),1e3)}function h(){i(),c("omnivore-extra-buttons-row")}function v(){e.remove(),e=void 0}function C(){window.open(new URL("/login",t.omnivoreURL),"_blank"),setTimeout(v,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.attachShadow({mode:"open"}),o.shadowRoot&&(o.shadowRoot.innerHTML="");const n=document.createElement("div");return n.id="#omnivore-toast",n.innerHTML=t,o.shadowRoot.appendChild(n),document.body.appendChild(o),function(e){const t=[{id:"#omnivore-toast-edit-title-btn",func:b},{id:"#omnivore-toast-edit-labels-btn",func:g},{id:"#omnivore-toast-read-now-btn",func:w},{id:"#omnivore-open-menu-btn",func:h},{id:"#omnivore-toast-close-btn",func:v},{id:"#omnivore-toast-login-btn",func:C}];for(const o of t){const t=e.shadowRoot.querySelector(o.id);t&&t.addEventListener("click",o.func)}}(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())})))}(o).catch((e=>console.log("error showing toast",e)))},window.updateStatus=s,window.updateLabelsFromCache=function(e){(async()=>{await getStorageItem("labels").then((e=>{n=e,console.log(" == updated labels",e)}))})()}}(); \ No newline at end of file +!function(){let e,t,o,n=[],a=!1;const r={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 s(){a=!0,o&&clearTimeout(o)}function i(o){if(e)switch(o.ctx&&(t={...t,...o.ctx}),o.target){case"logged_out":s(),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=r.animatedLoader;break;case"success":o=setTimeout((function(){console.log("hiding: ",e,a),a||(e.remove(),e=void 0)}),2500),n.innerHTML=r.success;break;case"failure":n.innerHTML=r.failure}}function d(t,o,n,a){const s=e.shadowRoot.querySelector(t),i=(()=>{switch(o){case"loading":return r.animatedLoader;case"success":return r.success;case"failure":return r.failure;case"none":return"";default:return}})();s.innerHTML=i?`${i}${n}`:n,a&&setTimeout((()=>{s.innerHTML=""}),a)}function c(t){console.log("currentToastEl: ",e);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,t){const o=document.createElement("button"),n=document.createElement("span");n.style="width:10px;height:10px;border-radius:1000px;",n.style.setProperty("background-color",e.color);const a=document.createElement("span");a.style="margin-left: 10px;pointer-events: none;",a.innerText=e.name;const r=document.createElement("span");return r.style="margin-left: auto;pointer-events: none;",r.className="checkbox",r.innerHTML='\n \n \n \n ',o.appendChild(n),o.appendChild(a),o.appendChild(r),o.onclick=m,o.onkeydown=p,o.setAttribute("data-label-id",e.id),o.setAttribute("data-label-idx",t),o.setAttribute("data-label-selected",e.selected?"on":"off"),o.setAttribute("tabIndex","-1"),o}function m(e){e.preventDefault();const t=e.target.getAttribute("data-label-id");f(e,t)}function f(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 r=n.find((e=>e.id===t));r&&(r.selected=a)}function p(e){switch(e.key.toLowerCase()){case"arrowup":{if(e.target==e.target.form.querySelector("#omnivore-edit-label-text"))return;const t=e.target.getAttribute("data-label-idx");let o=t&&NaN!=Number(t)?Number(t)-1:0;if(e.target==e.target.form.querySelector("#omnivore-save-button")){const t=Math.max(...Array.from(e.target.form.querySelectorAll("button[data-label-idx]")).map((e=>Number(e.getAttribute("data-label-idx")))));NaN!=t&&(o=t)}const n=e.target.form.querySelector(`button[data-label-idx='${o}']`);n?n.focus():e.target.form.querySelector("#omnivore-edit-label-text")?.focus(),e.preventDefault();break}case"arrowdown":{const t=e.target.getAttribute("data-label-idx"),o=t&&NaN!=Number(t)?Number(t)+1:0,n=e.target.form.querySelector(`button[data-label-idx='${o}']`);n?n.focus():e.target.form.querySelector(".omnivore-save-button")?.focus(),e.preventDefault();break}case"enter":{const t=e.target.getAttribute("data-label-id");f(e,t),e.preventDefault();break}}}function b(){s(),c("#omnivore-add-note-row"),e.shadowRoot.querySelector("#omnivore-add-note-textarea")?.focus(),e.shadowRoot.querySelector("#omnivore-add-note-form").onsubmit=e=>{console.log("submitting form: ",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()}}function g(){console.log("editing title"),s(),c("#omnivore-edit-title-row"),e.shadowRoot.querySelector("#omnivore-edit-title-textarea")?.focus(),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()}}async function v(){s(),await getStorageItem("labels").then((e=>{n=e})),c("#omnivore-edit-labels-row"),e.shadowRoot.querySelector("#omnivore-edit-label-text")?.focus();const o=e.shadowRoot.querySelector("#omnivore-edit-labels-list");e.shadowRoot.querySelector("#omnivore-edit-label-text").addEventListener("input",(function(){!async function(t){const o=e.shadowRoot.querySelector("#omnivore-edit-labels-list");o&&(o.innerHTML="",t?n.filter((e=>e.name.toLowerCase().indexOf(t.toLowerCase())>-1)).forEach((function(e,t){const n=u(e,t);o.appendChild(n)})):n.forEach((function(e,t){const n=u(e,t);o.appendChild(n)})))}(this.value)})),e.shadowRoot.querySelector("#omnivore-edit-label-text").onkeydown=p,o&&(o.innerHTML="",n.forEach((function(e,t){const n=u(e,t);o.appendChild(n)}))),e.shadowRoot.querySelector("#omnivore-edit-labels-form").onsubmit=o=>{o.preventDefault(),e.shadowRoot.querySelector("#omnivore-edit-labels-status").innerText="Updating labels...";const a=n.filter((e=>e.selected)).map((e=>e.id));browserApi.runtime.sendMessage({action:ACTIONS.SetLabels,payload:{ctx:t,labelIds:a}})}}function w(){s(),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((()=>{L()}),1e3)}function h(e){browserApi.runtime.sendMessage({action:ACTIONS.Archive,payload:{ctx:t}}),e.preventDefault()}function C(e){browserApi.runtime.sendMessage({action:ACTIONS.Delete,payload:{ctx:t}}),e.preventDefault()}function y(){s(),c("#omnivore-extra-buttons-row")}function L(){e.remove(),e=void 0}function x(){window.open(new URL("/login",t.omnivoreURL),"_blank"),setTimeout(L,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.attachShadow({mode:"open"}),o.shadowRoot&&(o.shadowRoot.innerHTML="");const n=document.createElement("div");return n.id="#omnivore-toast",n.innerHTML=t,o.shadowRoot.appendChild(n),document.body.appendChild(o),function(e){const t=[{id:"#omnivore-toast-add-note-btn",func:b},{id:"#omnivore-toast-edit-title-btn",func:g},{id:"#omnivore-toast-edit-labels-btn",func:v},{id:"#omnivore-toast-read-now-btn",func:w},{id:"#omnivore-open-menu-btn",func:y},{id:"#omnivore-toast-close-btn",func:L},{id:"#omnivore-toast-login-btn",func:x},{id:"#omnivore-toast-archive-btn",func:h},{id:"#omnivore-toast-delete-btn",func:C}];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),o}()),"loading"===t.type&&i({status:"loading",target:"page"}),document.querySelectorAll("#omnivore-toast").forEach((t=>{t!==e&&(console.log("removing current toast el: ",e),t.remove())})))}(o).catch((e=>console.log("error showing toast",e)))},window.updateStatus=i,window.updateLabelsFromCache=function(e){(async()=>{await getStorageItem("labels").then((e=>{n=e,console.log(" == updated labels",e)}))})()}}(); \ No newline at end of file