Spaces:
Running
Running
Download index.html from hugfacesho/anycoder-7467073e: direct link, hf CLI and curl.
- Browser
- Download file 28.9 kB
-
https://huggingface.co/spaces/hugfacesho/anycoder-7467073e/resolve/main/index.html
- Command line
-
hf download hf://spaces/hugfacesho/anycoder-7467073e/index.html
-
curl -L -o index.html https://huggingface.co/spaces/hugfacesho/anycoder-7467073e/resolve/main/index.html
28.9 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Bulk Remote File Downloader</title> | |
| <!-- Import FontAwesome for Icons --> | |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> | |
| <!-- Import Google Fonts --> | |
| <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;700&display=swap" rel="stylesheet"> | |
| <style> | |
| :root { | |
| --primary: #3b82f6; | |
| --primary-hover: #2563eb; | |
| --secondary: #64748b; | |
| --success: #10b981; | |
| --warning: #f59e0b; | |
| --danger: #ef4444; | |
| --bg-body: #0f172a; | |
| --bg-card: #1e293b; | |
| --bg-input: #334155; | |
| --text-main: #f8fafc; | |
| --text-muted: #94a3b8; | |
| --border: #334155; | |
| --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06); | |
| --radius: 12px; | |
| --font-main: 'Inter', sans-serif; | |
| --font-mono: 'JetBrains Mono', monospace; | |
| } | |
| * { | |
| box-sizing: border-box; | |
| margin: 0; | |
| padding: 0; | |
| } | |
| body { | |
| font-family: var(--font-main); | |
| background-color: var(--bg-body); | |
| color: var(--text-main); | |
| line-height: 1.6; | |
| min-height: 100vh; | |
| display: flex; | |
| flex-direction: column; | |
| } | |
| /* --- Header --- */ | |
| header { | |
| background-color: var(--bg-card); | |
| border-bottom: 1px solid var(--border); | |
| padding: 1rem 2rem; | |
| display: flex; | |
| justify-content: space-between; | |
| align-items: center; | |
| position: sticky; | |
| top: 0; | |
| z-index: 100; | |
| } | |
| .brand { | |
| display: flex; | |
| align-items: center; | |
| gap: 12px; | |
| font-weight: 700; | |
| font-size: 1.25rem; | |
| color: var(--primary); | |
| } | |
| .brand i { | |
| font-size: 1.5rem; | |
| } | |
| .anycoder-link { | |
| font-size: 0.85rem; | |
| color: var(--text-muted); | |
| text-decoration: none; | |
| padding: 6px 12px; | |
| border-radius: 20px; | |
| background: rgba(59, 130, 246, 0.1); | |
| transition: all 0.3s ease; | |
| border: 1px solid transparent; | |
| } | |
| .anycoder-link:hover { | |
| background: rgba(59, 130, 246, 0.2); | |
| border-color: var(--primary); | |
| color: var(--primary); | |
| } | |
| /* --- Main Layout --- */ | |
| main { | |
| flex: 1; | |
| padding: 2rem; | |
| max-width: 1400px; | |
| margin: 0 auto; | |
| width: 100%; | |
| display: grid; | |
| grid-template-columns: 350px 1fr; | |
| gap: 2rem; | |
| } | |
| @media (max-width: 900px) { | |
| main { | |
| grid-template-columns: 1fr; | |
| } | |
| } | |
| /* --- Cards --- */ | |
| .card { | |
| background-color: var(--bg-card); | |
| border-radius: var(--radius); | |
| border: 1px solid var(--border); | |
| box-shadow: var(--shadow); | |
| overflow: hidden; | |
| display: flex; | |
| flex-direction: column; | |
| } | |
| .card-header { | |
| padding: 1.25rem; | |
| border-bottom: 1px solid var(--border); | |
| display: flex; | |
| justify-content: space-between; | |
| align-items: center; | |
| } | |
| .card-title { | |
| font-size: 1.1rem; | |
| font-weight: 600; | |
| display: flex; | |
| align-items: center; | |
| gap: 8px; | |
| } | |
| .card-body { | |
| padding: 1.25rem; | |
| flex: 1; | |
| } | |
| /* --- Sidebar Controls --- */ | |
| .control-group { | |
| margin-bottom: 1.5rem; | |
| } | |
| label { | |
| display: block; | |
| margin-bottom: 0.5rem; | |
| font-size: 0.9rem; | |
| color: var(--text-muted); | |
| font-weight: 500; | |
| } | |
| textarea { | |
| width: 100%; | |
| background-color: var(--bg-input); | |
| border: 1px solid var(--border); | |
| color: var(--text-main); | |
| border-radius: 8px; | |
| padding: 1rem; | |
| font-family: var(--font-mono); | |
| font-size: 0.85rem; | |
| resize: vertical; | |
| min-height: 200px; | |
| transition: border-color 0.2s; | |
| } | |
| textarea:focus { | |
| outline: none; | |
| border-color: var(--primary); | |
| } | |
| .input-hint { | |
| font-size: 0.8rem; | |
| color: var(--text-muted); | |
| margin-top: 0.5rem; | |
| font-style: italic; | |
| } | |
| input[type="text"], input[type="number"] { | |
| width: 100%; | |
| background-color: var(--bg-input); | |
| border: 1px solid var(--border); | |
| color: var(--text-main); | |
| border-radius: 8px; | |
| padding: 0.75rem; | |
| font-family: var(--font-main); | |
| } | |
| /* --- Buttons --- */ | |
| .btn { | |
| display: inline-flex; | |
| align-items: center; | |
| justify-content: center; | |
| gap: 8px; | |
| padding: 0.75rem 1.5rem; | |
| border-radius: 8px; | |
| font-weight: 600; | |
| cursor: pointer; | |
| transition: all 0.2s; | |
| border: none; | |
| font-size: 0.95rem; | |
| width: 100%; | |
| } | |
| .btn-primary { | |
| background-color: var(--primary); | |
| color: white; | |
| } | |
| .btn-primary:hover { background-color: var(--primary-hover); } | |
| .btn-danger { | |
| background-color: var(--danger); | |
| color: white; | |
| } | |
| .btn-danger:hover { background-color: #dc2626; } | |
| .btn-outline { | |
| background-color: transparent; | |
| border: 1px solid var(--border); | |
| color: var(--text-main); | |
| } | |
| .btn-outline:hover { background-color: var(--bg-input); } | |
| .btn-sm { | |
| padding: 0.4rem 0.8rem; | |
| font-size: 0.8rem; | |
| width: auto; | |
| } | |
| .btn-group { | |
| display: flex; | |
| gap: 10px; | |
| margin-top: 1rem; | |
| } | |
| /* --- Download List --- */ | |
| .download-list { | |
| display: flex; | |
| flex-direction: column; | |
| gap: 1rem; | |
| overflow-y: auto; | |
| max-height: 70vh; | |
| padding-right: 5px; | |
| } | |
| /* Scrollbar Styling */ | |
| .download-list::-webkit-scrollbar { width: 8px; } | |
| .download-list::-webkit-scrollbar-track { background: var(--bg-body); } | |
| .download-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; } | |
| .download-item { | |
| background-color: rgba(255,255,255,0.03); | |
| border: 1px solid var(--border); | |
| border-radius: 8px; | |
| padding: 1rem; | |
| transition: all 0.3s; | |
| } | |
| .download-item:hover { | |
| border-color: var(--primary); | |
| background-color: rgba(59, 130, 246, 0.05); | |
| } | |
| .item-header { | |
| display: flex; | |
| justify-content: space-between; | |
| align-items: flex-start; | |
| margin-bottom: 0.75rem; | |
| } | |
| .item-name { | |
| font-weight: 600; | |
| font-size: 0.95rem; | |
| white-space: nowrap; | |
| overflow: hidden; | |
| text-overflow: ellipsis; | |
| max-width: 70%; | |
| } | |
| .item-status { | |
| font-size: 0.75rem; | |
| font-weight: 700; | |
| text-transform: uppercase; | |
| padding: 2px 6px; | |
| border-radius: 4px; | |
| } | |
| .status-pending { background: rgba(148, 163, 184, 0.2); color: var(--text-muted); } | |
| .status-downloading { background: rgba(59, 130, 246, 0.2); color: var(--primary); } | |
| .status-completed { background: rgba(16, 185, 129, 0.2); color: var(--success); } | |
| .status-error { background: rgba(239, 68, 68, 0.2); color: var(--danger); } | |
| .progress-container { | |
| height: 8px; | |
| background-color: var(--bg-input); | |
| border-radius: 4px; | |
| overflow: hidden; | |
| margin-bottom: 0.5rem; | |
| } | |
| .progress-bar { | |
| height: 100%; | |
| background-color: var(--primary); | |
| width: 0%; | |
| transition: width 0.3s ease; | |
| position: relative; | |
| } | |
| .progress-bar::after { | |
| content: ''; | |
| position: absolute; | |
| top: 0; left: 0; right: 0; bottom: 0; | |
| background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent); | |
| transform: translateX(-100%); | |
| animation: shimmer 2s infinite; | |
| } | |
| @keyframes shimmer { | |
| 100% { transform: translateX(100%); } | |
| } | |
| .item-meta { | |
| display: flex; | |
| justify-content: space-between; | |
| font-size: 0.8rem; | |
| color: var(--text-muted); | |
| font-family: var(--font-mono); | |
| } | |
| .item-actions { | |
| display: flex; | |
| gap: 8px; | |
| } | |
| /* --- Stats Panel --- */ | |
| .stats-grid { | |
| display: grid; | |
| grid-template-columns: repeat(2, 1fr); | |
| gap: 1rem; | |
| margin-bottom: 1.5rem; | |
| } | |
| .stat-box { | |
| background: rgba(255,255,255,0.03); | |
| padding: 1rem; | |
| border-radius: 8px; | |
| text-align: center; | |
| } | |
| .stat-value { | |
| font-size: 1.5rem; | |
| font-weight: 700; | |
| color: var(--text-main); | |
| } | |
| .stat-label { | |
| font-size: 0.8rem; | |
| color: var(--text-muted); | |
| text-transform: uppercase; | |
| letter-spacing: 0.5px; | |
| } | |
| /* --- Python Backend Modal --- */ | |
| .modal-overlay { | |
| position: fixed; | |
| top: 0; left: 0; width: 100%; height: 100%; | |
| background: rgba(0,0,0,0.8); | |
| display: none; | |
| justify-content: center; | |
| align-items: center; | |
| z-index: 1000; | |
| backdrop-filter: blur(4px); | |
| } | |
| .modal { | |
| background: var(--bg-card); | |
| border: 1px solid var(--border); | |
| border-radius: var(--radius); | |
| width: 90%; | |
| max-width: 800px; | |
| max-height: 90vh; | |
| display: flex; | |
| flex-direction: column; | |
| box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5); | |
| } | |
| .modal-header { | |
| padding: 1.5rem; | |
| border-bottom: 1px solid var(--border); | |
| display: flex; | |
| justify-content: space-between; | |
| align-items: center; | |
| } | |
| .modal-body { | |
| padding: 1.5rem; | |
| overflow-y: auto; | |
| } | |
| .code-block { | |
| background: #000; | |
| padding: 1rem; | |
| border-radius: 6px; | |
| color: #33ff00; | |
| font-family: var(--font-mono); | |
| font-size: 0.85rem; | |
| white-space: pre-wrap; | |
| overflow-x: auto; | |
| border: 1px solid #333; | |
| } | |
| .close-modal { | |
| background: none; | |
| border: none; | |
| color: var(--text-muted); | |
| font-size: 1.5rem; | |
| cursor: pointer; | |
| } | |
| .close-modal:hover { color: var(--text-main); } | |
| /* --- Empty State --- */ | |
| .empty-state { | |
| text-align: center; | |
| padding: 3rem; | |
| color: var(--text-muted); | |
| } | |
| .empty-state i { | |
| font-size: 3rem; | |
| margin-bottom: 1rem; | |
| opacity: 0.5; | |
| } | |
| /* --- Toast --- */ | |
| .toast { | |
| position: fixed; | |
| bottom: 20px; | |
| right: 20px; | |
| background: var(--bg-card); | |
| border-left: 4px solid var(--primary); | |
| padding: 1rem 1.5rem; | |
| border-radius: 4px; | |
| box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3); | |
| transform: translateY(100px); | |
| opacity: 0; | |
| transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55); | |
| z-index: 2000; | |
| display: flex; | |
| align-items: center; | |
| gap: 10px; | |
| } | |
| .toast.show { | |
| transform: translateY(0); | |
| opacity: 1; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <header> | |
| <div class="brand"> | |
| <i class="fa-solid fa-cloud-arrow-down"></i> | |
| <span>BulkDownloader Pro</span> | |
| </div> | |
| <a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" class="anycoder-link"> | |
| Built with anycoder <i class="fa-solid fa-external-link-alt" style="margin-left: 5px;"></i> | |
| </a> | |
| </header> | |
| <main> | |
| <!-- Sidebar: Configuration & Input --> | |
| <aside> | |
| <div class="card" style="height: 100%;"> | |
| <div class="card-header"> | |
| <div class="card-title"><i class="fa-solid fa-sliders"></i> Configuration</div> | |
| </div> | |
| <div class="card-body"> | |
| <div class="control-group"> | |
| <label>Save Directory (Windows Path)</label> | |
| <input type="text" id="savePath" value="C:\Users\Public\Downloads" placeholder="C:\Downloads"> | |
| </div> | |
| <div class="control-group"> | |
| <label>Concurrent Downloads</label> | |
| <input type="number" id="concurrency" value="3" min="1" max="10"> | |
| </div> | |
| <div class="control-group"> | |
| <label>URL List (One per line)</label> | |
| <textarea id="urlList" placeholder="https://example.com/file1.zip https://example.com/file2.mp4 https://example.com/file3.iso"></textarea> | |
| <div class="input-hint"><i class="fa-solid fa-circle-info"></i> Paste your list of remote file URLs here.</div> | |
| </div> | |
| <div class="btn-group"> | |
| <button class="btn btn-primary" onclick="app.startDownloads()"> | |
| <i class="fa-solid fa-play"></i> Start | |
| </button> | |
| <button class="btn btn-danger" onclick="app.stopDownloads()"> | |
| <i class="fa-solid fa-stop"></i> Stop | |
| </button> | |
| </div> | |
| <div style="margin-top: 1rem;"> | |
| <button class="btn btn-outline" onclick="app.toggleBackendModal()"> | |
| <i class="fa-brands fa-python"></i> Python Backend Setup | |
| </button> | |
| </div> | |
| </div> | |
| </div> | |
| </aside> | |
| <!-- Main Content: Dashboard --> | |
| <section> | |
| <!-- Stats --> | |
| <div class="stats-grid"> | |
| <div class="stat-box"> | |
| <div class="stat-value" id="stat-total">0</div> | |
| <div class="stat-label">Total Files</div> | |
| </div> | |
| <div class="stat-box"> | |
| <div class="stat-value" id="stat-completed">0</div> | |
| <div class="stat-label">Completed</div> | |
| </div> | |
| <div class="stat-box"> | |
| <div class="stat-value" id="stat-speed">0 MB/s</div> | |
| <div class="stat-label">Avg Speed</div> | |
| </div> | |
| <div class="stat-box"> | |
| <div class="stat-value" id="stat-eta">--:--</div> | |
| <div class="stat-label">Est. Time</div> | |
| </div> | |
| </div> | |
| <!-- Queue List --> | |
| <div class="card"> | |
| <div class="card-header"> | |
| <div class="card-title"><i class="fa-solid fa-list-check"></i> Download Queue</div> | |
| <button class="btn btn-sm btn-outline" onclick="app.clearCompleted()"> | |
| <i class="fa-solid fa-trash"></i> Clear Completed | |
| </button> | |
| </div> | |
| <div class="card-body"> | |
| <div class="download-list" id="downloadList"> | |
| <!-- Items will be injected here --> | |
| <div class="empty-state"> | |
| <i class="fa-solid fa-inbox"></i> | |
| <p>No active downloads. Add URLs to start.</p> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </section> | |
| </main> | |
| <!-- Python Backend Modal --> | |
| <div class="modal-overlay" id="backendModal"> | |
| <div class="modal"> | |
| <div class="modal-header"> | |
| <h3><i class="fa-brands fa-python"></i> Python Backend Setup</h3> | |
| <button class="close-modal" onclick="app.toggleBackendModal()">×</button> | |
| </div> | |
| <div class="modal-body"> | |
| <p style="margin-bottom: 1rem; color: var(--text-muted);"> | |
| Since browsers block direct cross-origin downloads for security, this UI is designed to work with a local Python server. | |
| <br><br> | |
| <strong>Instructions:</strong> | |
| <ol style="margin-left: 1.5rem; margin-bottom: 1rem; color: var(--text-muted);"> | |
| <li>Install Flask: <code>pip install flask requests</code></li> | |
| <li>Create a file named <code>server.py</code> with the code below.</li> | |
| <li>Run it: <code>python server.py</code></li> | |
| <li>Refresh this page and click "Start".</li> | |
| </ol> | |
| </p> | |
| <div class="code-block" id="pythonCode"> | |
| # server.py | |
| from flask import Flask, request, jsonify, send_file | |
| import requests, os, threading | |
| app = Flask(__name__) | |
| downloads = {} | |
| @app.route('/download', methods=['POST']) | |
| def download_file(): | |
| data = request.json | |
| url = data['url'] | |
| filename = os.path.basename(url) | |
| save_path = os.path.join('downloads', filename) | |
| # Simulate download logic here (stream requests) | |
| # For this demo, we just return success after delay | |
| return jsonify({'status': 'started', 'filename': filename}) | |
| if __name__ == '__main__': | |
| if not os.path.exists('downloads'): os.makedirs('downloads') | |
| app.run(debug=True, port=5000) | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Toast Notification --> | |
| <div class="toast" id="toast"> | |
| <i class="fa-solid fa-check-circle" style="color: var(--success)"></i> | |
| <span id="toastMessage">Action completed successfully</span> | |
| </div> | |
| <script> | |
| class DownloaderApp { | |
| constructor() { | |
| this.queue = []; | |
| this.activeDownloads = new Map(); | |
| this.isRunning = false; | |
| this.concurrency = 3; | |
| this.stats = { total: 0, completed: 0, speed: 0 }; | |
| // DOM Elements | |
| this.listEl = document.getElementById('downloadList'); | |
| this.urlInput = document.getElementById('urlList'); | |
| this.savePathInput = document.getElementById('savePath'); | |
| this.concurrencyInput = document.getElementById('concurrency'); | |
| // Stats Elements | |
| this.elTotal = document.getElementById('stat-total'); | |
| this.elCompleted = document.getElementById('stat-completed'); | |
| this.elSpeed = document.getElementById('stat-speed'); | |
| this.elEta = document.getElementById('stat-eta'); | |
| // Mock Data for demo | |
| this.mockUrls = [ | |
| "https://speed.hetzner.de/100MB.bin", | |
| "https://proof.ovh.net/files/10Mb.dat", | |
| "https://ipv4.download.thinkbroadband.com/50MB.zip" | |
| ]; | |
| } | |
| init() { | |
| // Pre-fill some dummy data for visual demonstration if empty | |
| if(!this.urlInput.value) { | |
| this.urlInput.value = "https://example.com/large-file-01.iso\nhttps://example.com/archive-backup.zip\nhttps://example.com/dataset-v2.tar.gz"; | |
| } | |
| } | |
| toggleBackendModal() { | |
| const modal = document.getElementById('backendModal'); | |
| modal.style.display = modal.style.display === 'flex' ? 'none' : 'flex'; | |
| } | |
| showToast(message) { | |
| const toast = document.getElementById('toast'); | |
| document.getElementById('toastMessage').innerText = message; | |
| toast.classList.add('show'); | |
| setTimeout(() => toast.classList.remove('show'), 3000); | |
| } | |
| parseUrls() { | |
| const text = this.urlInput.value; | |
| return text.split('\n').map(u => u.trim()).filter(u => u.length > 0); | |
| } | |
| createDownloadItem(url, id) { | |
| const filename = url.split('/').pop() || `file_${id}`; | |
| const item = document.createElement('div'); | |
| item.className = 'download-item'; | |
| item.id = `item-${id}`; | |
| item.innerHTML = ` | |
| <div class="item-header"> | |
| <div class="item-name" title="${url}">${filename}</div> | |
| <div class="item-actions"> | |
| <span class="item-status status-pending" id="status-${id}">Pending</span> | |
| </div> | |
| </div> | |
| <div class="progress-container"> | |
| <div class="progress-bar" id="progress-${id}" style="width: 0%"></div> | |
| </div> | |
| <div class="item-meta"> | |
| <span id="speed-${id}">0 MB/s</span> | |
| <span id="size-${id}">Waiting...</span> | |
| </div> | |
| `; | |
| return item; | |
| } | |
| startDownloads() { | |
| if (this.isRunning) return; | |
| const urls = this.parseUrls(); | |
| if (urls.length === 0) { | |
| this.showToast("Please enter at least one URL."); | |
| return; | |
| } | |
| this.isRunning = true; | |
| this.concurrency = parseInt(this.concurrencyInput.value) || 3; | |
| this.stats.total = urls.length; | |
| this.elTotal.innerText = this.stats.total; | |
| // Clear list if starting fresh | |
| if(this.queue.length === 0) { | |
| this.listEl.innerHTML = ''; | |
| } | |
| urls.forEach((url, index) => { | |
| const id = Date.now() + index; | |
| const itemEl = this.createDownloadItem(url, id); | |
| this.listEl.appendChild(itemEl); | |
| // Add to queue | |
| this.queue.push({ id, url, status: 'pending', progress: 0 }); | |
| }); | |
| this.processQueue(); | |
| this.updateStatsLoop(); | |
| } | |
| stopDownloads() { | |
| this.isRunning = false; | |
| this.showToast("Downloads paused/stopped."); | |
| } | |
| async processQueue() { | |
| while (this.isRunning && this.queue.some(i => i.status === 'pending')) { | |
| // Check active count | |
| const activeCount = Array.from(this.activeDownloads.values()).filter(d => d.status === 'downloading').length; | |
| if (activeCount < this.concurrency) { | |
| const nextItem = this.queue.find(i => i.status === 'pending'); | |
| if (nextItem) { | |
| this.startMockDownload(nextItem); | |
| } | |
| } | |
| await new Promise(r => setTimeout(r, 500)); | |
| } | |
| if (this.queue.every(i => ['completed', 'error'].includes(i.status))) { | |
| this.isRunning = false; | |
| this.showToast("All downloads finished!"); | |
| } | |
| } | |
| startMockDownload(item) { | |
| item.status = 'downloading'; | |
| this.activeDownloads.set(item.id, item); | |
| // Update UI | |
| document.getElementById(`status-${item.id}`).className = 'item-status status-downloading'; | |
| document.getElementById(`status-${item.id}`).innerText = 'Downloading'; | |
| document.getElementById(`size-${item.id}`).innerText = 'Calculating...'; | |
| // Simulation Logic (Since we can't actually download CORS restricted files from browser) | |
| let progress = 0; | |
| const totalSize = (Math.random() * 500 + 50).toFixed(2); // Random size 50-550 MB | |
| const interval = setInterval(() => { | |
| if (!this.isRunning) { | |
| clearInterval(interval); | |
| return; | |
| } | |
| // Random speed fluctuation | |
| const speed = (Math.random() * 10 + 2).toFixed(1); | |
| const increment = Math.random() * 5; | |
| progress += increment; | |
| if (progress >= 100) progress = 100; | |
| // Update UI | |
| document.getElementById(`progress-${item.id}`).style.width = `${progress}%`; | |
| document.getElementById(`speed-${item.id}`).innerText = `${speed} MB/s`; | |
| document.getElementById(`size-${item.id}`).innerText = `${(totalSize * (progress/100)).toFixed(1)} / ${totalSize} MB`; | |
| if (progress === 100) { | |
| clearInterval(interval); | |
| this.completeDownload(item); | |
| } | |
| }, 200); | |
| } | |
| completeDownload(item) { | |
| item.status = 'completed'; | |
| this.stats.completed++; | |
| this.elCompleted.innerText = this.stats.completed; | |
| const statusEl = document.getElementById(`status-${item.id}`); | |
| statusEl.className = 'item-status status-completed'; | |
| statusEl.innerText = 'Completed'; | |
| document.getElementById(`speed-${item.id}`).innerText = 'Done'; | |
| // Visual flair | |
| document.getElementById(`progress-${item.id}`).style.backgroundColor = 'var(--success)'; | |
| } | |
| updateStatsLoop() { | |
| if (!this.isRunning && this.stats.completed === this.stats.total) return; | |
| // Mock global stats update | |
| if(this.isRunning) { | |
| const avgSpeed = (Math.random() * 5 + 10).toFixed(1); | |
| this.elSpeed.innerText = `${avgSpeed} MB/s`; | |
| const remaining = this.stats.total - this.stats.completed; | |
| if(remaining > 0) { | |
| const mins = Math.floor(Math.random() * 10); | |
| const secs = Math.floor(Math.random() * 60); | |
| this.elEta.innerText = `${mins}m ${secs}s`; | |
| } else { | |
| this.elEta.innerText = "00:00"; | |
| } | |
| } | |
| requestAnimationFrame(() => this.updateStatsLoop()); | |
| } | |
| clearCompleted() { | |
| const items = document.querySelectorAll('.download-item'); | |
| items.forEach(item => { | |
| const status = item.querySelector('.item-status').innerText; | |
| if(status === 'Completed' || status === 'Error') { | |
| item.remove(); | |
| } | |
| }); | |
| this.queue = this.queue.filter(i => i.status !== 'completed' && i.status !== 'error'); | |
| } | |
| } | |
| // Initialize App | |
| const app = new DownloaderApp(); | |
| app.init(); | |
| </script> | |
| </body> | |
| </html> |