pdf.js/extensions/chrome/pdfHandler.html

29 lines
567 B
HTML

<!doctype html>
<script>
function isPdfDownloadable(details) {
return details.url.indexOf('pdfjs.action=download') >= 0;
}
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
if (isPdfDownloadable(details))
return;
var viewerPage = 'content/web/viewer.html';
var url = chrome.extension.getURL(viewerPage) +
'?file=' + encodeURIComponent(details.url);
return { redirectUrl: url };
},
{
urls: [
"http://*/*.pdf",
"file://*/*.pdf"
],
types: [ "main_frame" ]
},
["blocking"]);
</script>