Transform popup into top-right control panel

 New Features:
- Popup now positioned in top-right corner (not center)
- Permanent floating control panel with 3 buttons
- Control panel shows selected count
- Buttons: Download Selected, Download ALL, Clear Selection
- Clicking buttons triggers downloads from within the page
- Progress panel appears OVER control panel during downloads
- After download completes, returns to control panel

🎯 User Experience:
- No need to open extension popup anymore
- All controls directly on the page
- Real-time progress tracking
- Cleaner workflow

📱 UI:
- Purple gradient design
- Responsive button layout
- Progress bar with percentage
- Auto-hide progress, show controls
This commit is contained in:
renato97
2025-11-04 05:16:08 +00:00
parent 809d290a8a
commit 3d7b1e74d6

View File

@@ -25,36 +25,85 @@
// Estilos inline para máxima compatibilidad // Estilos inline para máxima compatibilidad
popup.style.position = 'fixed'; popup.style.position = 'fixed';
popup.style.top = '50%'; popup.style.top = '20px';
popup.style.left = '50%'; popup.style.right = '20px';
popup.style.transform = 'translate(-50%, -50%)'; popup.style.width = '320px';
popup.style.width = '450px';
popup.style.background = '#667eea'; popup.style.background = '#667eea';
popup.style.backgroundImage = 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)'; popup.style.backgroundImage = 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)';
popup.style.color = 'white'; popup.style.color = 'white';
popup.style.padding = '30px'; popup.style.padding = '20px';
popup.style.borderRadius = '15px'; popup.style.borderRadius = '12px';
popup.style.boxShadow = '0 10px 50px rgba(0,0,0,0.6)'; popup.style.boxShadow = '0 8px 32px rgba(0,0,0,0.5)';
popup.style.zIndex = '999999'; // ¡Muy alto! popup.style.zIndex = '999999'; // ¡Muy alto!
popup.style.fontFamily = 'Arial, sans-serif'; popup.style.fontFamily = 'Arial, sans-serif';
popup.style.display = 'block'; // Visible por defecto popup.style.display = 'block'; // Visible por defecto
popup.style.backdropFilter = 'blur(10px)'; popup.style.backdropFilter = 'blur(10px)';
popup.innerHTML = ` popup.innerHTML = `
<div style="text-align: center; margin-bottom: 20px;"> <div style="text-align: center;">
<h3 style="margin: 0 0 15px 0; font-size: 20px; font-weight: bold;">📦 Descargando Manga</h3> <h3 style="margin: 0 0 15px 0; font-size: 18px; font-weight: bold;">📦 Mass Downloader</h3>
<div id="progress-title" style="font-size: 16px; font-weight: bold; margin-bottom: 10px;">Preparando...</div>
<!-- Panel de control (cuando no está descargando) -->
<div id="control-panel" style="display: block;">
<div style="font-size: 12px; margin-bottom: 10px; opacity: 0.9;">
Seleccionados: <span id="selected-count">0</span>
</div>
<button id="btn-download-selected" style="width: 100%; padding: 10px; margin: 5px 0; background: #4CAF50; color: white; border: none; border-radius: 6px; cursor: pointer; font-weight: bold;">⬇️ Descargar Seleccionados</button>
<button id="btn-download-all" style="width: 100%; padding: 10px; margin: 5px 0; background: #2196F3; color: white; border: none; border-radius: 6px; cursor: pointer; font-weight: bold;">📚 Descargar TODOS</button>
<button id="btn-clear-selection" style="width: 100%; padding: 10px; margin: 5px 0; background: #ff9800; color: white; border: none; border-radius: 6px; cursor: pointer; font-weight: bold;">🗑️ Limpiar Selección</button>
</div>
<!-- Panel de progreso (cuando está descargando) -->
<div id="progress-panel" style="display: none;">
<div id="progress-title" style="font-size: 14px; font-weight: bold; margin: 10px 0;">Preparando...</div>
<div style="background: rgba(255,255,255,0.4); height: 12px; border-radius: 6px; overflow: hidden;">
<div id="progress-bar-fill" style="height: 100%; width: 0%; background: white; transition: width 0.3s ease;"></div>
</div>
<div style="display: flex; justify-content: space-between; margin-top: 8px; font-size: 12px; font-weight: bold;">
<span id="progress-count">0 / 0</span>
<span id="progress-percent">0%</span>
</div>
<div id="progress-status" style="margin-top: 10px; font-size: 11px; opacity: 0.9;"></div>
</div>
</div> </div>
<div style="background: rgba(255,255,255,0.4); height: 15px; border-radius: 8px; overflow: hidden; box-shadow: inset 0 2px 4px rgba(0,0,0,0.2);">
<div id="progress-bar-fill" style="height: 100%; width: 0%; background: white; transition: width 0.4s ease; box-shadow: 0 2px 8px rgba(255,255,255,0.5);"></div>
</div>
<div style="display: flex; justify-content: space-between; margin-top: 12px; font-size: 14px; font-weight: bold;">
<span id="progress-count">0 / 0</span>
<span id="progress-percent">0%</span>
</div>
<div id="progress-status" style="margin-top: 15px; font-size: 13px; text-align: center; opacity: 0.9;"></div>
`; `;
// Agregar event listeners a los botones
setTimeout(() => {
const btnDownloadSelected = document.getElementById('btn-download-selected');
const btnDownloadAll = document.getElementById('btn-download-all');
const btnClearSelection = document.getElementById('btn-clear-selection');
if (btnDownloadSelected) {
btnDownloadSelected.addEventListener('click', () => {
console.log('🎯 Click: Descargar Seleccionados');
// Enviar mensaje al popup.js para ejecutar la descarga
chrome.runtime.sendMessage({ action: 'triggerDownloadSelected' });
});
}
if (btnDownloadAll) {
btnDownloadAll.addEventListener('click', () => {
console.log('🎯 Click: Descargar TODOS');
chrome.runtime.sendMessage({ action: 'triggerDownloadAll' });
});
}
if (btnClearSelection) {
btnClearSelection.addEventListener('click', () => {
console.log('🎯 Click: Limpiar Selección');
selectedMangas.clear();
updateSelectedCount();
const countEl = document.getElementById('selected-count');
if (countEl) countEl.textContent = '0';
});
}
// Actualizar contador inicialmente
const countEl = document.getElementById('selected-count');
if (countEl) countEl.textContent = selectedMangas.size.toString();
}, 100);
console.log('✅ Popup creado, agregando al DOM...'); console.log('✅ Popup creado, agregando al DOM...');
document.body.appendChild(popup); document.body.appendChild(popup);
console.log('✅ Popup agregado al DOM:', popup); console.log('✅ Popup agregado al DOM:', popup);
@@ -78,6 +127,16 @@
const percent = total > 0 ? Math.round((current / total) * 100) : 0; const percent = total > 0 ? Math.round((current / total) * 100) : 0;
console.log(`📈 Porcentaje calculado: ${percent}%`); console.log(`📈 Porcentaje calculado: ${percent}%`);
// Cambiar a panel de progreso
const controlPanel = document.getElementById('control-panel');
const progressPanel = document.getElementById('progress-panel');
if (controlPanel && progressPanel) {
controlPanel.style.display = 'none';
progressPanel.style.display = 'block';
console.log('🔄 Cambiado a panel de progreso');
}
const titleEl = document.getElementById('progress-title'); const titleEl = document.getElementById('progress-title');
const countEl = document.getElementById('progress-count'); const countEl = document.getElementById('progress-count');
const percentEl = document.getElementById('progress-percent'); const percentEl = document.getElementById('progress-percent');
@@ -121,15 +180,28 @@
// Ocultar progreso // Ocultar progreso
function hideProgress() { function hideProgress() {
console.log('🙈 hideProgress() llamado');
const popup = document.getElementById('mass-downloader-progress-popup'); const popup = document.getElementById('mass-downloader-progress-popup');
if (popup) { if (popup) {
setTimeout(() => { // Cambiar de vuelta al panel de control
popup.style.opacity = '0'; const controlPanel = document.getElementById('control-panel');
popup.style.transition = 'opacity 0.5s ease'; const progressPanel = document.getElementById('progress-panel');
setTimeout(() => {
popup.remove(); if (controlPanel && progressPanel) {
}, 500); progressPanel.style.display = 'none';
}, 1000); controlPanel.style.display = 'block';
console.log('🔄 Cambiado a panel de control');
// Actualizar contador
const countEl = document.getElementById('selected-count');
if (countEl) {
countEl.textContent = selectedMangas.size.toString();
console.log('🔢 Contador actualizado:', countEl.textContent);
}
}
// NO remover el popup, solo cambiar de panel
} }
} }
@@ -170,6 +242,22 @@
console.log('🙈 Ocultando progreso'); console.log('🙈 Ocultando progreso');
hideProgress(); hideProgress();
sendResponse({ success: true }); sendResponse({ success: true });
} else if (request.action === 'updateSelectedCount') {
const countEl = document.getElementById('selected-count');
if (countEl) {
countEl.textContent = request.count.toString();
console.log('🔢 Contador actualizado:', countEl.textContent);
}
sendResponse({ success: true });
} else if (request.action === 'triggerDownloadSelected') {
console.log('🎯 Trigger: Descargar Seleccionados');
// Enviar mensaje al popup.js para ejecutar la descarga
chrome.runtime.sendMessage({ action: 'executeDownloadSelected' });
sendResponse({ success: true });
} else if (request.action === 'triggerDownloadAll') {
console.log('🎯 Trigger: Descargar TODOS');
chrome.runtime.sendMessage({ action: 'executeDownloadAll' });
sendResponse({ success: true });
} else { } else {
console.log('❓ Acción desconocida:', request.action); console.log('❓ Acción desconocida:', request.action);
} }