mirror of
https://github.com/EverythingPublic/firefox-ext-dl.git
synced 2026-01-13 16:18:04 +00:00
feat: update index.html
This commit is contained in:
13
index.html
13
index.html
@@ -108,14 +108,15 @@
|
||||
try {
|
||||
fetch(`https://addons.mozilla.org/api/v5/addons/addon/${document.getElementById('addon-url').value.match(/\/addon\/([^/]+)/)[1]}/`)
|
||||
.then(res => res.ok ? res.json() : Promise.reject(new Error(`Server responded ${res.status}`)))
|
||||
.then(data => {
|
||||
const a = document.createElement('a');
|
||||
a.href = data.current_version.file.url;
|
||||
a.download = a.href.split('/').pop().replace(/\.xpi$/, '.zip');
|
||||
.then(data => (status.textContent = 'Downloading file...', fetch(data.current_version.file.url).then(res => res.ok ? res.blob() : Promise.reject(new Error(`File download failed: ${res.status}`))).then(blob => ({blob, url: data.current_version.file.url}))))
|
||||
.then(({blob, url}) => {
|
||||
const a = document.createElement('a'), fileName = url.split('/').pop().replace(/\.xpi$/, '.zip');
|
||||
a.href = URL.createObjectURL(blob);
|
||||
a.download = fileName;
|
||||
document.body.appendChild(a).click();
|
||||
URL.revokeObjectURL(a.href);
|
||||
document.body.removeChild(a);
|
||||
status.className = 'success';
|
||||
status.textContent = `Download initiated for ${a.download}.`;
|
||||
status.className = 'success'; status.textContent = `Download initiated for ${fileName}.`;
|
||||
})
|
||||
.catch(err => { status.className = 'error'; status.textContent = `Error: ${err.message}.`; })
|
||||
.finally(() => setTimeout(() => status.textContent = status.className = '', 5000));
|
||||
|
||||
Reference in New Issue
Block a user