more tweaks
This commit is contained in:
parent
fc77b286b7
commit
b3c7be655e
3 changed files with 42 additions and 38 deletions
60
content.js
60
content.js
|
|
@ -287,45 +287,17 @@ function getFflate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createZipBlob(archiveEntries) {
|
async function createZipBlob(archiveEntries) {
|
||||||
const { Zip, ZipPassThrough } = getFflate()
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const chunks = []
|
fflate.zip(archiveEntries, { level: 0, consume: true }, (error, data) => {
|
||||||
const zip = new Zip()
|
|
||||||
let settled = false
|
|
||||||
|
|
||||||
zip.ondata = (error, chunk, final) => {
|
|
||||||
if (settled) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
settled = true
|
|
||||||
reject(error)
|
reject(error)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
resolve(data)
|
||||||
chunks.push(chunk)
|
|
||||||
|
|
||||||
if (final) {
|
|
||||||
settled = true
|
|
||||||
resolve(new Blob(chunks, { type: "application/zip" }))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
Object.entries(archiveEntries).forEach(([path, bytes]) => {
|
|
||||||
const file = new ZipPassThrough(path)
|
|
||||||
|
|
||||||
zip.add(file)
|
|
||||||
file.push(bytes, true)
|
|
||||||
})
|
})
|
||||||
|
})
|
||||||
zip.end()
|
.then((archiveBytes) => {
|
||||||
} catch (error) {
|
return new Blob([archiveBytes], { type: "application/zip" })
|
||||||
settled = true
|
|
||||||
reject(error)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -378,6 +350,7 @@ function createProgressDialog() {
|
||||||
const size = document.createElement("p")
|
const size = document.createElement("p")
|
||||||
const actions = document.createElement("div")
|
const actions = document.createElement("div")
|
||||||
const closeButton = document.createElement("button")
|
const closeButton = document.createElement("button")
|
||||||
|
const downloadButton = document.createElement("button")
|
||||||
const entries = new Map()
|
const entries = new Map()
|
||||||
const progress = new Map()
|
const progress = new Map()
|
||||||
const startTime = Date.now()
|
const startTime = Date.now()
|
||||||
|
|
@ -406,6 +379,12 @@ function createProgressDialog() {
|
||||||
size.textContent = `Downloaded size: ${formatMegabytes(totalDownloadedBytes)}`
|
size.textContent = `Downloaded size: ${formatMegabytes(totalDownloadedBytes)}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
downloadButton.type = "button"
|
||||||
|
downloadButton.id = "download-button"
|
||||||
|
downloadButton.textContent = "Download"
|
||||||
|
downloadButton.disabled = true
|
||||||
|
downloadButton.classList.add("ripper-hidden")
|
||||||
|
|
||||||
closeButton.type = "button"
|
closeButton.type = "button"
|
||||||
closeButton.textContent = "Close"
|
closeButton.textContent = "Close"
|
||||||
closeButton.disabled = true
|
closeButton.disabled = true
|
||||||
|
|
@ -420,6 +399,7 @@ function createProgressDialog() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
actions.append(downloadButton)
|
||||||
actions.append(closeButton)
|
actions.append(closeButton)
|
||||||
summary.append(elapsed, downloaded, size)
|
summary.append(elapsed, downloaded, size)
|
||||||
dialog.append(title, status, list, summary, actions)
|
dialog.append(title, status, list, summary, actions)
|
||||||
|
|
@ -488,6 +468,7 @@ function createProgressDialog() {
|
||||||
|
|
||||||
// Main export flow: fetch applicant data, download files, then assemble the ZIP.
|
// Main export flow: fetch applicant data, download files, then assemble the ZIP.
|
||||||
function rip(event) {
|
function rip(event) {
|
||||||
|
Notification.requestPermission()
|
||||||
const btn = event.target;
|
const btn = event.target;
|
||||||
const progressDialog = createProgressDialog()
|
const progressDialog = createProgressDialog()
|
||||||
btn.textContent = "working ..."
|
btn.textContent = "working ..."
|
||||||
|
|
@ -549,13 +530,20 @@ function rip(event) {
|
||||||
archiveEntries["fflate.min.js"] = viewerFflateSource
|
archiveEntries["fflate.min.js"] = viewerFflateSource
|
||||||
|
|
||||||
console.log("Generating zip archive...")
|
console.log("Generating zip archive...")
|
||||||
|
createZipBlob(archiveEntries)
|
||||||
return createZipBlob(archiveEntries)
|
|
||||||
.then((zipBlob) => {
|
.then((zipBlob) => {
|
||||||
console.log("Zip archive is ready.")
|
console.log("Zip archive is ready.")
|
||||||
|
if (Notification.permission == "granted") {
|
||||||
|
new Notification("EPAS Ripper", { body: `Zip archive for job offer ${aid} is ready for download` })
|
||||||
|
}
|
||||||
progressDialog.setStatus("Download ready.")
|
progressDialog.setStatus("Download ready.")
|
||||||
downloadBlob(zipBlob, `procedure_${aid}.zip`)
|
|
||||||
btn.textContent = "done"
|
btn.textContent = "done"
|
||||||
|
const downloadButton = document.querySelector("#download-button")
|
||||||
|
downloadButton.addEventListener("click", () => {
|
||||||
|
downloadBlob(zipBlob, `procedure_${aid}.zip`)
|
||||||
|
})
|
||||||
|
downloadButton.classList.remove("ripper-hidden")
|
||||||
|
downloadButton.disabled = false
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,18 @@
|
||||||
"manifest_version": 3,
|
"manifest_version": 3,
|
||||||
"name": "KF-EPAS-Ripper",
|
"name": "KF-EPAS-Ripper",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
|
"browser_specific_settings": {
|
||||||
|
"gecko": {
|
||||||
|
"id": "epas-ripper@math.janko.fr",
|
||||||
|
"data_collection_permissions": {
|
||||||
|
"required": [
|
||||||
|
"none"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"description": "Downloads all files from an EPAS application",
|
"description": "Downloads all files from an EPAS application",
|
||||||
|
"permissions": [ "notifications" ],
|
||||||
"host_permissions": [
|
"host_permissions": [
|
||||||
"https://personal.uni-graz.at/*"
|
"https://personal.uni-graz.at/*"
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,10 @@ button.ripper-btn:disabled {
|
||||||
max-height: 20rem;
|
max-height: 20rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ripper-hidden {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
.ripper-progress-item {
|
.ripper-progress-item {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
@ -121,6 +125,7 @@ button.ripper-btn:disabled {
|
||||||
}
|
}
|
||||||
|
|
||||||
.ripper-progress-actions > button {
|
.ripper-progress-actions > button {
|
||||||
|
margin-left: 0.5rem;
|
||||||
padding: 0.5rem 0.9rem;
|
padding: 0.5rem 0.9rem;
|
||||||
border: 1px solid #cbd5e1;
|
border: 1px solid #cbd5e1;
|
||||||
border-radius: 0.5rem;
|
border-radius: 0.5rem;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue