Skip to content

Commit

Permalink
34.4 update
Browse files Browse the repository at this point in the history
  • Loading branch information
EnderWolf006 committed Apr 4, 2024
1 parent 62db1cd commit 24aca82
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 18 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ jobs:
- - 2024/3/30: 已支持最多四周课表轮换,支持配置倒计时上方箭头小三角大小
- - 2024/3/31: 已支持单例模式(软件窗口唯一),替换更容易辨别的倒计时字体
- - 2024/4/02: 已支持课程简写角标,已支持隐藏星期显示与天数倒计时,优化倒计时字体
- - 2024/4/04: 已支持切换日程(将今日使用课表日程设置为本周的星期几, 调休用)
- 喜欢本项目的话, 点击右上角的Star支持一下作者吧😘
draft: false
prerelease: false
Expand Down
Binary file added image/toggle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 35 additions & 10 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@
<div class="countdown" id="countdownText">00:00</div>
</div>
</div>
<div class="leftSidebar sidebar background" id="leftSidebar"><span id="weekEN" class="t">Load</span><div class="corner options notIgnoreClick" id="weekCH">ing</div>
</div>
<div class="rightSidebar sidebar background" id="rightSidebar"><span id="countdownDays" class="t">000</span><div class="corner"></div>
</div>
<div class="leftSidebar sidebar background" id="leftSidebar"><span id="weekEN" class="t">Load</span><div class="corner options notIgnoreClick" id="weekCH">ing</div></div>
<div class="rightSidebar sidebar background" id="rightSidebar"><span id="countdownDays" class="t">000</span><div class="corner"></div></div>
</div>
<div class="miniCountdown" id="miniCountdown">00:00</div>

