Skip to content

Commit 24aca82

Browse files
committed
34.4 update
1 parent 62db1cd commit 24aca82

File tree

5 files changed

+68
-18
lines changed

5 files changed

+68
-18
lines changed

.github/workflows/main.yml

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ jobs:
6868
- - 2024/3/30: 已支持最多四周课表轮换,支持配置倒计时上方箭头小三角大小
6969
- - 2024/3/31: 已支持单例模式(软件窗口唯一),替换更容易辨别的倒计时字体
7070
- - 2024/4/02: 已支持课程简写角标,已支持隐藏星期显示与天数倒计时,优化倒计时字体
71+
- - 2024/4/04: 已支持切换日程(将今日使用课表日程设置为本周的星期几, 调休用)
7172
- 喜欢本项目的话, 点击右上角的Star支持一下作者吧😘
7273
draft: false
7374
prerelease: false

image/toggle.png

281 Bytes
Loading

index.html

+35-10
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@
2626
<div class="countdown" id="countdownText">00:00</div>
2727
</div>
2828
</div>
29-
<div class="leftSidebar sidebar background" id="leftSidebar"><span id="weekEN" class="t">Load</span><div class="corner options notIgnoreClick" id="weekCH">ing</div>
30-
</div>
31-
<div class="rightSidebar sidebar background" id="rightSidebar"><span id="countdownDays" class="t">000</span><div class="corner"></div>
32-
</div>
29+
<div class="leftSidebar sidebar background" id="leftSidebar"><span id="weekEN" class="t">Load</span><div class="corner options notIgnoreClick" id="weekCH">ing</div></div>
30+
<div class="rightSidebar sidebar background" id="rightSidebar"><span id="countdownDays" class="t">000</span><div class="corner"></div></div>
3331
</div>
3432
<div class="miniCountdown" id="miniCountdown">00:00</div>
3533

