From b95dd08817f1fed4deb8a128ce6f582be4b3ff05 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Wed, 24 May 2023 17:42:32 +0800 Subject: [PATCH] Bump the extension up for Safari --- .../SafariExtension/Resources/manifest.json | 14 ++- .../Resources/scripts/background.js | 2 +- .../content/content-listener-script.js | 2 +- .../Resources/scripts/content/page-info.js | 2 +- .../scripts/content/prepare-content.js | 2 +- .../Resources/scripts/content/toast.js | 2 +- .../Resources/views/background.html | 3 +- .../Resources/views/cta-popup.html | 97 ++++++++++++++++++- 8 files changed, 112 insertions(+), 12 deletions(-) diff --git a/apple/Sources/SafariExtension/Resources/manifest.json b/apple/Sources/SafariExtension/Resources/manifest.json index e59fa2d65..fb0288f9a 100644 --- a/apple/Sources/SafariExtension/Resources/manifest.json +++ b/apple/Sources/SafariExtension/Resources/manifest.json @@ -2,8 +2,8 @@ "manifest_version": 2, "name": "Omnivore", "short_name": "Omnivore", - "version": "0.1.24", - "description": "Save articles to your Omnivore library", + "version": "2.0.2", + "description": "Save PDFs and Articles to your Omnivore library", "author": "Omnivore Media, Inc", "default_locale": "en", "developer": { @@ -44,6 +44,10 @@ "id": "save-extension@omnivore.app" } }, + "options_ui": { + "page": "/views/options.html", + "open_in_tab": true + }, "content_scripts": [ { "matches": [ @@ -51,10 +55,10 @@ "http://*/**" ], "js": [ - "/scripts/constants.js", + "/scripts/common.js", + "/scripts/content/toast.js", "/scripts/content/page-info.js", "/scripts/content/prepare-content.js", - "/scripts/content/toast.js", "/scripts/content/content-listener-script.js" ] }, @@ -89,6 +93,6 @@ } }, "web_accessible_resources": [ - "views/cta-popup.html" + "views/toast.html" ] } diff --git a/apple/Sources/SafariExtension/Resources/scripts/background.js b/apple/Sources/SafariExtension/Resources/scripts/background.js index 62ba715e6..0e759196d 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 o=/^(?:[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,s=function(e){return"string"==typeof e&&o.test(e)};for(var r=[],a=0;a<256;++a)r.push((a+256).toString(16).substr(1));const i=function(e,t,o){var a=(e=e||{}).random||(e.rng||n)();if(a[6]=15&a[6]|64,a[8]=63&a[8]|128,t){o=o||0;for(var i=0;i<16;++i)t[o+i]=a[i];return t}return function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=(r[e[t+0]]+r[e[t+1]]+r[e[t+2]]+r[e[t+3]]+"-"+r[e[t+4]]+r[e[t+5]]+"-"+r[e[t+6]]+r[e[t+7]]+"-"+r[e[t+8]]+r[e[t+9]]+"-"+r[e[t+10]]+r[e[t+11]]+r[e[t+12]]+r[e[t+13]]+r[e[t+14]]+r[e[t+15]]).toLowerCase();if(!s(n))throw TypeError("Stringified UUID is invalid");return n}(a)};let u;const c="https://omnivore.app",d="https://api-prod.omnivore.app/api/";function l(e){return new Promise((t=>{browserApi.storage.local.get(e,(n=>{const o=n&&n[e]||null;t(o)}))}))}function p(e){return new Promise((t=>{browserApi.storage.local.set(e,t)}))}function f(e){return new Promise((t=>{browserApi.storage.local.remove(e,t)}))}function g(e){e.setRequestHeader("Content-Type","application/json"),u&&e.setRequestHeader("Authorization",u)}function b(){l("postInstallClickComplete").then((e=>{e&&f("postInstallClickComplete")}))}async function w(e,t,n,o){return browserApi.tabs.sendMessage(e.id,{action:ACTIONS.ShowMessage,payload:{type:"loading",text:"Saving..."}}),new Promise(((s,r)=>{const a=new XMLHttpRequest;a.open("POST",d+"graphql",!0),g(a),a.onerror=e=>{r(e)},a.onload=()=>{try{const t=function(e,t,n){if(4===n.readyState){if(200===n.status){const{data:o}=JSON.parse(n.response),s=o[t];if(!s)return;if("errorCodes"in s){const t={text:descriptions[o.createArticle.errorCodes[0]]||"Unable to save page",type:"error"};return"UNAUTHORIZED"===s.errorCodes[0]&&(t.errorCode=401,t.url=c,b()),void browserApi.tabs.sendMessage(e.id,{action:ACTIONS.ShowMessage,payload:t})}const r=s.url;return browserApi.tabs.sendMessage(e.id,{action:ACTIONS.ShowMessage,payload:{text:"Saved to Omnivore",link:r??c+"/home",linkText:"Read Now",type:"success"}}),s}if(400===n.status)return void browserApi.tabs.sendMessage(e.id,{action:ACTIONS.ShowMessage,payload:{text:"Unable to save page",type:"error"}})}}(e,n,a);if(!t)return r();s(t)}catch(e){r(e)}};const i=JSON.stringify({query:t,variables:{input:o}});a.send(i)})).catch((t=>{console.log("error saving page",t),browserApi.tabs.sendMessage(e.id,{action:ACTIONS.ShowMessage,payload:{text:"Unable to save page",type:"error"}})}))}function y(e){browserApi.tabs.sendMessage(e.id,{action:ACTIONS.GetContent},(async t=>{if(!t||"object"!=typeof t)return;const n=i(),{type:o,pageInfo:s,doc:r,uploadContentObjUrl:a}=t;switch(o){case"html":await w(e,SAVE_PAGE_QUERY,"savePage",{source:"extension",clientRequestId:n,originalContent:r,title:s.title,url:encodeURI(e.url)});break;case"url":await w(e,SAVE_URL_QUERY,"saveUrl",{source:"extension",clientRequestId:n,url:encodeURI(e.url)});break;case"pdf":{const t=await function(e,t,n,o){return new Promise((s=>{const r=new XMLHttpRequest;r.onreadystatechange=async function(){if(4===r.readyState){if(200===r.status){const{data:t}=JSON.parse(r.response);if("errorCodes"in t.uploadFileRequest&&"UNAUTHORIZED"===t.uploadFileRequest.errorCodes[0]&&(b(),browserApi.tabs.sendMessage(e.id,{action:ACTIONS.ShowMessage,payload:{text:"Unable to save page",type:"error",errorCode:401,url:c}})),t.uploadFileRequest&&t.uploadFileRequest.id&&t.uploadFileRequest.createdPageId&&!("errorCodes"in t.uploadFileRequest)){const r=await function({id:e,uploadSignedUrl:t},n,o){return fetch(o).then((e=>e.blob())).then((o=>new Promise((s=>{const r=new XMLHttpRequest;r.open("PUT",t,!0),r.setRequestHeader("Content-Type",n),r.onerror=()=>{s(void 0)},r.onload=()=>{s({id:e})},r.send(o)})))).catch((e=>{console.error("error uploading file",e)}))}(t.uploadFileRequest,n,o);if(URL.revokeObjectURL(o),!r)return;const a=t.uploadFileRequest.createdPageId,i=c+"/article/sr/"+a;return browserApi.tabs.sendMessage(e.id,{action:ACTIONS.ShowMessage,payload:{text:"Saved to Omnivore",link:i,linkText:"Read Now",type:"success"}}),s(t.uploadFileRequest)}browserApi.tabs.sendMessage(e.id,{action:ACTIONS.ShowMessage,payload:{text:"Unable to save page",type:"error"}})}else 400===r.status&&browserApi.tabs.sendMessage(e.id,{action:ACTIONS.ShowMessage,payload:{text:"Unable to save page",type:"error"}});s(!1)}};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:t,contentType:n,createPageEntry:!0}}});r.open("POST",d+"graphql",!0),g(r),r.send(a)}))}(e,encodeURI(e.url),s.contentType,a);if(!t||!t.id)return void await w(e,SAVE_URL_QUERY,"saveUrl",{source:"extension",clientRequestId:n,url:encodeURI(e.url)});break}}}))}async function A(e){const t=await l(e+"_saveInProgress");if(!t)return;clearInterval(t);const n=await l(e+"_saveInProgressTimeoutId_"+t);n&&clearTimeout(n)}function h(e){return l("postInstallClickComplete").then((async t=>{if(t)return!0;if("undefined"!=typeof browser&&browser.runtime&&browser.runtime.sendNativeMessage){const e=await browser.runtime.sendNativeMessage("omnivore",{message:ACTIONS.GetAuthToken});e.authToken&&(u=e.authToken)}return new Promise((t=>{const n=new XMLHttpRequest;n.onreadystatechange=function(){if(4===n.readyState&&200===n.status){const{data:o}=JSON.parse(n.response);o.me?(p({postInstallClickComplete:!0}),t(!0)):(browserApi.tabs.sendMessage(e,{action:ACTIONS.ShowMessage,payload:{type:"loading",text:"Loading..."}}),browserApi.tabs.sendMessage(e,{action:ACTIONS.ShowMessage,payload:{text:"",type:"error",errorCode:401,url:c}}),t(null))}};const o=JSON.stringify({query:"{me{id}}"});n.open("POST",d+"graphql",!0),g(n),n.send(o)}))}))}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(n){if(n&&n.pong)await h(t.id)&&e(t);else{const n=browserApi.runtime.getManifest().content_scripts,o=[...n[0].js,...n[1].js];!function(n,o,s){function r(e,t,n){return function(){browserScriptingApi.executeScript(e,t,n)}}let a=async function(){await h(t.id)&&e(t)};for(let e=o.length-1;e>=0;--e)a=r(n,{file:o[e]},a);null!==a&&a()}(t.id,o)}}))}))}function v(e,t){let n="/images/toolbar/icon";if(ENV_IS_FIREFOX?n+="_firefox":ENV_IS_EDGE&&(n+="_edge"),e||(n+="_inactive"),("boolean"==typeof t?t:window.matchMedia("(prefers-color-scheme: dark)").matches)&&(n+="_dark"),ENV_IS_FIREFOX)return n+".svg";const o=["16","24","32","48"];ENV_IS_EDGE||o.push("19","38");const s={};for(let e=0;e{!function t(){browserApi.tabs.get(e,(function(e){browserApi.runtime.lastError&&setTimeout(t,150),I(e)}))}()})),browserApi.tabs.onUpdated.addListener(((e,t,n)=>{t.status&&n&&n.active&&I(n)})),browserApi.tabs.onRemoved.addListener((e=>{!function(e){new Promise((e=>{browserApi.storage.local.get(null,(t=>{e(t||{})}))})).then((function(t){const n=[],o=Object.keys(t),s=e+"_saveInProgress";for(let e=0;e{"complete"!==e.status?(browserApi.tabs.sendMessage(e.id,{action:ACTIONS.ShowMessage,payload:{type:"loading",text:"Page loading..."}}),n&&"function"==typeof n&&n()):(t&&"function"==typeof t&&t(),y(e))}))}A(e),t(null,(()=>{!function(e,t,n,o=1e3,s=10500){const r=setInterval(e,o),a=setTimeout((()=>{clearInterval(r),t()}),s);n&&"function"==typeof n&&n(r,a)}((()=>{t((()=>{A(e)}))}),(()=>{A(e),browserApi.tabs.get(e,(e=>{y(e)}))}),((t,n)=>{const o={};o[e+"_saveInProgress"]=t,o[e+"_saveInProgressTimeoutId_"+t]=n,p(o)}))}))}(e.id)}))})),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.RefreshDarkMode&&m(t.tab.id,e.payload.value)})),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 async function(e,t){const n=i();await w(e,SAVE_URL_QUERY,"saveUrl",{source:"extension",clientRequestId:n,url:encodeURI(t)})}(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 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 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 3574f6c05..61105b124 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,t)=>{if(e===ACTIONS.GetContent)return prepareContent().then((e=>{t({type:e.type,doc:e.content||"",uploadContentObjUrl:e.uploadContentObjUrl,pageInfo:getPageInfo()})})),!0;if(e===ACTIONS.Ping)t({pong:!0});else if(e===ACTIONS.ShowMessage)showMessage(n);else if(e===ACTIONS.GetPageInfo){const e=getPageInfo();t(e)}else 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},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 diff --git a/apple/Sources/SafariExtension/Resources/scripts/content/page-info.js b/apple/Sources/SafariExtension/Resources/scripts/content/page-info.js index 41ec55df8..f0ca67759 100644 --- a/apple/Sources/SafariExtension/Resources/scripts/content/page-info.js +++ b/apple/Sources/SafariExtension/Resources/scripts/content/page-info.js @@ -1 +1 @@ -"use strict";window.getPageInfo=function(){return{title:function(){const n=document.querySelector(SELECTORS.TITLE);return n&&n.content||document.title||""}(),canonicalUrl:function(){const n=window.location.href,t=document.querySelector(SELECTORS.CANONICAL_URL),e=t&&t.href;return e?new URL(e,n).href:n}(),contentType:document.contentType}}; \ No newline at end of file +"use strict";window.getPageInfo=function(){return{title:function(){const n=document.querySelector(SELECTORS.TITLE),t=n&&n.content;return document.title||t||""}(),canonicalUrl:function(){const n=window.location.href,t=document.querySelector(SELECTORS.CANONICAL_URL),e=t&&t.href;return e?new URL(e,n).href:n}(),contentType:document.contentType}}; \ 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 e35ba7142..a2eb658ee 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 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 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:a}=n;e[i]=a,r({})})),window.prepareContent=async function(){return 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()}))}()||(await async function(){const e=document.scrollingElement||document.body,t=e.scrollTop,n=e.scrollHeight;o();const r=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(r);e.scrollTop<=n-500;){const t=e.scrollTop;if(e.scrollTop+=500,await new Promise((e=>{setTimeout(e,10)})),e.scrollTop===t)break}e.scrollTop=t,await new Promise((e=>{setTimeout(e,10)}))}(),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 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 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);try{if("undefined"!=typeof create_time&&create_time){const t=new Date(1e3*create_time),n=document.createElement("div");n.className="omnivore-published-date",n.innerHTML=t.toLocaleString(),e.appendChild(n)}}catch(e){console.log("Error while trying to add published date to WeChat post",e)}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 diff --git a/apple/Sources/SafariExtension/Resources/scripts/content/toast.js b/apple/Sources/SafariExtension/Resources/scripts/content/toast.js index 125653cb1..e2eba1bd7 100644 --- a/apple/Sources/SafariExtension/Resources/scripts/content/toast.js +++ b/apple/Sources/SafariExtension/Resources/scripts/content/toast.js @@ -1 +1 @@ -"use strict";!function(){let t,n,e,o;function r(t){if(!e)return;if(!t)return void(e.textContent="");e.textContent=t.text||"";const n=t.link;if(!n)return;const o=document.createElement("a");n.startsWith("http")&&(o.href=n),o.target="_blank",o.rel="external nofollow noopener noreferrer",o.textContent=t.linkText||"link",o.style.cssText="all: initial !important;\n margin-left: 1rem !important;\n color: #0645ad !important;\n font: inherit !important;\n cursor: pointer !important;\n ",e.appendChild(o)}window.showMessage=function(i){const a=document.body;if(!a)return;let p=5e3;t||(t=function(){const t=document.createElement("div");return t.className="webext-omnivore-toast",t.style.cssText="all: initial !important;\n position: fixed !important;\n top: 20px !important;\n right: 45px !important;\n z-index: 9999999 !important;\n display: flex !important;\n align-items: center !important;\n justify-content: center !important;\n overflow: hidden !important;\n width: 240px !important;\n height: 80px !important;\n border-radius: 10px !important;\n background: #fff !important;\n color: #3d3d3d !important;\n fill: currentColor !important;\n font: 700 13px Inter, sans-serif !important;\n box-shadow: 0 1px 89px rgba(57, 59, 67, 0.25) !important;\n user-select: none !important;\n transition: all 300ms ease !important;\n ",t}()),n&&e||function(){t.textContent="";const o=document.createElementNS("http://www.w3.org/2000/svg","svg");o.setAttribute("viewBox","0 0 16 16"),o.setAttribute("xmlns","http://www.w3.org/2000/svg"),o.style.cssText="all: initial !important;\n height: 20px !important;\n width: 20px !important;\n margin-left: 24px !important;\n fill: inherit !important;\n color: inherit !important;\n ",n=o,t.appendChild(o);const r=document.createElement("div");r.style.cssText="all: initial !important;\n flex: 1 !important;\n padding: 0 24px !important;\n color: inherit !important;\n font: inherit !important;\n ",e=r,t.appendChild(r)}();let l=!1;if("loading"===i.type)p=2e4,n.innerHTML='',r(i);else if("error"!==i.type)n.innerHTML='',r(i);else if(i.errorCode&&401===i.errorCode){t.textContent="",t.style.setProperty("width","310px","important"),t.style.setProperty("height","auto","important"),n=null,e=null;const o=function(n){const e=document.createDocumentFragment(),o=function(){const n=document.createElement("button");n.style.cssText="all: initial !important;\n position: absolute !important;\n top: 8px !important;\n right: 8px !important;\n border: none !important;\n background: none !important;\n color: inherit !important;\n fill: inherit !important;\n outline: none !important;\n cursor: pointer !important;\n ";const e=document.createElementNS("http://www.w3.org/2000/svg","svg");return e.setAttribute("viewBox","0 0 16 16"),e.setAttribute("xmlns","http://www.w3.org/2000/svg"),e.style.cssText="all: initial !important;\n width: 16px !important;\n height: 16px !important;\n color: inherit !important;\n fill: inherit !important;\n ",e.addEventListener("click",(function(){t.remove()})),e.innerHTML='',n.appendChild(e),n}();e.appendChild(o);const r=document.createElement("iframe"),i="/views/cta-popup.html?url="+encodeURIComponent(n),a=ENV_EXTENSION_ORIGIN+i;return r.src=a,r.style.cssText="all: initial !important;\n width: 310px !important;\n height: 360px !important;\n ",e.appendChild(r),e}(i.url);t.appendChild(o),p=8e3}else l=!0,n.innerHTML='',r(i);const m=l?"#808080":"#fff",s=l?"#fff":"#3d3d3d";var c;t.style.setProperty("background",m,"important"),t.style.setProperty("color",s,"important"),t.parentNode!==a&&a.appendChild(t),c=p,o&&clearTimeout(o),o=setTimeout((function(){t.remove()}),c);const d=document.querySelectorAll(".webext-omnivore-toast");for(let n=0;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 diff --git a/apple/Sources/SafariExtension/Resources/views/background.html b/apple/Sources/SafariExtension/Resources/views/background.html index 07a7a0029..aaf8577f7 100644 --- a/apple/Sources/SafariExtension/Resources/views/background.html +++ b/apple/Sources/SafariExtension/Resources/views/background.html @@ -6,7 +6,8 @@ Omnivore background - + + diff --git a/apple/Sources/SafariExtension/Resources/views/cta-popup.html b/apple/Sources/SafariExtension/Resources/views/cta-popup.html index da7b74116..260725c08 100644 --- a/apple/Sources/SafariExtension/Resources/views/cta-popup.html +++ b/apple/Sources/SafariExtension/Resources/views/cta-popup.html @@ -7,7 +7,102 @@ - +