refactor: improve bounty extraction logic and enhance character selection in infinite mode
This commit is contained in:
@@ -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[^>]*>.*?<\/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 <br> tag
|
||||
const firstValue = text.split('<br')[0].trim();
|
||||
let cleanText = firstValue.replace(/<[^>]*>/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 <br>
|
||||
const secondValue = text.split('<br>')[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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user