Files
firefox-ext-dl/index.html
2025-09-12 10:42:45 -07:00

132 lines
5.2 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Firefox Extension Downloader</title>
<style>
:root {
--bg-color: #121212;
--surface-color: #1e1e1e;
--primary-color: #00aaff;
--primary-hover: #0088cc;
--text-color: #e0e0e0;
--border-color: #333;
--error-color: #ff4d4d;
--success-color: #4dff4d;
}
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap');
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
background-color: var(--bg-color);
color: var(--text-color);
display: grid;
place-items: center;
padding: 1rem;
}
main {
width: 100%;
max-width: 500px;
background-color: var(--surface-color);
padding: 2.5rem 2rem;
border-radius: 12px;
border: 1px solid var(--border-color);
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
text-align: center;
}
h1 {
font-size: 1.75rem;
margin-bottom: 0.5rem;
font-weight: 600;
}
p {
margin-bottom: 1.5rem;
color: #aaa;
}
#dl-form {
display: flex;
flex-direction: column;
gap: 1rem;
}
#addon-url {
width: 100%;
padding: 0.75rem 1rem;
background-color: var(--bg-color);
border: 1px solid var(--border-color);
border-radius: 8px;
color: var(--text-color);
font-size: 1rem;
outline: none;
transition: border-color 0.2s, box-shadow 0.2s;
}
#addon-url:focus {
border-color: var(--primary-color);
box-shadow: 0 0 0 3px rgba(0, 170, 255, 0.2);
}
button {
padding: 0.75rem 1rem;
background-color: var(--primary-color);
color: #fff;
border: none;
border-radius: 8px;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: background-color 0.2s;
}
button:hover, button:focus {
background-color: var(--primary-hover);
outline: none;
}
#status {
margin-top: 1.5rem;
margin-bottom: -1rem; /* prevent layout shift */
min-height: 1.2em;
font-weight: 600;
}
#status.error { color: var(--error-color); }
#status.success { color: var(--success-color); }
</style>
</head>
<body>
<main>
<h1>Extension Downloader</h1>
<p>Provide a Firefox Add-on Store URL to download its source file as a <code>.zip</code> archive.</p>
<form id="dl-form">
<input type="url" id="addon-url" placeholder="https://addons.mozilla.org/..." required autocomplete="off">
<button type="submit">Download as .zip</button>
</form>
<p id="status"></p>
</main>
<script>
document.getElementById('dl-form').addEventListener('submit', e => {
e.preventDefault();
const status = document.getElementById('status');
status.className = ''; status.textContent = 'Acquiring target...';
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 => (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 zipBlob = new Blob([blob], { type: 'application/zip' }), fileName = url.split('/').pop().replace(/\.xpi$/, '.zip');
const a = document.createElement('a');
a.href = URL.createObjectURL(zipBlob);
a.download = fileName;
document.body.appendChild(a).click();
URL.revokeObjectURL(a.href);
document.body.removeChild(a);
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));
} catch (err) {
status.className = 'error'; status.textContent = 'Error: Invalid URL format.';
setTimeout(() => status.textContent = status.className = '', 5000);
}
});
</script>
</body>
</html>