(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(`