自定义主题配置指南

NEUQ 空闲教室总表 · 主题系统 · Ver 3.0

目录
  1. 快速开始
  2. 文件格式
  3. 明暗模式锁定
  4. 导入与管理
  5. 预设主题
  6. 颜色变量参考
  7. 布局变量参考
  8. 完整示例
  9. 常见问题

1. 快速开始

创建一个 .toml 文件,填写需要自定义的字段,然后在页面底部点击「导入主题」按钮选择该文件即可。未填写的字段自动使用默认值。

也可以直接使用页面底部的预设主题下拉菜单,从 7 个内置主题中一键切换。

# my-theme.toml — 最简示例
name = "我的主题"

[light]
body_bg = "#f0f4f8"
h1_text = "#1a365d"
tab_active_text = "#3182ce"
tab_active_border = "#3182ce"
timeslot_title_text = "#3182ce"
link_color = "#3182ce"
提示:项目 assets/themes/ 目录下提供了 7 个预制主题(Tokyo Night、Nord、Catppuccin、Gruvbox、Ayu、Everforest、Kanagawa),可通过下拉菜单直接选择,也可下载 TOML 文件作为编写自定义主题的参考。

2. 文件格式

TOML 文件由以下可选部分组成:

name = "主题名称"         # 可选,显示在页面底部
mode = "light"            # 可选,锁定明暗模式(见第 3 节)

[light]                    # 亮色模式颜色变量(可选)
body_bg = "#f5f5f5"
body_text = "#333"

[dark]                     # 暗色模式颜色变量(可选)
body_bg = "#1a1a2e"
body_text = "#ccc"

[layout]                   # 布局/字号变量(可选,亮暗共用)
font_size_header = "24px"
所有字段均可省略。省略的字段使用系统默认值。[light][dark] 分别控制亮色/暗色模式下的样式,[layout] 中的字号在两种模式下共用。

3. 明暗模式锁定

默认情况下,页面会跟随操作系统的亮色/暗色偏好自动切换。通过设置顶层 mode 字段,可以锁定为固定模式,不再随系统变化。

# 锁定为亮色模式(无视系统偏好)
mode = "light"

# 锁定为暗色模式(无视系统偏好)
mode = "dark"

# 不设置 mode 字段 = 跟随系统(默认行为)
mode 值行为
不设置 / 省略跟随操作系统偏好自动切换(默认)
"light"强制亮色模式,忽略系统偏好
"dark"强制暗色模式,忽略系统偏好
使用场景:如果你的主题只设计了亮色配色,设置 mode = "light" 可以防止系统切换到暗色时出现样式不匹配的问题。反之亦然。

点击页面上的「重置」按钮后,模式锁定会一并解除,恢复跟随系统偏好。

4. 导入与管理

预设主题和自定义导入互斥:选择预设主题后会覆盖之前的自定义主题,导入自定义文件后下拉菜单会自动回到「默认主题」。点击「重置」会同时清除两者。

5. 预设主题

页面底部的下拉菜单提供了以下内置主题,选择即可即时预览并保存:

名称风格文件
Ayu暖粉调ayu.toml
Catppuccin紫罗兰调catppuccin.toml
Everforest森林绿调everforest.toml
Gruvbox复古暖调gruvbox.toml
Kanagawa朱红调kanagawa.toml
Nord北欧蓝调nord.toml
Tokyo Night冷蓝调都市夜景tokyonight.toml
自定义预设:所有预设主题的 TOML 源文件位于项目的 assets/themes/ 目录下,可下载后修改为自己的主题。

6. 颜色变量参考

颜色值支持任何合法的 CSS 颜色格式:#hexrgb()rgba()hsl() 等。

6.1 背景色

TOML 字段控制元素默认值 (亮/暗)
body_bg页面整体背景#f9f9f9 / #121212
badge_bg更新状态徽章背景#7b7b7b / #888
banner_bg顶部通知横幅背景#f9f9f9 / #121212
tab_bar_bgTab 栏背景#f0f0f0 / #2a2a2a
tab_active_bgTab 激活态背景rgba(255,255,255,0.75) / rgba(30,30,30,0.75)
container_bgTab 容器 / 折叠容器背景rgba(255,255,255,0.2) / rgba(30,30,30,0.5)
container_shadow容器阴影2px 4px 3px 2px rgba(0,0,0,0.06) / 0px 2px 5px 1px rgba(0,0,0,0.5)
info_box_bg通知框背景rgba(138,138,138,0.05) / rgba(213,213,213,0.08)

6.2 主文字色

