diff --git a/src/contentScript.js b/src/contentScript.js index b2b831a2..ef12b560 100644 --- a/src/contentScript.js +++ b/src/contentScript.js @@ -803,35 +803,20 @@ async function detectPDF() { setting["detectPDF"] == "true" && document?.body?.children?.[0]?.type == "application/pdf" ) { - addPdfListener(); + util.addFrameListener("pdfErrorLoadDocument", openPdfIframeBlob); openPdfIframe(window.location.href); - // var url = "file:///D:/dummy.pd"; - // openPdfIframe(url); - // redirectToPDFViewer(); } } -function redirectToPDFViewer() { - window.location.replace( - util.getUrlExt( - `/pdfjs/web/viewer.html?file=${encodeURIComponent(window.location.href)}` - ) - ); -} -function addPdfListener() { - //if pdf not working message come, try open using blob url - util.addFrameListener("pdfErrorLoadDocument", openPdfIframeBlob); +async function getBlobUrl(url) { + var blob = await fetch(url).then((r) => r.blob()); + var url = URL.createObjectURL(blob); + return url; } async function openPdfIframeBlob() { - if (isBlobPdfOpened) { - return; - } - // wrap url for bypass referrer check, sciencedirect - isBlobPdfOpened = true; var url = window.location.href; - var blob = await fetch(url).then((r) => r.blob()); - var url = URL.createObjectURL(blob); + var url= await getBlobUrl(url); openPdfIframe(url); } diff --git a/src/pdf/pdfInject.js b/src/pdf/pdfInject.js index 7004654c..1a80d147 100644 --- a/src/pdf/pdfInject.js +++ b/src/pdf/pdfInject.js @@ -13,10 +13,10 @@ import * as dom_util from "/src/util/dom"; initPdf(); async function initPdf() { + checkPdfError(); await dom_util.waitJquery(); //wait jquery load checkLocalFileUrl(); // warn no permission if file url checkLocalFileType(); - checkPdfError(); addCustomKeystroke(); //make line break for spaced text addCallbackForPdfTextLoad(addSpaceBetweenPdfText);