fix: 修复错误页面和多subtask测试点页面的 TypeError (#1009)

Closed
BO
2mo ago
+219-219
  • contest.php: 比赛私有/不存在的 403/404 页面没有 h3 和比赛信息,跳过处理
  • problem.php: 错误页面不再显示题目切换器,题目列表为空时不再报错,
    没有提交按钮或题目内容时跳过相关处理
  • reinfo.php: 多subtask时遍历所有分组并跳过结构不同的元素;无权查看时不再报错

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_0135Ggqqp6xktQZytLRJQ9nc


Summary by cubic

修复了 XMOJ.user.js 中错误页面和多 subtask 测试点页面的 TypeError,避免页面在缺少预期 DOM 结构时崩溃。

  • 统一在每次使用 querySelector 结果前增加 null 检查,替代原先针对 contest.php、problem.php、reinfo.php 的零散修复。
  • 错误页面(如比赛不存在或无权访问)不再渲染题目切换器等缺失元素。
  • 遍历 subtask 分组时跳过结构不同的元素,无权限查看时不再报错。

Summary by Sourcery

Harden the userscript against missing or unexpected page elements so error pages and multi-subtask views no longer cause runtime failures.

Bug Fixes:

  • Prevent TypeErrors when processing error, unauthorized, missing-content, and structurally different XMOJ pages.
  • Handle contests, problems, user statistics, submission forms, rankings, and test-point pages safely when expected DOM elements are absent.
  • Support multi-subtask test-point pages by processing available groups without assuming a uniform structure.

Enhancements:

  • Make page customization logic resilient across incomplete or unexpected page layouts by skipping unavailable elements and using empty collections where appropriate.