TOML 字段控制元素默认值 (亮/暗)
body_text页面正文文字#474747 / #bbb
collapsible_text折叠容器标题文字#474747 / #bbb
btn_text主题按钮文字(导入/重置)#474747 / #bbb
info_text信息文本(更新时间、版本号等)#7b7b7b / #888
badge_text徽章文字#f9f9f9 / #121212
banner_text横幅文字#7b7b7b / #888
banner_close_text横幅关闭按钮#7b7b7b / #888
collapsible_desc_text折叠区域描述文字#7b7b7b / #888
theme_name_text主题名称显示文字#7b7b7b / #888
h1_text页面大标题#3f3f3f / #ccc
date_display_text日期切换器显示文字#3f3f3f / #ccc

6.3 Tab 文字色

TOML 字段控制元素默认值 (亮/暗)
tab_textTab 按钮文字#888 / #aaa
tab_text_hoverTab 按钮悬停文字#000 / #fff

6.4 悬停背景色

TOML 字段控制元素默认值 (亮/暗)
date_btn_hover_bg日期切换按钮悬停背景#e5e5e5 / #3a3a3a
tab_hover_bgTab 按钮悬停背景#e5e5e5 / #3a3a3a
theme_btn_hover_bg主题按钮悬停背景#e5e5e5 / #3a3a3a

6.5 边框色

TOML 字段控制元素默认值 (亮/暗)
banner_border横幅底边框rgba(137,137,137,0.3) / rgba(213,213,213,0.3)
info_box_border通知框边框rgba(137,137,137,0.3) / rgba(213,213,213,0.3)
container_borderTab 容器边框rgba(137,137,137,0.3) / rgba(213,213,213,0.3)
tab_bar_borderTab 栏底边框#d8d8d8 / #444
tab_btn_borderTab 按钮右边框#d8d8d8 / #444
hr_border分隔线#d8d8d8 / #444
collapsible_border折叠容器边框#d8d8d8 / #444
collapsible_desc_border折叠内容区顶边框#d8d8d8 / #444
theme_btn_border主题按钮边框#d8d8d8 / #444

6.6 表格色

TOML 字段控制元素默认值 (亮/暗)
table_header_text表头文字 (th)inherit
table_header_bg表头背景 (th)#f7f7f7 / #2c2c2c
table_border表格边框#e0e0e0 / #444
floor_label_bg工学馆楼层标签背景 (1F, 2F...)#f7f7f7 / #2c2c2c
floor_label_text工学馆楼层标签文字inherit
building_name_bg本部其它/南校区教学楼名称行背景#f7f7f7 / #2c2c2c
building_name_text本部其它/南校区教学楼名称行文字inherit
info_box_text临时通知框文字#4f4f4f / #ccc

6.7 强调色

TOML 字段控制元素默认值 (亮/暗)
date_btn_icon日期切换箭头图标#777 / #d1d1d1
tab_active_textTab 激活态文字#777 / #d1d1d1
tab_active_borderTab 激活态底部边框#777 / #d1d1d1
timeslot_title_text时间段标题文字(如"第 1-2 节")#777 / #d1d1d1
theme_btn_hover_border主题按钮悬停边框#777 / #d1d1d1

6.8 链接与标记色

TOML 字段控制元素默认值 (亮/暗)
link_color链接文字、下划线装饰色#4e4e4e / #c8c8c8
strong_color加粗文字 (<strong>),表示全天空闲rgb(76,76,76) / #ddd
del_color删除线文字 (<del>)、重置按钮悬停边框gray / #888

7. 布局变量参考

布局变量在 [layout] 部分配置,亮暗模式共用。所有值均为合法的 CSS 长度值(如 14px1.2em1rem)。

TOML 字段控制元素默认值
font_size_table表格整体字号 (table, th)12px
font_size_td表格单元格字号 (td)14px
font_size_header页面大标题字号 (h1)22px
font_size_info信息文本字号(更新时间等)13px
font_size_timeslot时间段标题字号("第 1-2 节")20px
font_size_tabTab 按钮字号17px
font_size_date日期显示字号18px
容器整体宽度不可通过主题配置自定义,固定为 800px

8. 完整示例

8.1 最小配置

只修改一两个变量,其余全部使用默认值:

name = "极简"

[light]
tab_active_text = "#e74c3c"
timeslot_title_text = "#e74c3c"

8.2 锁定暗色模式

name = "永夜"
mode = "dark"

[dark]
body_bg = "#0d1117"
banner_bg = "#161b22"
container_bg = "rgba(13,17,23,0.9)"
body_text = "#c9d1d9"
h1_text = "#f0f6fc"
tab_active_text = "#58a6ff"
tab_active_border = "#58a6ff"
timeslot_title_text = "#58a6ff"
link_color = "#58a6ff"

8.3 完整双色主题

name = "我的主题"

[light]
# 背景色
body_bg = "#f0f4f8"
banner_bg = "#e2e8f0"
tab_bar_bg = "#e8ecf2"
tab_active_bg = "#ffffff"
container_bg = "rgba(255,255,255,0.85)"
container_shadow = "0 4px 20px rgba(0,0,0,0.06)"
info_box_bg = "#edf2f7"