Expand Down Expand Up @@ -69,7 +67,7 @@
let classHtml = '';
for (let i = 0; i < scheduleData.scheduleArray.length; i++) {
let inner = scheduleData.scheduleArray[i]
if(scheduleData.scheduleArray[i].indexOf('@') != -1){
if (scheduleData.scheduleArray[i].indexOf('@') != -1) {
inner = `<div><div style="display:inline">${inner.split('@')[0]}</div><div class="subClass">${inner.split('@')[1]}</div></div>`
}
if (scheduleData.currentHighlight.index == i) {
Expand Down Expand Up @@ -159,13 +157,13 @@
let data = scheduleConfig.daily_class[week]
weekCH.innerText = data.Chinese
weekEN.innerText = data.English
if(scheduleConfig.countdown_target === 'hidden'){
if (scheduleConfig.countdown_target === 'hidden') {
rightSidebar.style.display = 'none'
}else{
} else {
rightSidebar.style.display = 'block'
countdownDays.innerText = Math.ceil(Math.abs(new Date(scheduleConfig.countdown_target) - date) / (1000 * 60 * 60 * 24))
}
leftSidebar.style.display = scheduleConfig.week_display ? 'block' : 'none'
leftSidebar.style.display = scheduleConfig.week_display ? 'block' : 'none'
}

function tick(reset = false) {
Expand Down Expand Up @@ -199,7 +197,7 @@
let timer = undefined
window.addEventListener("mousemove", event => {
if (event.target.className && event.target.className.indexOf('notIgnoreClick') == -1) {
root.style.opacity = '0.3'
root.style.opacity = '0.2'
clearTimeout(timer)
timer = setTimeout(() => {
root.style.opacity = '1'
Expand Down Expand Up @@ -252,7 +250,7 @@
let index = arg.arg.index;
let selectedClass = arg.arg.classes[arg.index];
const date = getCurrentEditedDate();
const dayOfWeek = date.getDay();
const dayOfWeek = getCurrentEditedDay(date);
scheduleConfig.daily_class[dayOfWeek].classList[index] = selectedClass;
})

Expand Down Expand Up @@ -296,6 +294,33 @@
isClassHidden = arg
tick(reset = true)
})

ipcRenderer.on('setDayOffset', (e, arg) => {
ipcRenderer.send('dialog', {
reply: 'getDayOffset',
options: {
title: '切换日程',
message: `将今日使用课表日程设置为本周的星期几:`,
buttons: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '重置至当前日期'],
cancelId: -1,
}
})
})

ipcRenderer.on('getDayOffset', (e, arg) => {
if (arg.index == -1) return
if (arg.index <= 6) {
localStorage.setItem('dayOffset', arg.index.toString())
localStorage.setItem('setDayOffsetLastDay', new Date().getDay().toString())
dayOffset = arg.index
setDayOffsetLastDay = new Date().getDay()
return
}
localStorage.setItem('dayOffset', '-1')
localStorage.setItem('setDayOffsetLastDay', '-1')
dayOffset = -1
setDayOffsetLastDay = -1
})
</script>

</html>
33 changes: 25 additions & 8 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,34 @@ var timeOffset = localStorage.getItem('timeOffset')
if (timeOffset === null) localStorage.setItem('timeOffset', '0')
timeOffset = Number(localStorage.getItem('timeOffset'))

function getCurrentEditedDate(){
var dayOffset = localStorage.getItem('dayOffset')
if (dayOffset === null) localStorage.setItem('dayOffset', '-1')
dayOffset = Number(localStorage.getItem('dayOffset'))

var setDayOffsetLastDay = localStorage.getItem('setDayOffsetLastDay')
if (setDayOffsetLastDay === null) localStorage.setItem('setDayOffsetLastDay', '-1')
setDayOffsetLastDay = Number(localStorage.getItem('setDayOffsetLastDay'))


function getCurrentEditedDate() {
let d = new Date();
d.setSeconds(d.getSeconds() + timeOffset)
return d;
}

function getCurrentEditedDay(date) {
if (dayOffset === -1)
return date.getDay();
if (setDayOffsetLastDay == new Date().getDay()) {
return dayOffset;
}
localStorage.setItem('dayOffset', '-1')
localStorage.setItem('setDayOffsetLastDay', '-1')
dayOffset = -1
setDayOffsetLastDay = -1
return date.getDay();
}

// Generated by ChatGPT4
function isBreakTime(startTime, endTime, currentTime) {
const [startH, startM] = startTime.split(':').map(Number);
Expand Down Expand Up @@ -40,12 +62,10 @@ function getNextClassIndex(timetable, currentIndex) {
// Generated by ChatGPT4
function getCurrentDaySchedule() {
const date = getCurrentEditedDate();
const dayOfWeek = date.getDay(); // 0 = Sunday, 1 = Monday, ...
const dayOfWeek = getCurrentEditedDay(date); // 0 = Sunday, 1 = Monday, ...
const weekNumber = weekIndex; // 当前周数

const dailyClass = scheduleConfig.daily_class[dayOfWeek];
if (!dailyClass) return [];

return dailyClass.classList.map(subject => {
if (Array.isArray(subject)) {
return subject[weekNumber]; // 处理每周不同的课程
Expand Down Expand Up @@ -82,14 +102,12 @@ function getScheduleData() {
const currentSchedule = getCurrentDaySchedule();
const currentTime = getCurrentTime();
// let currentTime = '07:10:01';
const dayOfWeek = getCurrentEditedDate().getDay();
const dayOfWeek = getCurrentEditedDay(getCurrentEditedDate());
const timetable = scheduleConfig.daily_class[dayOfWeek].timetable
const dayTimetable = scheduleConfig.timetable[timetable];
const divider = scheduleConfig.divider[timetable];

let scheduleArray = [];
let currentHighlight = { index: null, type: null, fullName: null, countdown: null, countdownText: null };

Object.keys(dayTimetable).forEach((timeRange, index) => {
const [startTime, endTime] = timeRange.split('-');
const classIndex = dayTimetable[timeRange];
Expand Down Expand Up @@ -137,7 +155,6 @@ function getScheduleData() {
currentHighlight.fullName = currentSchedule[classIndex]; // 使用时间表中的描述
}
});

return { scheduleArray, currentHighlight, timetable, divider };
}

Expand Down
7 changes: 7 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ ipcMain.on('getWeekIndex', (e, arg) => {
win.webContents.send('getTimeOffset')
}
},
{
icon: basePath + 'image/toggle.png',
label: '切换日程',
click: () => {
win.webContents.send('setDayOffset')
}
},
{
icon: basePath + 'image/github.png',
label: '源码仓库',
Expand Down

0 comments on commit 24aca82

Please sign in to comment.