From 35afaa97da4bf720eabfb0804846ac66538e5da8 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Wed, 4 Oct 2023 11:13:23 +0800 Subject: [PATCH] Update the Safari extension --- apple/Omnivore.xcodeproj/project.pbxproj | 12 ++++++------ .../Sources/SafariExtension/Resources/manifest.json | 4 ++-- .../SafariExtension/Resources/scripts/background.js | 2 +- .../scripts/content/content-listener-script.js | 2 +- .../Resources/scripts/content/prepare-content.js | 2 +- .../Resources/scripts/content/toast.js | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/apple/Omnivore.xcodeproj/project.pbxproj b/apple/Omnivore.xcodeproj/project.pbxproj index cf37c62cd..a61592edc 100644 --- a/apple/Omnivore.xcodeproj/project.pbxproj +++ b/apple/Omnivore.xcodeproj/project.pbxproj @@ -1388,7 +1388,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 91; + CURRENT_PROJECT_VERSION = 94; DEAD_CODE_STRIPPING = YES; DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_TEAM = QJF2XZ86HB; @@ -1400,7 +1400,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 12.0; - MARKETING_VERSION = 1.32.0; + MARKETING_VERSION = 1.33.0; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = app.omnivore.app; @@ -1423,7 +1423,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 91; + CURRENT_PROJECT_VERSION = 94; DEAD_CODE_STRIPPING = YES; DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_TEAM = QJF2XZ86HB; @@ -1435,7 +1435,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 12.0; - MARKETING_VERSION = 1.32.0; + MARKETING_VERSION = 1.33.0; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = app.omnivore.app; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -1490,7 +1490,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.32.0; + MARKETING_VERSION = 1.33.0; PRODUCT_BUNDLE_IDENTIFIER = app.omnivore.app; PRODUCT_NAME = Omnivore; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -1831,7 +1831,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.32.0; + MARKETING_VERSION = 1.33.0; PRODUCT_BUNDLE_IDENTIFIER = app.omnivore.app; PRODUCT_NAME = Omnivore; PROVISIONING_PROFILE_SPECIFIER = ""; diff --git a/apple/Sources/SafariExtension/Resources/manifest.json b/apple/Sources/SafariExtension/Resources/manifest.json index 63789dae2..9781facf2 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.4.2", + "version": "2.6.2", "description": "Save PDFs and Articles to your Omnivore library", "author": "Omnivore Media, Inc", "default_locale": "en", @@ -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'; prefetch-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'; 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/", "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 0db7c28e2..4fc2a0b9d 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 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 w(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 A(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 q(e){new Promise((e=>{browserApi.tabs.query({active:!0,currentWindow:!0},(function(t){e(t[0]||null)}))})).then((t=>{console.log("currentTab: ",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)}}))}))}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 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 w(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)}}}))}A(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((()=>{A(e)}))}),(()=>{A(e),browserApi.tabs.get(e,(async e=>{await w(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.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))})),browserApi.contextMenus.create({id:"save-selection",title:"Save this link to Omnivore",contexts:["link"],onclick:async function(e){q((async function(t){await I(t,e.linkUrl)}))}})})(); \ 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 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 diff --git a/apple/Sources/SafariExtension/Resources/scripts/content/content-listener-script.js b/apple/Sources/SafariExtension/Resources/scripts/content/content-listener-script.js index 61105b124..4c59e5fb0 100644 --- a/apple/Sources/SafariExtension/Resources/scripts/content/content-listener-script.js +++ b/apple/Sources/SafariExtension/Resources/scripts/content/content-listener-script.js @@ -1 +1 @@ -"use strict";!function(){const e=window.matchMedia("(prefers-color-scheme: dark)");e&&(e.onchange=function(e){browserApi.runtime.sendMessage({action:ACTIONS.RefreshDarkMode,payload:{value:e.matches}})}),browserApi.runtime.onMessage.addListener((({action:e,payload:n},o,a)=>{if(e===ACTIONS.GetContent)return prepareContent().then((e=>{a({type:e.type,doc:e.content||"",uploadContentObjUrl:e.uploadContentObjUrl,pageInfo:getPageInfo()})})),!0;console.log("handling ",e,n),e===ACTIONS.Ping?a({pong:!0}):e===ACTIONS.ShowToolbar?showToolbar(n):e===ACTIONS.UpdateStatus?updateStatus(n):e===ACTIONS.LabelCacheUpdated?updateLabelsFromCache(n):e===ACTIONS.AddIframeContent||console.warn("Unknown message has been taken")}))}(); \ No newline at end of file +"use strict";!function(){const e=window.matchMedia("(prefers-color-scheme: dark)");e&&(e.onchange=function(e){browserApi.runtime.sendMessage({action:ACTIONS.RefreshDarkMode,payload:{value:e.matches}})}),browserApi.runtime.onMessage.addListener((({action:e,payload:n},t,o)=>{if(e===ACTIONS.GetContent){const e=n&&n.createHighlight;return prepareContent(e).then((e=>{o({type:e.type,doc:e.content||"",uploadContentObjUrl:e.uploadContentObjUrl,pageInfo:getPageInfo()})})),!0}console.log("handling ",e,n),e===ACTIONS.Ping?o({pong:!0}):e===ACTIONS.ShowToolbar?showToolbar(n):e===ACTIONS.UpdateStatus?updateStatus(n):e===ACTIONS.LabelCacheUpdated?updateLabelsFromCache(n):e===ACTIONS.AddIframeContent||console.warn("Unknown message has been taken")}))}(); \ No newline at end of file diff --git a/apple/Sources/SafariExtension/Resources/scripts/content/prepare-content.js b/apple/Sources/SafariExtension/Resources/scripts/content/prepare-content.js index 31fdcc15d..ef59e1f70 100644 --- a/apple/Sources/SafariExtension/Resources/scripts/content/prepare-content.js +++ b/apple/Sources/SafariExtension/Resources/scripts/content/prepare-content.js @@ -1 +1 @@ -"use strict";!function(){const e={};function t(t){const n=t.tagName.toLowerCase();if("iframe"===n){const n=e[t.src];if(!n)return;const o=document.createElement("div");o.className="omnivore-instagram-embed",o.innerHTML=n;const r=t.parentNode;if(!r)return;return void r.replaceChild(o,t)}if("img"===n||"image"===n){if(-1===window.getComputedStyle(t).getPropertyValue("filter").indexOf("blur("))return;return void t.remove()}const o=window.getComputedStyle(t),r=o.getPropertyValue("background-image");if(r&&"none"!==r)return;const i=o.getPropertyValue("filter");if(i&&-1!==i.indexOf("blur("))return void t.remove();if(t.src)return;if(t.innerHTML.length>24)return;const c=/url\("(.+?)"\)/gi,a=c.exec(r);c.lastIndex=0;const l=a&&a[1];if(!l)return;const s=document.createElement("img");s.src=l;const p=t.parentNode;p&&p.replaceChild(s,t)}function n(){const e=document.createElement("div");e.style.position="absolute",e.style.left="-2000px",e.style.zIndex="-2000",e.innerHTML=document.body.innerHTML,document.documentElement.appendChild(e),Array.from(e.getElementsByTagName("*")).forEach(t);const n=`${document.head.innerHTML}${e.innerHTML}`;return e.remove(),n}function o(){const e=document.querySelectorAll(".webext-omnivore-backdrop");for(let t=0;t{for(let t=0;t{if(t!==ACTIONS.AddIframeContent)return;const{url:i,content:c}=n;e[i]=c,r({})})),window.prepareContent=async function(){const e=await async function(){const e=".pdf"===window.location.pathname.slice(-4).toLowerCase(),t=-1!==["application/acrobat","application/pdf","application/x-pdf","applications/vnd.pdf","text/pdf","text/x-pdf"].indexOf(document.contentType);if(!e&&!t)return Promise.resolve(null);const n=document.querySelector("embed");return n&&"application/pdf"!==n.type?Promise.resolve(null):ENV_DOES_NOT_SUPPORT_BLOB_URL_ACCESS&&n.src?Promise.resolve({type:"url",uploadContentObjUrl:n.src}):new Promise(((e,t)=>{const n=new XMLHttpRequest;n.open("GET","",!0),n.responseType="blob",n.onload=function(n){200===this.status?e({type:"pdf",uploadContentObjUrl:URL.createObjectURL(this.response)}):t(n)},n.send()}))}();if(e)return e;const t=window.location.href;try{if(handleBackendUrl(t))return{type:"url"}}catch{console.log("error checking url")}return await async function(e){const t=document.scrollingElement||document.body,n=t.scrollTop,r=t.scrollHeight;o();const i=function(){const e=document.createElement("div");return e.className="webext-omnivore-backdrop",e.style.cssText="all: initial !important;\n position: fixed !important;\n top: 0 !important;\n right: 0 !important;\n bottom: 0 !important;\n left: 0 !important;\n z-index: 99999 !important;\n background: #fff !important;\n opacity: 0.8 !important;\n transition: opacity 0.3s !important;\n -webkit-backdrop-filter: blur(4px) !important;\n backdrop-filter: blur(4px) !important;\n ",e}();for(document.body.appendChild(i);t.scrollTop<=r-500&&window.location.href===e;){const e=t.scrollTop;if(t.scrollTop+=500,await new Promise((e=>{setTimeout(e,10)})),t.scrollTop===e)break}t.scrollTop=n,await new Promise((e=>{setTimeout(e,10)}))}(t),o(),{type:"html",content:n()}}}(); \ No newline at end of file +"use strict";!function(){const e={};function t(t){const n=t.tagName.toLowerCase();if("iframe"===n){const n=e[t.src];if(!n)return;const o=document.createElement("div");o.className="omnivore-instagram-embed",o.innerHTML=n;const r=t.parentNode;if(!r)return;return void r.replaceChild(o,t)}if("img"===n||"image"===n){if(-1===window.getComputedStyle(t).getPropertyValue("filter").indexOf("blur("))return;return void t.remove()}const o=window.getComputedStyle(t),r=o.getPropertyValue("background-image");if(r&&"none"!==r)return;const i=o.getPropertyValue("filter");if(i&&-1!==i.indexOf("blur("))return void t.remove();if(t.src)return;if(t.innerHTML.length>24)return;const a=/url\("(.+?)"\)/gi,c=a.exec(r);a.lastIndex=0;const l=c&&c[1];if(!l)return;const s=document.createElement("img");s.src=l;const d=t.parentNode;d&&d.replaceChild(s,t)}function n(){const e=document.createElement("div");e.style.position="absolute",e.style.left="-2000px",e.style.zIndex="-2000",e.innerHTML=document.body.innerHTML,document.documentElement.appendChild(e),Array.from(e.getElementsByTagName("*")).forEach(t);const n=`${document.head.innerHTML}${e.innerHTML}`;return e.remove(),n}browserApi.runtime.onMessage.addListener((({action:t,payload:n},o,r)=>{if(t!==ACTIONS.AddIframeContent)return;const{url:i,content:a}=n;e[i]=a,r({})}));const o=e=>{const t=/^(a|b|basefont|bdo|big|em|font|i|s|small|span|strike|strong|su[bp]|tt|u|code|mark)$/i;let n="";const o=r=>{let i=!1;const a=r instanceof HTMLElement?r:r.parentElement;if(a&&(i=window.getComputedStyle(a).whiteSpace.startsWith("pre")),3==r.nodeType){const e=i?r.nodeValue:r.nodeValue.replace(/\n/g,"");n+=e}else r!=e&&(t.test(r.tagName)||(n+="\n\n"));r.childNodes.forEach((function(e){o(e)}))};return o(e),n.trim()};function r(){const e=document.querySelectorAll(".webext-omnivore-backdrop");for(let t=0;t{for(let t=0;t{const n=new XMLHttpRequest;n.open("GET","",!0),n.responseType="blob",n.onload=function(n){200===this.status?e({type:"pdf",uploadContentObjUrl:URL.createObjectURL(this.response)}):t(n)},n.send()}))}();if(t)return t;const i=window.location.href;try{if(!e&&handleBackendUrl(i))return{type:"url"}}catch{console.log("error checking url")}if(console.log("get content: ",e),e){console.log("creating highlight while saving");const e=(()=>{try{const e=window.document.querySelectorAll('span[data-omnivore-highlight-start="true"],\n span[data-omnivore-highlight-end="true"]');for(let t=0;t{setTimeout(e,10)})),t.scrollTop===e)break}t.scrollTop=n,await new Promise((e=>{setTimeout(e,10)}))}(i),r(),{type:"html",content:n()}}}(); \ 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 72178c056..2e5b74219 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 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=f,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");p(e,t)}function p(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 f(e){switch(e.cancelBubble=!0,e.stopPropogation&&e.stopPropogation(),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");p(e,t),e.preventDefault();break}}}function b(){s(),c("#omnivore-add-note-row");const o=e.shadowRoot.querySelector("#omnivore-add-note-textarea");o&&(o.focus(),o.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:o.value}}))}),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(),e.stopPropogation()}}function g(){s(),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()}}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=f,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((()=>{x()}),1e3)}function h(e){browserApi.runtime.sendMessage({action:ACTIONS.Archive,payload:{ctx:t}}),e.preventDefault()}function y(e){browserApi.runtime.sendMessage({action:ACTIONS.Delete,payload:{ctx:t}}),e.preventDefault()}function C(){s(),c("#omnivore-extra-buttons-row")}function x(){e.remove(),e=void 0}function L(){window.open(new URL("/login",t.omnivoreURL),"_blank"),setTimeout(x,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: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:C},{id:"#omnivore-toast-close-btn",func:x},{id:"#omnivore-toast-login-btn",func:L},{id:"#omnivore-toast-archive-btn",func:h},{id:"#omnivore-toast-delete-btn",func:y}];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":w();break;case"l":v();break;case"m":C();break;case"t":g();break;case"n":e.preventDefault(),b()}e.cancelBubble=!0,e.stopPropogation&&e.stopPropogation()}))}(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())})),e.focus())}(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 +!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":o=setTimeout((function(){console.log("hiding: ",e,a),a||(e.remove(),e=void 0)}),2500),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=f,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 f(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 g(){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=f,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:g},{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(),g()}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