Skip to content

Commit

Permalink
fix sciencedirect pdf
Browse files Browse the repository at this point in the history
  • Loading branch information
ttop32 committed Oct 27, 2024
1 parent 6664d33 commit 3c26ec0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 22 deletions.
27 changes: 6 additions & 21 deletions src/contentScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/pdf/pdfInject.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3c26ec0

Please sign in to comment.