feat(vtop-login): add MutationObserver for captcha refresh - #23
Conversation
📝 WalkthroughWalkthroughThe captcha-handling logic for the VTOP login page was refactored into a named function, ChangesCaptcha Solving Refactor
Estimated code review effort: 1 (Trivial) | ~5 minutes Sequence Diagram(s)sequenceDiagram
participant DOM as captchaBlock DOM
participant Observer as MutationObserver
participant Solver as solveVtopLoginCaptcha
participant Solve as solve()
Solver->>DOM: query img, captchaStr, submitBtn
Solver->>Solve: solve(img, textB) if both exist
Solver->>DOM: focus submitBtn if exists
DOM-->>Observer: children changed
Observer->>Solver: re-invoke solveVtopLoginCaptcha()
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Pull request overview
This PR improves the VTOP login captcha autofill flow by re-solving the captcha when the captcha UI updates (e.g., after using the refresh button), using a MutationObserver.
Changes:
- Refactored VTOP login captcha handling into a dedicated
solveVtopLoginCaptcha()helper. - Added a
MutationObserveron the captcha container to trigger re-solving when the captcha changes.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if(captchaBlock) { | ||
| var observer = new MutationObserver(function () { | ||
| solveVtopLoginCaptcha(); | ||
| }); | ||
| observer.observe(captchaBlock, { childList: true }); | ||
| } |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
js/captcha/captchaparser.js (1)
258-301: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDuplicated captcha-solve/observer pattern across branches.
solveVtopLoginCaptchamirrors the newly-addedsolveRegistrationCaptcha(lines 280-301) and the earliersolve_captcha+MutationObserverblocks for vtopcc/vtop2 (lines 224-256) — same shape, only selectors differ. Consider extracting a shared helper (e.g.,attachCaptchaSolver({imgSelector, textSelector, submitSelector, observeTarget})) to reduce triplication and ease future maintenance.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@js/captcha/captchaparser.js` around lines 258 - 301, The captcha-solving logic is duplicated across solveVtopLoginCaptcha, solveRegistrationCaptcha, and the earlier solve_captcha/MutationObserver branches, with only selectors changing. Extract the repeated “find image/text/submit, resize image, call solve, focus submit, attach observer” flow into a shared helper such as attachCaptchaSolver or a generalized solveCaptchaForPage, and have each hostname branch pass its specific selectors and observe target.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@js/captcha/captchaparser.js`:
- Around line 258-301: The captcha-solving logic is duplicated across
solveVtopLoginCaptcha, solveRegistrationCaptcha, and the earlier
solve_captcha/MutationObserver branches, with only selectors changing. Extract
the repeated “find image/text/submit, resize image, call solve, focus submit,
attach observer” flow into a shared helper such as attachCaptchaSolver or a
generalized solveCaptchaForPage, and have each hostname branch pass its specific
selectors and observe target.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 36f0564c-62a4-4c1a-9b3d-1c76b6d31df8
📒 Files selected for processing (1)
js/captcha/captchaparser.js
Previous code was not able to autofill captcha on vtop login page when refresh button was clicked.
So, I added MutationObserver to watch captcha changes and autofill whenever refresh button is clicked.
Please review the code.
Summary by CodeRabbit