diff --git a/scripts/scrape-onepiece.ts b/scripts/scrape-onepiece.ts index c936cad..4c63bb5 100644 --- a/scripts/scrape-onepiece.ts +++ b/scripts/scrape-onepiece.ts @@ -629,29 +629,22 @@ function extractBounty($: cheerio.CheerioAPI): number | null { const div = $('[data-source="bounty"] .pi-data-value'); if (div.length === 0) return 0; - let text = div.html(); + const cleanedDiv = div.clone(); + // Drop references and old crossed-out bounty values. + cleanedDiv.find('sup, s, del, strike').remove(); + + const text = cleanedDiv.text().replace(/\s+/g, ' ').trim(); if (!text) return 0; - // Remove all sup blocks (citations) - text = text.replace(/]*>.*?<\/sup>/gi, ''); + // Parse the first amount token (e.g. "3,189,000,000"), which is the active bounty. + const amountMatch = text.match(/\d{1,3}(?:[\s,.'’]\d{3})+|\d+/); + if (!amountMatch) return 0; - // Extract the first value before any
tag - const firstValue = text.split(']*>/g, '').trim(); + const digits = amountMatch[0].replace(/\D/g, ''); + if (!digits) return 0; - // Check if cleanText contains digits - if (!/\d/.test(cleanText)) { - // If no digits, try second value after
- const secondValue = text.split('
')[1]; - if (secondValue) { - cleanText = secondValue.replace(/<[^>]*>/g, '').trim(); - } - } - - // Remove all non-digits - cleanText = cleanText.replace(/\D/g, ''); - - return cleanText ? parseInt(cleanText) : 0; + const value = Number(digits); + return Number.isFinite(value) ? value : 0; } /** diff --git a/src/lib/components/ProfileButton.svelte b/src/lib/components/ProfileButton.svelte index afd3639..09bc731 100644 --- a/src/lib/components/ProfileButton.svelte +++ b/src/lib/components/ProfileButton.svelte @@ -1,6 +1,7 @@