# 文字色
body_text = "#2d3748"
collapsible_text = "#2d3748"
btn_text = "#4a5568"
info_text = "#718096"
badge_text = "#ffffff"
banner_text = "#2d3748"
banner_close_text = "#718096"
collapsible_desc_text = "#718096"
theme_name_text = "#718096"
h1_text = "#1a202c"
date_display_text = "#1a202c"

# Tab
tab_text = "#4a5568"
tab_text_hover = "#1a202c"

# Hover
date_btn_hover_bg = "#d4dbe5"
tab_hover_bg = "#d4dbe5"
theme_btn_hover_bg = "#d4dbe5"

# 边框
banner_border = "#cbd5e0"
info_box_border = "#cbd5e0"
container_border = "#d4dbe5"
tab_bar_border = "#d4dbe5"
tab_btn_border = "#d4dbe5"
hr_border = "#e2e8f0"
collapsible_border = "#d4dbe5"
collapsible_desc_border = "#e2e8f0"
theme_btn_border = "#d4dbe5"

# 表格
table_header_text = "#2d3748"
table_border = "#e2e8f0"
table_header_bg = "#edf2f7"
floor_label_bg = "#e2e8f0"
floor_label_text = "#2d3748"
building_name_bg = "#e2e8f0"
building_name_text = "#2d3748"
info_box_text = "#2d3748"

# 强调色
date_btn_icon = "#3182ce"
tab_active_text = "#3182ce"
tab_active_border = "#3182ce"
timeslot_title_text = "#3182ce"
theme_btn_hover_border = "#3182ce"

# 链接与标记
link_color = "#3182ce"
strong_color = "#e53e3e"
del_color = "#a0aec0"

[dark]
body_bg = "#1a202c"
banner_bg = "#171923"
tab_bar_bg = "#1e2432"
tab_active_bg = "#2d3748"
container_bg = "rgba(26,32,44,0.88)"
container_shadow = "0 4px 20px rgba(0,0,0,0.4)"
info_box_bg = "#1e2432"

body_text = "#e2e8f0"
collapsible_text = "#e2e8f0"
btn_text = "#a0aec0"
info_text = "#718096"
badge_text = "#1a202c"
banner_text = "#e2e8f0"
banner_close_text = "#718096"
collapsible_desc_text = "#718096"
theme_name_text = "#718096"
h1_text = "#f7fafc"
date_display_text = "#f7fafc"

tab_text = "#a0aec0"
tab_text_hover = "#e2e8f0"

date_btn_hover_bg = "#2d3748"
tab_hover_bg = "#2d3748"
theme_btn_hover_bg = "#2d3748"

banner_border = "rgba(45,55,72,0.5)"
info_box_border = "rgba(45,55,72,0.5)"
container_border = "#2d3748"
tab_bar_border = "#2d3748"
tab_btn_border = "#2d3748"
hr_border = "#2d3748"
collapsible_border = "#2d3748"
collapsible_desc_border = "#2d3748"
theme_btn_border = "#2d3748"

table_header_text = "#e2e8f0"
table_border = "#2d3748"
table_header_bg = "#2d3748"
floor_label_bg = "#2d3748"
floor_label_text = "#e2e8f0"
building_name_bg = "#2d3748"
building_name_text = "#e2e8f0"
info_box_text = "#e2e8f0"

date_btn_icon = "#63b3ed"
tab_active_text = "#63b3ed"
tab_active_border = "#63b3ed"
timeslot_title_text = "#63b3ed"
theme_btn_hover_border = "#63b3ed"

link_color = "#63b3ed"
strong_color = "#fc8181"
del_color = "#718096"

[layout]
font_size_table = "12px"
font_size_td = "14px"
font_size_header = "22px"
font_size_info = "13px"
font_size_timeslot = "20px"
font_size_tab = "17px"
font_size_date = "18px"

9. 常见问题

Q: 导入后没有变化?

请检查 TOML 文件中的字符串值是否用双引号包裹(如 body_bg = "#f5f5f5")。颜色值中包含 # 字符,必须用引号括起来。

Q: 只想修改暗色模式,亮色不变?

只写 [dark] 部分即可,[light] 可以完全省略:

name = "仅暗色"
[dark]
body_bg = "#0d1117"
body_text = "#c9d1d9"

Q: 如何让主题始终显示为暗色?

设置 mode = "dark" 即可锁定暗色模式。

Q: 容器宽度可以自定义吗?

不可以。容器宽度固定为 800px,不纳入主题配置。

Q: 主题配置保存在哪里?

保存在浏览器 Cookie 中(名称 neuq_theme_config),有效期 1 年。清除浏览器 Cookie 会丢失自定义主题。


NEUQ Classroom Query · Theme Configuration Guide · Ver 3.0