(async () => { const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); const modal = document.querySelector('#match-modal'); const modalBody = document.querySelector('#match-modal-body'); if (!modalBody) { alert('No se encontró el panel de detalle de Vola. Abre la página de Programación del torneo e inténtalo nuevamente.'); return; } const candidates = new Map(); document.querySelectorAll('td.match.finished .btn-match-detail[data-match]').forEach((el) => { const id = String(el.dataset.match || '').trim(); if (id) candidates.set(id, el); }); document.querySelectorAll('.match-container[data-match]').forEach((el) => { if (!el.querySelector('.match-idx.status-2')) return; const id = String(el.dataset.match || '').trim(); if (id && !candidates.has(id)) candidates.set(id, el); }); document.querySelectorAll('table.match-table.match-status-2[data-id]').forEach((el) => { const id = String(el.dataset.id || '').trim(); if (id && !candidates.has(id)) candidates.set(id, el); }); const items = [...candidates.entries()]; if (!items.length) { alert('No se encontraron partidos finalizados visibles en esta página de Vola.'); return; } const closeModal = async () => { try { if (window.jQuery && typeof window.jQuery.fn?.modal === 'function') { window.jQuery('#match-modal').modal('hide'); } else { modal?.querySelector('.modal-close, .close')?.click(); } } catch (_) {} await sleep(220); }; const waitForDetail = async (id, previousHtml) => { const started = Date.now(); while (Date.now() - started < 12000) { const html = modalBody.innerHTML || ''; const hasScores = /score-team1set1|score-team2set1|score-team1set1-manual|score-team2set1-manual/i.test(html); const hasMatchId = html.includes(`value="${id}"`) || html.includes(`value='${id}'`) || html.includes(id); if (html && html !== previousHtml && hasScores && hasMatchId) return html; await sleep(120); } throw new Error('timeout'); }; const sections = []; const failures = []; let processed = 0; console.log(`[PRO PADEL SERIES] Extrayendo ${items.length} partidos finalizados...`); for (const [id, element] of items) { const previousHtml = modalBody.innerHTML || ''; try { element.scrollIntoView({ block: 'center', behavior: 'auto' }); element.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, view: window })); const detailHtml = await waitForDetail(id, previousHtml); sections.push(`
${detailHtml}
`); processed += 1; console.log(`[PRO PADEL SERIES] ${processed}/${items.length} · partido ${id}`); } catch (error) { failures.push(id); console.warn(`[PRO PADEL SERIES] No se pudo leer el partido ${id}.`, error); } await closeModal(); await sleep(180); } const generatedAt = new Date().toISOString(); const output = `Vola resultados masivos${sections.join('\n')}`; const blob = new Blob([output], { type: 'text/html;charset=utf-8' }); const url = URL.createObjectURL(blob); const link = document.createElement('a'); link.href = url; link.download = `vola-resultados-masivos-${generatedAt.slice(0,10)}.html`; document.body.appendChild(link); link.click(); link.remove(); setTimeout(() => URL.revokeObjectURL(url), 1000); const message = failures.length ? `Listo: ${sections.length} partidos extraídos. No se pudieron leer ${failures.length}: ${failures.join(', ')}` : `Listo: ${sections.length} partidos extraídos correctamente.`; console.log(`[PRO PADEL SERIES] ${message}`); alert(message + '\n\nAhora sube el archivo descargado en PRO PADEL SERIES → Actualizar desde Vola → Subir resultados con sets.'); })();