diff --git a/lib/form_filler.mjs b/lib/form_filler.mjs index d28785e..d2b67bf 100644 --- a/lib/form_filler.mjs +++ b/lib/form_filler.mjs @@ -411,7 +411,16 @@ Answer:`; // Fieldsets (radios and checkbox groups) for (const fs of await container.$$('fieldset')) { - const leg = await fs.$eval('legend', el => el.textContent.trim()).catch(() => ''); + const leg = await fs.$eval('legend', el => { + let raw = (el.textContent || '').replace(/\s+/g, ' ').replace(/\s*\*\s*$/, '').replace(/\s*Required\s*$/i, '').trim(); + if (raw.length > 8) { + for (let len = Math.ceil(raw.length / 2); len >= 4; len--) { + const candidate = raw.slice(0, len); + if (raw.startsWith(candidate + candidate)) { raw = candidate.trim(); break; } + } + } + return raw; + }).catch(() => ''); if (!leg) continue; const anyChecked = await fs.$('input:checked'); if (anyChecked) continue;