feat: 验证码识别不出时自动换一张
What does this PR aim to accomplish?:
When AutoCaptcha declines a 4-digit captcha (too close to call), the user currently has to type it or click the image for a new one. This PR makes the script fetch a new challenge automatically instead.
How does this PR accomplish the above?:
RefreshCaptchanow loops up toCaptchaMaxAttempts(5) times, waiting 300ms between fetches, while the solver keeps returningnull. The status line shows progress (正在自动换一张(2/5)) and falls back to asking for manual input if all of them fail.- Fetching
vcode.phpdoes not count as a failed attempt (only a submitted blank/wrong answer escalates to the 8-char challenge), so retries are safe. - The loop stops as soon as the user starts typing (a new fetch would invalidate the image they're reading), when the image is clicked (the
CaptchaRequestIDcheck), on 8-character challenges, and on network errors. - The submit error paths that
await RefreshCaptchamay now take up to ~1–2s longer in the worst case.
⚠️ Not yet tested in a browser: only node --check was run. Items 3 and 11 need human verification (new UI and classic UI).
By submitting this pull request, I confirm the following:
- I have read and understood the contributor's guide, as well as this entire template.
- I have commented on my proposed changes within the code.
- I have tested my changes.
- I am willing to help maintain this change if there are issues with it later.
- It is compatible with the GNU General Public License v3.0.
- I have squashed any insignificant commits.
- I have checked that another pull request for this purpose does not exist.
- I have considered and confirmed that this submission will be valuable to others.
- I accept that this submission may not be used, and the PR can be closed at the will of the maintainer.
- I give this submission freely and claim no ownership to its content.
- I have verified that my changes work correctly in both the new UI and the old/classic UI.
- I have read the above and my PR is ready for review.
🤖 Generated with Claude Code
Summary by Sourcery
Automatically replace ambiguous captchas during recognition so users can retry without manually changing the image.
New Features:
- Automatically fetch replacement 4-digit captchas when AutoCaptcha cannot confidently recognize the current image, retrying up to five times before requesting manual input.
Bug Fixes:
- Prevent captcha refresh retries from escalating the session to the harder challenge and preserve user-entered answers or newer captcha requests.
Enhancements:
- Stop automatic retries on user interaction, unsupported captcha lengths, and network failures while providing progress and fallback status messages.
Build:
- Bump the userscript and package versions to 3.6.6 and update release metadata.
Summary by cubic
AutoCaptcha now fetches a replacement captcha automatically when it can't read the current one, instead of asking the user to type it or click the image. The captcha input is locked while a replacement loads so a stale image can't be answered. Bumps XMOJ.user.js, Update.json, and package.json to 3.6.6.
- Retries up to 5 times with 300ms between attempts, then falls back to manual input.
- Fetching a replacement doesn't count as an incorrect answer, so retries won't trigger the harder 8-character challenge.
- Retries stop on manual input, image clicks, non-4-digit captchas, or fetch failures.
- Only
node --checkhas been run; both new and classic UIs still need browser verification.