@@ -69,7 +67,7 @@
6967
let classHtml = '';
7068
for (let i = 0; i < scheduleData.scheduleArray.length; i++) {
7169
let inner = scheduleData.scheduleArray[i]
72-
if(scheduleData.scheduleArray[i].indexOf('@') != -1){
70+
if (scheduleData.scheduleArray[i].indexOf('@') != -1) {
7371
inner = `<div><div style="display:inline">${inner.split('@')[0]}</div><div class="subClass">${inner.split('@')[1]}</div></div>`
7472
}
7573
if (scheduleData.currentHighlight.index == i) {
@@ -159,13 +157,13 @@
159157
let data = scheduleConfig.daily_class[week]
160158
weekCH.innerText = data.Chinese
161159
weekEN.innerText = data.English
162-
if(scheduleConfig.countdown_target === 'hidden'){
160+
if (scheduleConfig.countdown_target === 'hidden') {
163161
rightSidebar.style.display = 'none'
164-
}else{
162+
} else {
165163
rightSidebar.style.display = 'block'
166164
countdownDays.innerText = Math.ceil(Math.abs(new Date(scheduleConfig.countdown_target) - date) / (1000 * 60 * 60 * 24))
167165
}
168-
leftSidebar.style.display = scheduleConfig.week_display ? 'block' : 'none'
166+
leftSidebar.style.display = scheduleConfig.week_display ? 'block' : 'none'
169167
}
170168

171169
function tick(reset = false) {
@@ -199,7 +197,7 @@
199197
let timer = undefined
200198
window.addEventListener("mousemove", event => {
201199
if (event.target.className && event.target.className.indexOf('notIgnoreClick') == -1) {
202-
root.style.opacity = '0.3'
200+
root.style.opacity = '0.2'
203201
clearTimeout(timer)
204202
timer = setTimeout(() => {
205203
root.style.opacity = '1'
@@ -252,7 +250,7 @@
252250
let index = arg.arg.index;
253251
let selectedClass = arg.arg.classes[arg.index];
254252
const date = getCurrentEditedDate();
255-
const dayOfWeek = date.getDay();
253+
const dayOfWeek = getCurrentEditedDay(date);
256254
scheduleConfig.daily_class[dayOfWeek].classList[index] = selectedClass;
257255
})
258256

@@ -296,6 +294,33 @@
296294
isClassHidden = arg
297295
tick(reset = true)
298296
})
297+
298+
ipcRenderer.on('setDayOffset', (e, arg) => {
299+
ipcRenderer.send('dialog', {
300+
reply: 'getDayOffset',
301+
options: {
302+
title: '切换日程',
303+
message: `将今日使用课表日程设置为本周的星期几:`,
304+
buttons: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '重置至当前日期'],
305+
cancelId: -1,
306+
}
307+
})
308+
})
309+
310+
ipcRenderer.on('getDayOffset', (e, arg) => {
311+
if (arg.index == -1) return
312+
if (arg.index <= 6) {
313+
localStorage.setItem('dayOffset', arg.index.toString())
314+
localStorage.setItem('setDayOffsetLastDay', new Date().getDay().toString())
315+
dayOffset = arg.index
316+
setDayOffsetLastDay = new Date().getDay()
317+
return
318+
}
319+
localStorage.setItem('dayOffset', '-1')
320+
localStorage.setItem('setDayOffsetLastDay', '-1')
321+
dayOffset = -1
322+
setDayOffsetLastDay = -1
323+
})
299324
</script>
300325

301326
</html>

js/index.js

+25-8
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,34 @@ var timeOffset = localStorage.getItem('timeOffset')
66
if (timeOffset === null) localStorage.setItem('timeOffset', '0')
77
timeOffset = Number(localStorage.getItem('timeOffset'))
88

9-
function getCurrentEditedDate(){
9+
var dayOffset = localStorage.getItem('dayOffset')
10+
if (dayOffset === null) localStorage.setItem('dayOffset', '-1')
11+
dayOffset = Number(localStorage.getItem('dayOffset'))
12+
13+
var setDayOffsetLastDay = localStorage.getItem('setDayOffsetLastDay')
14+
if (setDayOffsetLastDay === null) localStorage.setItem('setDayOffsetLastDay', '-1')
15+
setDayOffsetLastDay = Number(localStorage.getItem('setDayOffsetLastDay'))
16+
17+
18+
function getCurrentEditedDate() {
1019
let d = new Date();
1120
d.setSeconds(d.getSeconds() + timeOffset)
1221
return d;
1322
}
1423

24+
function getCurrentEditedDay(date) {
25+
if (dayOffset === -1)
26+
return date.getDay();
27+
if (setDayOffsetLastDay == new Date().getDay()) {
28+
return dayOffset;
29+
}
30+
localStorage.setItem('dayOffset', '-1')
31+
localStorage.setItem('setDayOffsetLastDay', '-1')
32+
dayOffset = -1
33+
setDayOffsetLastDay = -1
34+
return date.getDay();
35+
}
36+
1537
// Generated by ChatGPT4
1638
function isBreakTime(startTime, endTime, currentTime) {
1739
const [startH, startM] = startTime.split(':').map(Number);
@@ -40,12 +62,10 @@ function getNextClassIndex(timetable, currentIndex) {
4062
// Generated by ChatGPT4
4163
function getCurrentDaySchedule() {
4264
const date = getCurrentEditedDate();
43-
const dayOfWeek = date.getDay(); // 0 = Sunday, 1 = Monday, ...
65+
const dayOfWeek = getCurrentEditedDay(date); // 0 = Sunday, 1 = Monday, ...
4466
const weekNumber = weekIndex; // 当前周数
45-
4667
const dailyClass = scheduleConfig.daily_class[dayOfWeek];
4768
if (!dailyClass) return [];
48-
4969
return dailyClass.classList.map(subject => {
5070
if (Array.isArray(subject)) {
5171
return subject[weekNumber]; // 处理每周不同的课程
@@ -82,14 +102,12 @@ function getScheduleData() {
82102
const currentSchedule = getCurrentDaySchedule();
83103
const currentTime = getCurrentTime();
84104
// let currentTime = '07:10:01';
85-
const dayOfWeek = getCurrentEditedDate().getDay();
105+
const dayOfWeek = getCurrentEditedDay(getCurrentEditedDate());
86106
const timetable = scheduleConfig.daily_class[dayOfWeek].timetable
87107
const dayTimetable = scheduleConfig.timetable[timetable];
88108
const divider = scheduleConfig.divider[timetable];
89-
90109
let scheduleArray = [];
91110
let currentHighlight = { index: null, type: null, fullName: null, countdown: null, countdownText: null };
92-
93111
Object.keys(dayTimetable).forEach((timeRange, index) => {
94112
const [startTime, endTime] = timeRange.split('-');
95113
const classIndex = dayTimetable[timeRange];
@@ -137,7 +155,6 @@ function getScheduleData() {
137155
currentHighlight.fullName = currentSchedule[classIndex]; // 使用时间表中的描述
138156
}
139157
});
140-
141158
return { scheduleArray, currentHighlight, timetable, divider };
142159
}
143160

main.js

+7
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ ipcMain.on('getWeekIndex', (e, arg) => {
117117
win.webContents.send('getTimeOffset')
118118
}
119119
},
120+
{
121+
icon: basePath + 'image/toggle.png',
122+
label: '切换日程',
123+
click: () => {
124+
win.webContents.send('setDayOffset')
125+
}
126+
},
120127
{
121128
icon: basePath + 'image/github.png',
122129
label: '源码仓库',

0 commit comments

Comments
 (0)