Skip to content

fix: problem PID 可能为 null#877

Merged
boomzero merged 3 commits intodevfrom
boomzero/getPID
Oct 7, 2025
Merged

fix: problem PID 可能为 null#877
boomzero merged 3 commits intodevfrom
boomzero/getPID

Conversation

@boomzero
Copy link
Member

@boomzero boomzero commented Oct 7, 2025


What does this PR aim to accomplish?:

This PR fixes a bug where the ProblemSwitcher utility would fail to display a problem's ID (PID) if the user navigated directly to a contest problem page without first visiting the main contest page.

The utility relied on localStorage being populated by a visit to the contest page. Without this preliminary visit, the necessary data wasn't cached, and the PID would not appear next to the problem title. This PR ensures the PID is always displayed, regardless of the user's navigation path.


How does this PR accomplish the above?:

  • Proactive Data Fetching: The script now checks if the problem's PID is available in localStorage. If it is not found, the script automatically sends a fetch request to the main contest page in the background.
  • DOM Parsing & Caching: It then parses the HTML from the fetched contest page, extracts the PIDs for all problems in the contest, and saves them to localStorage.
  • Display PID: After the cache is populated, the script retrieves the correct PID for the current problem and appends it to the <h2> title element as intended.
  • Refactor: A minor code cleanup was performed, removing an unnecessary intermediate variable (result) to make an assignment more direct.

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

@hendragon-bot hendragon-bot bot added the user-script This issue or pull request is related to the main user script label Oct 7, 2025
@pull-request-size pull-request-size bot added size/M and removed size/S labels Oct 7, 2025
@boomzero boomzero merged commit 10d6806 into dev Oct 7, 2025
3 checks passed
@boomzero boomzero deleted the boomzero/getPID branch October 7, 2025 14:06
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.

1 participant