(async () => { const toAbs = href => new URL(href, location.origin).href; function parseDoc(doc) { const rows = [...doc.querySelectorAll('table tr')].filter(tr => tr.querySelectorAll('td').length); return rows.map(tr => { const link = tr.querySelector('a[href*="event?e="]'); if (!link) return null; const u = new URL(link.getAttribute('href'), location.origin); const d = u.searchParams.get('d'); // deck ID const tds = tr.querySelectorAll('td'); return { deck_title: link.textContent.trim(), player: (tds[1]?.innerText || '').trim(), deck_id: d ? Number(d) : null }; }).filter(Boolean); } // parse current page const firstPage = parseDoc(document); // find total pages const pageNums = [...document.querySelectorAll('a[href*="current_page="]')] .map(a => Number(new URL(a.href).searchParams.get('current_page'))) .filter(n => Number.isFinite(n)); const maxPage = pageNums.length ? Math.max(...pageNums) : 1; const all = [...firstPage]; const cur = new URL(location.href).searchParams.get('current_page') || ''; const base = new URL(location.href); // get all pages for (let p = 1; p <= maxPage; p++) { if (String(p) === cur) continue; base.searchParams.set('current_page', String(p)); const html = await fetch(base.href, { credentials: 'include' }).then(r => r.text()); const doc = new DOMParser().parseFromString(html, 'text/html'); all.push(...parseDoc(doc)); } // fetch and print each deck for (const deck of all) { if (!deck.deck_id) continue; const txt = await fetch(`/dec?d=${deck.deck_id}`).then(r => r.text()); console.log(`===== ${deck.deck_title} — ${deck.player} =====\n${txt}\n`); } })();