Skip to content

Fix problem switcher not update#933

Merged
boomzero merged 36 commits intodevfrom
fix-problem-switcher-not-update
Mar 14, 2026
Merged

Fix problem switcher not update#933
boomzero merged 36 commits intodevfrom
fix-problem-switcher-not-update

Conversation

@def-WA2025
Copy link
Member

@def-WA2025 def-WA2025 commented Mar 13, 2026

What does this PR aim to accomplish?

Fix *EX problems not display.

How does this PR accomplish the above?

Update list when click the refresh button. (The refresh button is located at the top of the problem switcher)


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. I understand which branch to base my commits and Pull Requests against.
  2. I have commented on my proposed changes within the code and I have tested my changes.
  3. I am willing to help maintain this change if there are issues with it later.
  4. It is compatible with the GNU General Public License v3.0
  5. I have squashed any insignificant commits. (git rebase)
  6. I have checked that another pull request for this purpose does not exist.
  7. I have considered and confirmed that this submission will be valuable to others.
  8. I accept that this submission may not be used, and the pull request can be closed at the will of the maintainer.
  9. I give this submission freely and claim no ownership to its content.

  • I have read the above and my PR is ready for review. Check this box to confirm

Summary by Sourcery

Fix contest problem switcher updates and add an optional image enlargement utility.

New Features:

  • Add an ImageEnlarger utility that provides a fullscreen image viewer with zoom, pan, navigation, keyboard/touch controls, and image download support.
  • Expose a GetContestProblemList helper on the page to populate and refresh the contest problem list from the contest page.

Bug Fixes:

  • Ensure the contest problem switcher correctly loads and refreshes the problem list so previously missing problems are displayed.

Enhancements:

  • Add a refresh action in the contest problem switcher UI to reload the problem list on demand.
  • Bump the userscript version from 3.3.0 to 3.3.1 to reflect the new behavior and features.

Summary by cubic

Fixes the contest Problem Switcher so it refreshes reliably and no longer shows empty entries. Adds a manual “刷新” action, exposes GetContestProblemList(), and bumps the script to 3.3.2 with updated Update.json release notes.

  • Bug Fixes

    • Added GetContestProblemList() to fetch/cache contest problems and initialize when missing; clicking “刷新” reloads the list.
    • Prevented null/empty problems when parsing the contest table.
  • New Features

    • Optional Image Enlarger (“图片放大功能”): click images to open a modal with zoom/pan, wheel/keyboard controls, swipe navigation, and download.

Written for commit c87d08f. Summary will update on new commits.

boomzero and others added 27 commits February 8, 2025 09:15
Signed-off-by: Zhu Chenrui <boomzero_zcr@outlook.com>
Signed-off-by: Zhu Chenrui <boomzero_zcr@outlook.com>
(cherry picked from commit 07d7590)

Update feature.yml

Signed-off-by: Zhu Chenrui <boomzero_zcr@outlook.com>
(cherry picked from commit 1a99430)

Update docs.yml

Signed-off-by: Zhu Chenrui <boomzero_zcr@outlook.com>
(cherry picked from commit 6017bcf)
Signed-off-by: Shan Wenxiao <seanoj_noreply@yeah.net>
…ns[bot]

This prevents infinite loops where the bot commits version updates,
which triggers the workflow again, causing another commit.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
The last-commit-author guard now only exits for non-edited events,
so PR title/body changes still update Update.json metadata even
when the branch tip is a github-actions[bot] commit.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Exclude all bot actors (not just github-actions[bot]) from triggering
the UpdateVersion workflow, preventing loops from AI code review bots.
Allow edited events through the script-level guard so PR title/body
changes still update Update.json metadata.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sourcery-ai
Copy link

sourcery-ai bot commented Mar 13, 2026

Reviewer's Guide

Refactors how contest problem lists are loaded and refreshed in the problem switcher and adds an optional image enlargement utility with modal viewing, zoom, pan, navigation, and download support.

Sequence diagram for contest problem switcher refresh

