feat: 验证码识别不出时自动换一张

Merged
BO
2mo ago
+69-35

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?:

  • RefreshCaptcha now loops up to CaptchaMaxAttempts (5) times, waiting 300ms between fetches, while the solver keeps returning null. The status line shows progress (正在自动换一张(2/5)) and falls back to asking for manual input if all of them fail.
  • Fetching vcode.php does 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 CaptchaRequestID check), on 8-character challenges, and on network errors.
  • The submit error paths that await RefreshCaptcha may 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:

  1. I have read and understood the contributor's guide, as well as this entire template.
  2. I have commented on my proposed changes within the code.
  3. I have tested my changes.
  4. I am willing to help maintain this change if there are issues with it later.
  5. It is compatible with the GNU General Public License v3.0.
  6. I have squashed any insignificant commits.
  7. I have checked that another pull request for this purpose does not exist.
  8. I have considered and confirmed that this submission will be valuable to others.
  9. I accept that this submission may not be used, and the PR can be closed at the will of the maintainer.
  10. I give this submission freely and claim no ownership to its content.
  11. 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 --check has been run; both new and classic UIs still need browser verification.