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