sequenceDiagram
    actor User
    participant ProblemSwitcherUI
    participant GetContestProblemList
    participant XMOJServer
    participant LocalStorage
    participant Browser

    User->>ProblemSwitcherUI: Load contest page with script
    ProblemSwitcherUI->>LocalStorage: getItem(UserScript_Contest_cid_ProblemList)
    alt ProblemList not in LocalStorage
        ProblemSwitcherUI->>GetContestProblemList: GetContestProblemList(false)
        GetContestProblemList->>XMOJServer: fetch(contest.php?cid=cid)
        XMOJServer-->>GetContestProblemList: HTML contest page
        GetContestProblemList->>GetContestProblemList: Parse DOM and extract problem rows
        GetContestProblemList->>LocalStorage: setItem(UserScript_Contest_cid_ProblemList, problemList)
        GetContestProblemList-->>ProblemSwitcherUI: return
        ProblemSwitcherUI->>LocalStorage: getItem(UserScript_Contest_cid_ProblemList)
    end
    ProblemSwitcherUI->>Browser: Render problemSwitcher and problem buttons

    User->>ProblemSwitcherUI: Click refresh link in problemSwitcher
    ProblemSwitcherUI->>GetContestProblemList: GetContestProblemList(true)
    GetContestProblemList->>XMOJServer: fetch(contest.php?cid=cid)
    XMOJServer-->>GetContestProblemList: HTML contest page
    GetContestProblemList->>GetContestProblemList: Parse DOM and rebuild problemList
    GetContestProblemList->>LocalStorage: setItem(UserScript_Contest_cid_ProblemList, problemList)
    GetContestProblemList->>Browser: location.reload()
    Browser->>ProblemSwitcherUI: Reload page and rebuild problemSwitcher from updated list
Loading

Class diagram for updated problem loader and new image enlarger utility

classDiagram
    class ProblemSwitcherModule {
        +main()
        +UtilityEnabled(utilityName)
    }

    class GetContestProblemListUtility {
        +GetContestProblemList(RefreshList)
    }

    class ImageEnlargerUtility {
        +initImageEnlarger()
        +OpenImageModal(imgElement)
        +CloseImageModal()
        +NavigateTo(index)
        +UpdateImageSize()
        +UpdateNavButtons()
        +ApplyEnlargerToImage(img)
        +ApplyEnlargerToImages()
    }

    class ImageModalState {
        -CurrentZoom : number
        -ZoomStep : number
        -MinZoom : number
        -MaxZoom : number
        -ImageList : string[]
        -CurrentImageIndex : number
        -PanX : number
        -PanY : number
        -IsDragging : boolean
        -IsTouchPanning : boolean
        -DragStartX : number
        -DragStartY : number
        -DragStartPanX : number
        -DragStartPanY : number
        -TouchStartX : number
        -TouchStartY : number
        -TouchPanStartPanX : number
        -TouchPanStartPanY : number
    }

    ProblemSwitcherModule --> GetContestProblemListUtility : uses
    ProblemSwitcherModule --> ImageEnlargerUtility : uses when ImageEnlarger enabled
    ImageEnlargerUtility --> ImageModalState : manages
Loading

State diagram for the new image enlargement modal

stateDiagram-v2
    [*] --> Hidden

    Hidden: Modal not visible
    Visible: Modal visible at base zoom
    Zoomed: Image zoomed or panned

    Hidden --> Visible: OpenImageModal
    Visible --> Hidden: CloseImageModal

    Visible --> Zoomed: ZoomIn or ZoomOut or StartPan
    Zoomed --> Zoomed: ContinuePan or ZoomIn or ZoomOut
    Zoomed --> Visible: ResetZoom

    Visible --> Visible: NavigateToNext or NavigateToPrev
    Zoomed --> Zoomed: NavigateToNext or NavigateToPrev

    Visible --> Hidden: EscapeKey or ClickBackdrop
    Zoomed --> Hidden: EscapeKey or ClickBackdrop
Loading

File-Level Changes

