Skip to content

Commit

Permalink
Add Firefox PDF Perms Detection
Browse files Browse the repository at this point in the history
  • Loading branch information
smashedr committed Aug 14, 2024
1 parent 4a00ed0 commit 3b544e8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
5 changes: 4 additions & 1 deletion src/html/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
<i class="fa-solid fa-file-pdf me-1"></i> Extract from PDF
<i class="fa-solid fa-flask" id="pdf-icon" style="min-width: 22px;"></i></a>
<div id="firefox-files" class="alert alert-warning text-center p-1 my-0 d-none">
Firefox does not allow access to files.
Firefox does <b>not</b> allow access to files.
</div>
<div id="firefox-pdf" class="alert alert-warning text-center p-1 my-0 d-none">
PDF Extraction Requires <a href="#" class="alert-link grant-permissions">Host Permissions</a>.
</div>
<hr class="my-0">
<form id="links-form" class="my-0">
Expand Down
35 changes: 23 additions & 12 deletions src/js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const pdfIcon = document.getElementById('pdf-icon')
async function initPopup() {
filterInput.focus()
updateManifest()
await checkPerms()
const hasPerms = await checkPerms()

const { options, patterns } = await chrome.storage.sync.get([
'options',
Expand All @@ -67,15 +67,23 @@ async function initPopup() {
const url = new URL(tab.url)
console.debug('url:', url)
if (url.pathname.toLowerCase().endsWith('.pdf')) {
if (typeof browser !== 'undefined' && url.protocol === 'file:') {
console.log(
'%cFirefox does not support file access.',
'color: OrangeRed'
)
document
.getElementById('firefox-files')
.classList.remove('d-none')
return
if (typeof browser !== 'undefined') {
if (url.protocol === 'file:') {
console.log(
'%cFirefox does not support file access.',
'color: OrangeRed'
)
document
.getElementById('firefox-files')
.classList.remove('d-none')
return
}
if (!hasPerms) {
document
.getElementById('firefox-pdf')
.classList.remove('d-none')
return
}
}
console.debug(`Detected PDF: ${url.href}`)
pdfBtn.dataset.pdfUrl = url.href
Expand Down Expand Up @@ -153,15 +161,18 @@ async function popupLinks(event) {
let url
if (href.endsWith('html/options.html')) {
chrome.runtime.openOptionsPage()
return window.close()
window.close()
return
} else if (href === '#') {
return
} else if (href.startsWith('http')) {
url = href
} else {
url = chrome.runtime.getURL(href)
}
console.log('url:', url)
await chrome.tabs.create({ active: true, url })
return window.close()
window.close()
}

/**
Expand Down

0 comments on commit 3b544e8

Please sign in to comment.