mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Merge pull request #77 from omnivore-app/fix/safari-pdf-upload-handler
On Safari fallback to SaveURL for PDFs
This commit is contained in:
commit
aae3250410
8 changed files with 37 additions and 26 deletions
|
|
@ -2,7 +2,7 @@
|
|||
"manifest_version": 2,
|
||||
"name": "Omnivore",
|
||||
"short_name": "Omnivore",
|
||||
"version": "0.1.20",
|
||||
"version": "0.1.22",
|
||||
"description": "Save articles to your Omnivore library",
|
||||
"author": "Omnivore Media, Inc",
|
||||
"default_locale": "en",
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -1 +1 @@
|
|||
"use strict";window.browserApi="object"==typeof chrome&&chrome&&chrome.runtime&&chrome||"object"==typeof browser&&browser||{},window.browserActionApi=browserApi.action||browserApi.browserAction||browserApi.pageAction,window.browserScriptingApi=browserApi.scripting||browserApi.tabs,window.ENV_EXTENSION_ORIGIN=browserApi.runtime.getURL("PATH/").replace("/PATH/",""),window.ENV_IS_FIREFOX=ENV_EXTENSION_ORIGIN.startsWith("moz-extension://"),window.ENV_IS_EDGE=navigator.userAgent.toLowerCase().indexOf("edg")>-1,window.SELECTORS={CANONICAL_URL:["head > link[rel='canonical']"],TITLE:["head > meta[property='og:title']"]},window.ACTIONS={ShowMessage:"SHOW_MESSAGE",GetContent:"GET_CONTENT",GetPageInfo:"GET_PAGE_INFO",Ping:"PING",AddIframeContent:"ADD_IFRAME_CONTENT",RefreshDarkMode:"REFRESH_DARK_MODE",GetAuthToken:"GET_AUTH_TOKEN"},window.DONT_REMOVE_ELEMENTS=["meta","script","title"],window.CREATE_ARTICLE_QUERY="mutation CreateArticle ($input: CreateArticleInput!){\n createArticle(input:$input){\n ... on CreateArticleSuccess{\n createdArticle{\n id\n title\n slug\n hasContent\n }\n user {\n id\n profile {\n id\n username\n }\n }\n}\n ... on CreateArticleError{\n errorCodes\n }\n}\n}",window.CREATE_ARTICLE_SAVING_REQUEST_QUERY="mutation CreateArticleSavingRequest ($input: CreateArticleSavingRequestInput!){\n createArticleSavingRequest(input:$input){\n ... on CreateArticleSavingRequestSuccess{\n articleSavingRequest{\n id\n }\n }\n ... on CreateArticleSavingRequestError{\n errorCodes\n }\n }\n}";
|
||||
"use strict";window.browserApi="object"==typeof chrome&&chrome&&chrome.runtime&&chrome||"object"==typeof browser&&browser||{},window.browserActionApi=browserApi.action||browserApi.browserAction||browserApi.pageAction,window.browserScriptingApi=browserApi.scripting||browserApi.tabs,window.ENV_EXTENSION_ORIGIN=browserApi.runtime.getURL("PATH/").replace("/PATH/",""),window.ENV_IS_FIREFOX=ENV_EXTENSION_ORIGIN.startsWith("moz-extension://"),window.ENV_IS_EDGE=navigator.userAgent.toLowerCase().indexOf("edg")>-1,window.ENV_DOES_NOT_SUPPORT_BLOB_URL_ACCESS=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),window.SELECTORS={CANONICAL_URL:["head > link[rel='canonical']"],TITLE:["head > meta[property='og:title']"]},window.ACTIONS={ShowMessage:"SHOW_MESSAGE",GetContent:"GET_CONTENT",GetPageInfo:"GET_PAGE_INFO",Ping:"PING",AddIframeContent:"ADD_IFRAME_CONTENT",RefreshDarkMode:"REFRESH_DARK_MODE",GetAuthToken:"GET_AUTH_TOKEN"},window.DONT_REMOVE_ELEMENTS=["meta","script","title"],window.CREATE_ARTICLE_QUERY="mutation CreateArticle ($input: CreateArticleInput!){\n createArticle(input:$input){\n ... on CreateArticleSuccess{\n createdArticle{\n id\n title\n slug\n hasContent\n }\n user {\n id\n profile {\n id\n username\n }\n }\n}\n ... on CreateArticleError{\n errorCodes\n }\n}\n}",window.CREATE_ARTICLE_SAVING_REQUEST_QUERY="mutation CreateArticleSavingRequest ($input: CreateArticleSavingRequestInput!){\n createArticleSavingRequest(input:$input){\n ... on CreateArticleSavingRequestSuccess{\n articleSavingRequest{\n id\n }\n }\n ... on CreateArticleSavingRequestError{\n errorCodes\n }\n }\n}";
|
||||
|
|
@ -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),console.log("\n\nStarting evaluation!"),Array.from(e.getElementsByTagName("*")).forEach(t);const n=`<head>${document.head.innerHTML}</head><body>${e.innerHTML}</body>`;return e.remove(),n}function o(){const e=document.querySelectorAll(".webext-omnivore-backdrop");for(let t=0;t<e.length;t++)e[t].style.setProperty("opacity","0","important");setTimeout((()=>{for(let t=0;t<e.length;t++)e[t].remove()}),500)}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({})})),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):new Promise(((e,t)=>{const n=new XMLHttpRequest;n.open("GET","",!0),n.responseType="blob",n.onload=function(n){200===this.status?e(URL.createObjectURL(this.response)):t(n)},n.send()}))}();return e?{type:"pdf",uploadContentObjUrl:e}:(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()})}}();
|
||||
"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=`<head>${document.head.innerHTML}</head><body>${e.innerHTML}</body>`;return e.remove(),n}function o(){const e=document.querySelectorAll(".webext-omnivore-backdrop");for(let t=0;t<e.length;t++)e[t].style.setProperty("opacity","0","important");setTimeout((()=>{for(let t=0;t<e.length;t++)e[t].remove()}),500)}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({})})),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()})}}();
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
"manifest_version": 2,
|
||||
"name": "process.env.EXTENSION_NAME",
|
||||
"short_name": "process.env.EXTENSION_NAME",
|
||||
"version": "0.1.20",
|
||||
"version": "0.1.22",
|
||||
"description": "Save articles to your Omnivore library",
|
||||
"author": "Omnivore Media, Inc",
|
||||
"default_locale": "en",
|
||||
|
|
|
|||
|
|
@ -73,6 +73,10 @@ function uploadFile ({ id, uploadSignedUrl }, contentType, contentObjUrl) {
|
|||
};
|
||||
xhr.send(blob);
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('error uploading file', err)
|
||||
return undefined
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -260,18 +264,24 @@ function saveArticle (tab) {
|
|||
|
||||
let uploadResult = null;
|
||||
|
||||
if (type === 'pdf') {
|
||||
// For PDF articles, we first upload the PDF file before passing the upload file ID in createArticle
|
||||
uploadResult = await savePdfFile(tab, encodeURI(tab.url), pageInfo.contentType, uploadContentObjUrl);
|
||||
if (!uploadResult || !uploadResult.id) {
|
||||
browserApi.tabs.sendMessage(tab.id, {
|
||||
action: ACTIONS.ShowMessage,
|
||||
payload: {
|
||||
text: 'Unable to save page',
|
||||
type: 'error'
|
||||
}
|
||||
});
|
||||
return;
|
||||
switch(type) {
|
||||
case 'pdf': {
|
||||
// For PDFs, we first upload the PDF file before passing the upload file ID in createArticle
|
||||
uploadResult = await savePdfFile(tab, encodeURI(tab.url), pageInfo.contentType, uploadContentObjUrl);
|
||||
if (!uploadResult || !uploadResult.id) {
|
||||
browserApi.tabs.sendMessage(tab.id, {
|
||||
action: ACTIONS.ShowMessage,
|
||||
payload: {
|
||||
text: 'Unable to save page',
|
||||
type: 'error'
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
case 'url': {
|
||||
// We don't have to special case URL, it will fall through
|
||||
// and be handled when isContentAvailable returns false
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -434,7 +444,6 @@ function checkAuthOnFirstClickPostInstall (tabId) {
|
|||
const xhr = new XMLHttpRequest();
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4 && xhr.status === 200) {
|
||||
console.log('response:' + xhr.response);
|
||||
const { data } = JSON.parse(xhr.response);
|
||||
if (!data.me) {
|
||||
browserApi.tabs.sendMessage(tabId, {
|
||||
|
|
@ -467,7 +476,6 @@ function checkAuthOnFirstClickPostInstall (tabId) {
|
|||
const data = JSON.stringify({
|
||||
query
|
||||
});
|
||||
console.log('querying url', omnivoreGraphqlURL)
|
||||
xhr.open('POST', omnivoreGraphqlURL + 'graphql', true);
|
||||
setupConnection(xhr);
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ window.browserScriptingApi = browserApi.scripting || browserApi.tabs;
|
|||
window.ENV_EXTENSION_ORIGIN = browserApi.runtime.getURL('PATH/').replace('/PATH/', '');
|
||||
window.ENV_IS_FIREFOX = ENV_EXTENSION_ORIGIN.startsWith('moz-extension://');
|
||||
window.ENV_IS_EDGE = navigator.userAgent.toLowerCase().indexOf('edg') > -1;
|
||||
window.ENV_DOES_NOT_SUPPORT_BLOB_URL_ACCESS = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
|
||||
|
||||
window.SELECTORS = {
|
||||
CANONICAL_URL: ["head > link[rel='canonical']"],
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
browserApi
|
||||
XMLHttpRequest
|
||||
ACTIONS
|
||||
ENV_DOES_NOT_SUPPORT_BLOB_URL_ACCESS
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
|
@ -28,7 +29,6 @@
|
|||
'text/x-pdf'
|
||||
];
|
||||
const isPdfContent = pdfContentTypes.indexOf(document.contentType) !== -1;
|
||||
|
||||
if (!hasPdfExtension && !isPdfContent) {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
|
|
@ -38,6 +38,10 @@
|
|||
return Promise.resolve(null);
|
||||
}
|
||||
|
||||
if (ENV_DOES_NOT_SUPPORT_BLOB_URL_ACCESS && embedEl.src) {
|
||||
return Promise.resolve({ type: 'url', uploadContentObjUrl: embedEl.src })
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const xhr = new XMLHttpRequest();
|
||||
// load `document` from `cache`
|
||||
|
|
@ -45,8 +49,7 @@
|
|||
xhr.responseType = 'blob';
|
||||
xhr.onload = function (e) {
|
||||
if (this.status === 200) {
|
||||
// `blob` response
|
||||
resolve(URL.createObjectURL(this.response));
|
||||
resolve({ type: 'pdf', uploadContentObjUrl: URL.createObjectURL(this.response) })
|
||||
} else {
|
||||
reject(e);
|
||||
}
|
||||
|
|
@ -132,7 +135,6 @@
|
|||
// Without adding that copy to the DOM the `window.getComputedStyle` method will always return undefined.
|
||||
document.documentElement.appendChild(contentCopyEl);
|
||||
|
||||
console.log('\n\nStarting evaluation!');
|
||||
Array.from(contentCopyEl.getElementsByTagName('*')).forEach(prepareContentPostItem);
|
||||
|
||||
/*
|
||||
|
|
@ -181,9 +183,9 @@
|
|||
}
|
||||
|
||||
async function prepareContent () {
|
||||
const pdfContentObjectUrl = await grabPdfContent();
|
||||
if (pdfContentObjectUrl) {
|
||||
return { type: 'pdf', uploadContentObjUrl: pdfContentObjectUrl };
|
||||
const pdfContent = await grabPdfContent();
|
||||
if (pdfContent) {
|
||||
return pdfContent
|
||||
}
|
||||
|
||||
async function scrollPage () {
|
||||
|
|
|
|||
Loading…
Reference in a new issue