Change Details Files
Centralize contest problem list fetching and support refreshing the problem switcher list via a UI control.
  • Extract contest problem list fetch/parse/store logic into a reusable unsafeWindow.GetContestProblemList helper that updates localStorage and optionally reloads the page.
  • Replace inline contest problem list loading with a call to the new helper and subsequent read from localStorage when initializing the problem switcher.
  • Add a visible refresh link/button to the problem switcher that calls GetContestProblemList(true) so users can update the list manually.
XMOJ.user.js
Introduce an opt‑in image enlargement feature that enhances images with a clickable preview and rich modal viewer.
  • Register a new ImageEnlarger toggle in the utilities/settings menu to gate the feature.
  • Inject CSS styles for an image modal, toolbar, navigation controls, and hover effects on previewable images.
  • Create a fullscreen modal with close, zoom, previous/next navigation, keyboard shortcuts, mouse wheel zoom, drag/touch pan, and swipe navigation behavior.
  • Attach click handlers to page images (excluding avatar providers) to open them in the modal and manage a gallery of previewable images.
  • Implement image download via GM_xmlhttpRequest with a blob URL fallback and observe DOM mutations to automatically enable the enlarger for dynamically added images.
  • Wrap the enlarger logic in a try/catch with debug-mode error reporting via SmartAlert.
XMOJ.user.js
Bump the userscript version to reflect the new functionality.
  • Increment @Version metadata from 3.3.0 to 3.3.1.
XMOJ.user.js
Update.json

Possibly linked issues

  • #: Yes. PR updates contest problem list on refresh, fixing the issue where *EX problems don’t appear.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@hendragon-bot hendragon-bot bot added the user-script This issue or pull request is related to the main user script label Mar 13, 2026
cubic-dev-ai[bot]

This comment was marked as resolved.

Copy link
Member

@PythonSmall-Q PythonSmall-Q left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check if the suggestions given by sourcery-ai is true. If so, fix them.

@PythonSmall-Q PythonSmall-Q linked an issue Mar 14, 2026 that may be closed by this pull request
2 tasks
@boomzero
Copy link
Member

Maybe I should fix this? I can just tell Claude to do it(

def-WA2025 and others added 2 commits March 14, 2026 21:40
Signed-off-by: zsTree <wa2025666@gmail.com>
sourcery-ai[bot]

This comment was marked as resolved.

sourcery-ai[bot]

This comment was marked as resolved.

@def-WA2025
Copy link
Member Author

@boomzero @PythonSmall-Q Fixed

@def-WA2025 def-WA2025 mentioned this pull request Mar 14, 2026
2 tasks
@boomzero

This comment was marked as outdated.

@boomzero

This comment was marked as outdated.

@boomzero

This comment was marked as outdated.

@boomzero
Copy link
Member

I think I would merge this one, because of the effort you spent

@boomzero
Copy link
Member

But first, @codex review

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

ℹ️ 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".

@boomzero
Copy link
Member

Oh, okay, then good

@boomzero boomzero enabled auto-merge (squash) March 14, 2026 14:29
boomzero added a commit that referenced this pull request Mar 14, 2026
Takes all logic fixes from PR #933 (GetContestProblemList helper,
null-safe init, XSS fix, ImageEnlarger) while keeping the ↻ button UI
from this branch instead of #933's inline 'refreshList' text link.

- Removed .refreshList CSS and the inline onclick "刷新" element
- Resolved Update.json version conflict: both PRs credited under 3.3.2

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@boomzero
Copy link
Member

@codex review

@boomzero
Copy link
Member

This is a combination of these two PRs that improves the UI

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. Another round soon, please!

ℹ️ 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".

Copy link
Member

@boomzero boomzero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work

@boomzero boomzero merged commit 7119f81 into dev Mar 14, 2026
6 checks passed
@boomzero boomzero deleted the fix-problem-switcher-not-update branch March 14, 2026 14:37
@def-WA2025
Copy link
Member Author

tks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M user-script This issue or pull request is related to the main user script

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Problem Switcher Not Update

3 participants