mirror of
https://github.com/ExamAware/ExamSchedule.git
synced 2025-04-29 02:56:32 +00:00
refactor: 史诗级重构拆分多年狮山代码
This commit is contained in:
parent
dc0e5c20ef
commit
a2ba88ef29
@ -7,42 +7,26 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
const remainingTimeElem = document.getElementById("remaining-time");
|
||||
const statusElem = document.getElementById("status");
|
||||
const examTableBodyElem = document.getElementById("exam-table-body");
|
||||
const fullscreenBtn = document.getElementById("fullscreen-btn");
|
||||
const settingsBtn = document.getElementById("settings-btn");
|
||||
const settingsModal = document.getElementById("settings-modal");
|
||||
const closeSettingsBtn = document.getElementById("close-settings-btn");
|
||||
const saveSettingsBtn = document.getElementById("save-settings-btn");
|
||||
const offsetTimeInput = document.getElementById("offset-time");
|
||||
const roomInput = document.getElementById("room-input");
|
||||
const roomElem = document.getElementById("room");
|
||||
const zoomInput = document.getElementById("zoom-input");
|
||||
|
||||
let offsetTime = getCookie("offsetTime") || 0;
|
||||
let room = getCookie("room") || "";
|
||||
let zoomLevel = getCookie("zoomLevel") || 1;
|
||||
|
||||
offsetTime = parseInt(offsetTime);
|
||||
roomElem.textContent = room;
|
||||
const roomElem = document.getElementById("room"); // 添加这一行
|
||||
let offsetTime = getCookie("offsetTime") || 0; // 添加这一行
|
||||
|
||||
function fetchData() {
|
||||
return fetch('exam_config.json', { cache: "no-store" }) // 不保留缓存
|
||||
return fetch('exam_config.json', { cache: "no-store" })
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
displayExamInfo(data);
|
||||
updateCurrentTime();
|
||||
updateExamInfo(data);
|
||||
setInterval(() => updateCurrentTime(), 1000); // Update current time every second
|
||||
setInterval(() => updateExamInfo(data), 1000); // Update exam info every second
|
||||
setInterval(() => updateCurrentTime(), 1000);
|
||||
setInterval(() => updateExamInfo(data), 1000);
|
||||
})
|
||||
.catch(error => console.error('Error fetching exam data:', error));
|
||||
}
|
||||
|
||||
function displayExamInfo(data) {
|
||||
// Display exam name
|
||||
const examNameText = data.examName;
|
||||
const roomText = roomElem.textContent;
|
||||
examNameElem.innerHTML = `${examNameText} <span id="room">${roomText}</span>`;
|
||||
// Display message
|
||||
messageElem.textContent = data.message;
|
||||
}
|
||||
|
||||
@ -51,11 +35,6 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
currentTimeElem.textContent = now.toLocaleTimeString('zh-CN', { hour12: false });
|
||||
}
|
||||
|
||||
function formatTimeWithoutSeconds(time) {
|
||||
// Convert time to string and remove seconds if present
|
||||
return time.slice(0, -3);
|
||||
}
|
||||
|
||||
function updateExamInfo(data) {
|
||||
const now = new Date(new Date().getTime() + offsetTime * 1000);
|
||||
let currentExam = null;
|
||||
@ -135,7 +114,6 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
statusElem.style.color = "#3946AF";
|
||||
}
|
||||
|
||||
// Update next exams table
|
||||
examTableBodyElem.innerHTML = "";
|
||||
data.examInfos.forEach(exam => {
|
||||
const start = new Date(exam.start);
|
||||
@ -160,64 +138,5 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
});
|
||||
}
|
||||
|
||||
// Fullscreen functionality
|
||||
fullscreenBtn.addEventListener("click", () => {
|
||||
if (!document.fullscreenElement) {
|
||||
document.documentElement.requestFullscreen();
|
||||
} else {
|
||||
if (document.exitFullscreen) {
|
||||
document.exitFullscreen();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Open settings modal
|
||||
settingsBtn.addEventListener("click", () => {
|
||||
offsetTimeInput.value = offsetTime;
|
||||
roomInput.value = room;
|
||||
zoomInput.value = zoomLevel;
|
||||
settingsModal.style.display = "block";
|
||||
});
|
||||
|
||||
// Close settings modal
|
||||
closeSettingsBtn.addEventListener("click", () => {
|
||||
settingsModal.style.display = "none";
|
||||
});
|
||||
|
||||
// Save settings
|
||||
saveSettingsBtn.addEventListener("click", () => {
|
||||
offsetTime = parseInt(offsetTimeInput.value);
|
||||
room = roomInput.value;
|
||||
zoomLevel = parseFloat(zoomInput.value);
|
||||
setCookie("offsetTime", offsetTime, 365);
|
||||
setCookie("room", room, 365);
|
||||
setCookie("zoomLevel", zoomLevel, 365);
|
||||
roomElem.textContent = room;
|
||||
document.body.style.zoom = zoomLevel;
|
||||
settingsModal.style.display = "none";
|
||||
});
|
||||
|
||||
document.body.style.zoom = zoomLevel;
|
||||
|
||||
// Utility function to set a cookie
|
||||
function setCookie(name, value, days) {
|
||||
const d = new Date();
|
||||
d.setTime(d.getTime() + (days * 24 * 60 * 60 * 1000));
|
||||
const expires = "expires=" + d.toUTCString();
|
||||
document.cookie = name + "=" + value + ";" + expires + ";path=/";
|
||||
}
|
||||
|
||||
// Utility function to get a cookie
|
||||
function getCookie(name) {
|
||||
const nameEQ = name + "=";
|
||||
const ca = document.cookie.split(';');
|
||||
for (let i = 0; i < ca.length; i++) {
|
||||
let c = ca[i];
|
||||
while (c.charAt(0) === ' ') c = c.substring(1, c.length);
|
||||
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
fetchData();
|
||||
});
|
13
exam/Scripts/main.js
Normal file
13
exam/Scripts/main.js
Normal file
@ -0,0 +1,13 @@
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
const fullscreenBtn = document.getElementById("fullscreen-btn");
|
||||
|
||||
fullscreenBtn.addEventListener("click", () => {
|
||||
if (!document.fullscreenElement) {
|
||||
document.documentElement.requestFullscreen();
|
||||
} else {
|
||||
if (document.exitFullscreen) {
|
||||
document.exitFullscreen();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
42
exam/Scripts/settings.js
Normal file
42
exam/Scripts/settings.js
Normal file
@ -0,0 +1,42 @@
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
const settingsBtn = document.getElementById("settings-btn");
|
||||
const settingsModal = document.getElementById("settings-modal");
|
||||
const closeSettingsBtn = document.getElementById("close-settings-btn");
|
||||
const saveSettingsBtn = document.getElementById("save-settings-btn");
|
||||
const offsetTimeInput = document.getElementById("offset-time");
|
||||
const roomInput = document.getElementById("room-input");
|
||||
const roomElem = document.getElementById("room");
|
||||
const zoomInput = document.getElementById("zoom-input");
|
||||
|
||||
let offsetTime = getCookie("offsetTime") || 0;
|
||||
let room = getCookie("room") || "";
|
||||
let zoomLevel = getCookie("zoomLevel") || 1;
|
||||
|
||||
offsetTime = parseInt(offsetTime);
|
||||
roomElem.textContent = room;
|
||||
|
||||
settingsBtn.addEventListener("click", () => {
|
||||
offsetTimeInput.value = offsetTime;
|
||||
roomInput.value = room;
|
||||
zoomInput.value = zoomLevel;
|
||||
settingsModal.style.display = "block";
|
||||
});
|
||||
|
||||
closeSettingsBtn.addEventListener("click", () => {
|
||||
settingsModal.style.display = "none";
|
||||
});
|
||||
|
||||
saveSettingsBtn.addEventListener("click", () => {
|
||||
offsetTime = parseInt(offsetTimeInput.value);
|
||||
room = roomInput.value;
|
||||
zoomLevel = parseFloat(zoomInput.value);
|
||||
setCookie("offsetTime", offsetTime, 365);
|
||||
setCookie("room", room, 365);
|
||||
setCookie("zoomLevel", zoomLevel, 365);
|
||||
roomElem.textContent = room;
|
||||
document.body.style.zoom = zoomLevel;
|
||||
settingsModal.style.display = "none";
|
||||
});
|
||||
|
||||
document.body.style.zoom = zoomLevel;
|
||||
});
|
21
exam/Scripts/utils.js
Normal file
21
exam/Scripts/utils.js
Normal file
@ -0,0 +1,21 @@
|
||||
function setCookie(name, value, days) {
|
||||
const d = new Date();
|
||||
d.setTime(d.getTime() + (days * 24 * 60 * 60 * 1000));
|
||||
const expires = "expires=" + d.toUTCString();
|
||||
document.cookie = name + "=" + value + ";" + expires + ";path=/";
|
||||
}
|
||||
|
||||
function getCookie(name) {
|
||||
const nameEQ = name + "=";
|
||||
const ca = document.cookie.split(';');
|
||||
for (let i = 0; i < ca.length; i++) {
|
||||
let c = ca[i];
|
||||
while (c.charAt(0) === ' ') c = c.substring(1, c.length);
|
||||
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function formatTimeWithoutSeconds(time) {
|
||||
return time.slice(0, -3);
|
||||
}
|
@ -2,7 +2,7 @@ body {
|
||||
font-family: 'HarmonyOS Sans SC Regular', 'Roboto', Arial, sans-serif;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
background: url('../background.jpg') no-repeat center center fixed;
|
||||
background: url('../../background.jpg') no-repeat center center fixed; /* 更新路径 */
|
||||
background-size: cover;
|
||||
animation: fadeIn 1s;
|
||||
color: #e0e0e0;
|
@ -4,7 +4,7 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Exam Schedule</title>
|
||||
<link rel="stylesheet" href="styles.css">
|
||||
<link rel="stylesheet" href="Styles/dark.css">
|
||||
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500&display=swap" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
@ -60,6 +60,9 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="script.js"></script>
|
||||
<script src="Scripts/utils.js"></script>
|
||||
<script src="Scripts/settings.js"></script>
|
||||
<script src="Scripts/examInfo.js"></script>
|
||||
<script src="Scripts/main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -50,8 +50,6 @@
|
||||
text-align: center;
|
||||
background: rgba(255, 255, 255, 0);
|
||||
padding: 30px;
|
||||
border-radius: 16px;
|
||||
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
|
||||
animation: fadeIn 2s ease-in-out;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user