diff --git a/background.jpg b/background.jpg index 16c205c..88e4466 100644 Binary files a/background.jpg and b/background.jpg differ diff --git a/exam/Scripts/examInfo.js b/exam/Scripts/examInfo.js index d0d89c9..81ee081 100644 --- a/exam/Scripts/examInfo.js +++ b/exam/Scripts/examInfo.js @@ -11,6 +11,24 @@ document.addEventListener("DOMContentLoaded", () => { let offsetTime = getCookie("offsetTime") || 0; function fetchData() { + // 优先使用本地配置 + const localConfig = localStorage.getItem('localExamConfig'); + if (localConfig) { + try { + const data = JSON.parse(localConfig); + displayExamInfo(data); + updateCurrentTime(); + updateExamInfo(data); + setInterval(() => updateCurrentTime(), 1000); + setInterval(() => updateExamInfo(data), 1000); + return Promise.resolve(); + } catch (error) { + localStorage.removeItem('localExamConfig'); + errorSystem.show('本地配置无效,已切换至默认配置'); + } + } + + // 使用默认配置 return fetch('exam_config.json', { cache: "no-store" }) .then(response => response.json()) .then(data => { diff --git a/exam/Scripts/settings.js b/exam/Scripts/settings.js index 0f57755..9a4da35 100644 --- a/exam/Scripts/settings.js +++ b/exam/Scripts/settings.js @@ -9,6 +9,8 @@ document.addEventListener("DOMContentLoaded", () => { const zoomInput = document.getElementById("zoom-input"); const themeToggle = document.getElementById("theme-toggle"); const themeLink = document.getElementById("theme-link"); + const configFileInput = document.getElementById("config-file"); + const clearConfigBtn = document.getElementById("clear-config-btn"); let offsetTime = getCookie("offsetTime") || 0; let room = getCookie("room") || ""; @@ -79,6 +81,58 @@ document.addEventListener("DOMContentLoaded", () => { themeLink.href = theme === "light" ? "Styles/light.css" : "Styles/dark.css"; }); + configFileInput.addEventListener("change", (event) => { + try { + const file = event.target.files[0]; + if (!file) return; + + const reader = new FileReader(); + reader.onload = (e) => { + try { + const config = JSON.parse(e.target.result); + + // 验证配置文件格式 + if (!config.examInfos || !Array.isArray(config.examInfos)) { + throw new Error("无效的配置文件格式"); + } + + // 验证每个考试信息 + config.examInfos.forEach(exam => { + if (!exam.name || !exam.start || !exam.end) { + throw new Error("考试信息不完整"); + } + // 验证日期格式 + if (isNaN(new Date(exam.start).getTime()) || isNaN(new Date(exam.end).getTime())) { + throw new Error("无效的日期格式"); + } + }); + + // 保存配置到本地存储 + localStorage.setItem('localExamConfig', JSON.stringify(config)); + errorSystem.show('配置文件已加载,将在下次启动时生效'); + + } catch (error) { + errorSystem.show('配置文件格式错误: ' + error.message); + } + }; + reader.readAsText(file); + } catch (e) { + errorSystem.show('读取文件失败: ' + e.message); + } + }); + + clearConfigBtn.addEventListener("click", () => { + try { + if (confirm("确定要清除本地配置吗?这将恢复使用默认配置文件。")) { + localStorage.removeItem('localExamConfig'); + configFileInput.value = ''; // 清空文件选择 + errorSystem.show('本地配置已清除,将在下次启动时生效'); + } + } catch (e) { + errorSystem.show('清除配置失败: ' + e.message); + } + }); + try { document.body.style.zoom = zoomLevel; } catch (e) { diff --git a/exam/Styles/dark.css b/exam/Styles/dark.css index 691ea81..fbb0731 100644 --- a/exam/Styles/dark.css +++ b/exam/Styles/dark.css @@ -410,3 +410,54 @@ input:checked + .slider:before { justify-content: space-between; gap: 10px; } + +.config-file-container { + margin: 12px 0; + padding: 10px; + border: 1px solid #555; + border-radius: 5px; + background-color: rgba(31, 31, 31, 0.5); +} + +.config-file-container label { + display: block; + margin-bottom: 8px; + color: #e0e0e0; +} + +.config-file-container input[type="file"] { + display: block; + width: 100%; + padding: 8px; + border: 1px solid #555; + border-radius: 4px; + background-color: #222; + color: #e0e0e0; + cursor: pointer; +} + +.config-file-container input[type="file"]:hover { + background-color: #333; +} + +.file-hint { + margin-top: 4px; + font-size: 12px; + color: #888; +} + +.config-control-btn { + margin-top: 10px; + padding: 8px 16px; + background-color: #d9534f; + color: white; + border: none; + border-radius: 4px; + cursor: pointer; + font-size: 14px; + transition: background-color 0.3s ease; +} + +.config-control-btn:hover { + background-color: #c9302c; +} diff --git a/exam/Styles/light.css b/exam/Styles/light.css index 95c7691..3c70d93 100644 --- a/exam/Styles/light.css +++ b/exam/Styles/light.css @@ -415,3 +415,54 @@ input:checked + .slider:before { justify-content: space-between; gap: 10px; } + +.config-file-container { + margin: 12px 0; + padding: 10px; + border: 1px solid #ccc; + border-radius: 5px; + background-color: rgba(255, 255, 255, 0.5); +} + +.config-file-container label { + display: block; + margin-bottom: 8px; + color: #333; +} + +.config-file-container input[type="file"] { + display: block; + width: 100%; + padding: 8px; + border: 1px solid #ccc; + border-radius: 4px; + background-color: #fff; + color: #333; + cursor: pointer; +} + +.config-file-container input[type="file"]:hover { + background-color: #f5f5f5; +} + +.file-hint { + margin-top: 4px; + font-size: 12px; + color: #666; +} + +.config-control-btn { + margin-top: 10px; + padding: 8px 16px; + background-color: #d9534f; + color: white; + border: none; + border-radius: 4px; + cursor: pointer; + font-size: 14px; + transition: background-color 0.3s ease; +} + +.config-control-btn:hover { + background-color: #c9302c; +} diff --git a/exam/exam_config.json b/exam/exam_config.json index cf37394..43ac6ae 100644 --- a/exam/exam_config.json +++ b/exam/exam_config.json @@ -5,43 +5,43 @@ "examInfos": [ { "name": "语文", - "start": "2025-03-27T07:20:00", - "end": "2025-03-27T09:50:00" + "start": "2025-03-30T07:20:00", + "end": "2025-03-30T09:50:00" }, { "name": "物理", - "start": "2025-03-27T10:20:00", - "end": "2025-03-27T11:50:00" + "start": "2025-03-30T10:20:00", + "end": "2025-03-30T11:50:00" }, { "name": "英语", - "start": "2025-03-27T14:10:00", - "end": "2025-03-27T16:10:00" + "start": "2025-03-30T14:10:00", + "end": "2025-03-30T23:50:00" }, { "name": "历史", - "start": "2025-03-27T16:30:00", - "end": "2025-03-27T18:00:00" + "start": "2025-03-30T23:55:00", + "end": "2025-03-31T01:00:00" }, { "name": "数学", - "start": "2025-03-28T07:50:00", - "end": "2025-03-28T09:50:00" + "start": "2025-03-31T07:50:00", + "end": "2025-03-31T09:50:00" }, { "name": "化学", - "start": "2025-03-28T10:20:00", - "end": "2025-03-28T11:50:00" + "start": "2025-03-31T10:20:00", + "end": "2025-03-31T11:50:00" }, { - "name": "生物、政治", - "start": "2025-03-28T14:10:00", - "end": "2025-03-28T15:40:00" + "name": "生物/政治", + "start": "2025-03-31T14:10:00", + "end": "2025-03-31T15:40:00" }, { "name": "地理", - "start": "2025-03-28T16:10:00", - "end": "2025-03-28T17:40:00" + "start": "2025-03-31T16:10:00", + "end": "2025-03-31T17:40:00" } ] } diff --git a/exam/index.html b/exam/index.html index 606075d..59ad297 100644 --- a/exam/index.html +++ b/exam/index.html @@ -59,6 +59,12 @@ +
+ + +
支持.json格式文件
+ +