feat: 验证码识别不出时自动换一张 - #1023
feat: 验证码识别不出时自动换一张#1023
Conversation
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Reviewer's GuideUpdates captcha refresh handling to automatically try up to five newly fetched images when AutoCaptcha cannot confidently recognize a 4-digit challenge, while guarding against stale requests, user interaction, unsupported challenge lengths, and network failures before falling back to manual entry. Sequence diagram for automatic captcha retrysequenceDiagram
participant User
participant RefreshCaptcha
participant CaptchaServer
participant SolveCaptcha
participant CaptchaInput
RefreshCaptcha->>CaptchaServer: fetch(vcode.php)
CaptchaServer-->>RefreshCaptcha: ImageBlob
RefreshCaptcha->>SolveCaptcha: SolveCaptcha(ImageBlob)
SolveCaptcha-->>RefreshCaptcha: null
loop up to CaptchaMaxAttempts (5)
RefreshCaptcha->>RefreshCaptcha: wait 300ms
RefreshCaptcha->>CaptchaServer: fetch(vcode.php)
CaptchaServer-->>RefreshCaptcha: ImageBlob
RefreshCaptcha->>SolveCaptcha: SolveCaptcha(ImageBlob)
SolveCaptcha-->>RefreshCaptcha: answer or null
end
alt answer recognized
RefreshCaptcha->>CaptchaInput: set value
else user starts typing or clicks image
RefreshCaptcha-->>User: stop retrying
else all attempts declined
RefreshCaptcha-->>User: request manual input
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="XMOJ.user.js" line_range="4419-4420" />
<code_context>
+ const CaptchaResponse = await fetch("https://www.xmoj.tech/vcode.php?" + Math.random(), {cache: "no-store"});
</code_context>
<issue_to_address>
**issue (bug_risk):** When the user starts typing while a captcha fetch is in progress, the completed fetch still revokes the displayed image and replaces it before checking `CaptchaInput.value`. The typed answer therefore targets the old image while the session expects the newly fetched challenge.
**Triggers:** When the user begins entering an answer before `fetch(...).blob()` resolves.
**Suggested fix:** Check `CaptchaInput.value` again immediately after the blob fetch and before revoking `CaptchaObjectURL` or assigning `CaptchaImage.src`.
```suggestion
if (RequestID !== CaptchaRequestID) return;
if (CaptchaInput.value !== "") return;
if (CaptchaObjectURL !== null) URL.revokeObjectURL(CaptchaObjectURL);
```
</issue_to_address>Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: XMOJ.user.js:4420
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ba08aac5b1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const Answer = await SolveCaptcha(ImageBlob); | ||
| if (RequestID !== CaptchaRequestID) return; | ||
| // Never overwrite what the user has already started typing. | ||
| if (CaptchaInput.value !== "") return; |
There was a problem hiding this comment.
Prevent typing while a retry replaces the challenge
When a user starts manually entering the currently displayed captcha after the pre-fetch check on line 4407 but before the retry fetch and solver finish, vcode.php has already replaced the session's expected answer and the image is replaced on line 4422. This late check then returns while preserving the answer typed from the old image, so the next submission is guaranteed to fail and may escalate the session to the harder captcha. Disable manual entry during an in-flight automatic refresh or otherwise clear/reconcile input when the fetched challenge replaces the displayed one.
Useful? React with 👍 / 👎.
|
Tested and works |
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
What does this PR aim to accomplish?:
When
AutoCaptchadeclines 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.vcode.phpdoes not count as a failed attempt (only a submitted blank/wrong answer escalates to the 8-char challenge), so retries are safe.CaptchaRequestIDcheck), on 8-character challenges, and on network errors.await RefreshCaptchamay now take up to ~1–2s longer in the worst case.node --checkwas run. Items 3 and 11 need human verification (new UI and classic UI).By submitting this pull request, I confirm the following:
🤖 Generated with Claude Code
Summary by Sourcery
Automatically replace ambiguous captchas during recognition so users can retry without manually changing the image.
New Features:
Bug Fixes:
Enhancements:
Build:
Summary by cubic
AutoCaptchanow 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. BumpsXMOJ.user.js,Update.json, andpackage.jsonto 3.6.6.node --checkhas been run; both new and classic UIs still need browser verification.Written for commit abff304. Summary will update on new commits.