-
Notifications
You must be signed in to change notification settings - Fork 25
/
index.html
326 lines (298 loc) · 12.3 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
<!DOCTYPE html>
<html lang="ch" id="html">
<head>
<title>电子课表</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/scheduleConfig.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<div class="globalContainer" id="globalContainer">
<div class="classContainer background" id="classContainer">
<div class="class">加</div>
<div class="class">载</div>
<div class="class">中</div>
</div>
<div class="countdownContainer" id="countdownContainer">
<div class="triangle"></div>
<div class="countdowner" id="countdowner">
<div class="currentClass" id="currentFullName">Loading</div>
<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>
<div class="miniCountdown" id="miniCountdown">00:00</div>
</body>
<script>
const { ipcRenderer } = require('electron');
let scheduleData = getScheduleData();
let globalContainer = document.getElementById('globalContainer')
let classContainer = document.getElementById('classContainer')
let countdownContainer = document.getElementById('countdownContainer')
let countdowner = document.getElementById('countdowner')
let currentFullName = document.getElementById('currentFullName')
let countdownText = document.getElementById('countdownText')
let weekEN = document.getElementById('weekEN')
let weekCH = document.getElementById('weekCH')
let countdownDays = document.getElementById('countdownDays')
let miniCountdown = document.getElementById('miniCountdown')
let rightSidebar = document.getElementById('rightSidebar')
let leftSidebar = document.getElementById('leftSidebar')
let root = document.querySelector(':root');
let isClassCountdown = true
let isClassHidden = true
let lastScheduleData = {
currentHighlight: {
index: null,
type: null,
fullName: null,
countdown: null,
countdownText: null
},
scheduleArray: [null, null, null],
timetable: null,
divider: [null, null]
}
function setScheduleClass() {
let classHtml = '';
for (let i = 0; i < scheduleData.scheduleArray.length; i++) {
let inner = scheduleData.scheduleArray[i]
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) {
if (scheduleData.currentHighlight.type === 'current')
classHtml += `<div class="class current" id="highlighted">${inner}</div>`
else if (scheduleData.currentHighlight.type === 'upcoming')
classHtml += `<div class="class upcoming" id="highlighted">${inner}</div>`
}
else {
if (scheduleData.currentHighlight.index > i)
classHtml += `<div class="class" style="color:rgba(166,166,166);">${inner}</div>`
else
classHtml += `<div class="class">${inner}</div>`
}
if (scheduleData.divider.indexOf(i) != -1)
classHtml += '<div class="divider"></div>'
}
classContainer.innerHTML = classHtml
}
function setBackgroundDisplay() {
let elements = document.getElementsByClassName('background')
for (element of elements) {
element.style.visibility = (scheduleData.currentHighlight.type === 'current' && isClassHidden) ? 'hidden' : 'visible'
}
}
function setCountdownerContent() {
currentFullName.innerText = scheduleData.currentHighlight.fullName;
currentFullName.style.color = scheduleData.currentHighlight.type === 'current' ? 'rgba(0, 255, 10, 1)' : 'rgba(255, 255, 5, 1)'
countdownText.innerText = scheduleData.currentHighlight.countdownText;
if (scheduleData.currentHighlight.type === 'current') {
if (isClassCountdown) {
if (isClassHidden) { // 上课 并且开启了倒计时 并且 隐藏主体 -> 显示小窗口
countdownContainer.style.display = 'none'
miniCountdown.style.display = 'block'
miniCountdown.innerHTML = `<div class="currentClass">${currentFullName.innerText = scheduleData.currentHighlight.fullName}</div><div class="countdown" style="margin-left:5px">${scheduleData.currentHighlight.countdownText}</div>`
} else { // 上课 并且开启了倒计时 并且 不隐藏主体 -> 正常计时
countdownContainer.style.display = 'block'
miniCountdown.style.display = 'none'
}
} else { // 上课 并且关闭了倒计时 -> 都不显示
countdownContainer.style.display = 'none'
miniCountdown.style.display = 'none'
}
}
else { // 下课正常显示
countdownContainer.style.display = 'block';
miniCountdown.style.display = 'none'
}
}
function setCountdownerPosition() {
let highlightElement = document.getElementById('highlighted')
let offset = {}
if (scheduleData.currentHighlight.type === 'current') {
offset = {
x: highlightElement.offsetLeft - countdownContainer.offsetWidth / 2 + highlightElement.offsetWidth / 2,
y: classContainer.offsetHeight
}
} else if (scheduleData.currentHighlight.type === 'upcoming') {
if (scheduleData.currentHighlight.index != 0 && scheduleData.divider.indexOf((scheduleData.currentHighlight.index - 1)) != -1) {
offset = {
x: highlightElement.offsetLeft - countdownContainer.offsetWidth / 2 - Number(getComputedStyle(highlightElement).marginLeft.replace('px', '')) - getComputedStyle(root).getPropertyValue('--divider-width').replace('px', '') / 2 - getComputedStyle(root).getPropertyValue('--divider-margin').replace('px', ''),
y: classContainer.offsetHeight
}
} else {
offset = {
x: highlightElement.offsetLeft - countdownContainer.offsetWidth / 2 - Number(getComputedStyle(highlightElement).marginLeft.replace('px', '')),
y: classContainer.offsetHeight
}
}
}
if (scheduleData.currentHighlight.isEnd) {
offset = {
x: highlightElement.offsetLeft - countdownContainer.offsetWidth / 2 + highlightElement.offsetWidth + Number(getComputedStyle(highlightElement).marginLeft.replace('px', '')),
y: classContainer.offsetHeight
}
}
countdownContainer.style.left = offset.x + 'px'
countdownContainer.style.top = offset.y + 'px'
}
function setSidebar() {
let date = getCurrentEditedDate()
let week = date.getDay()
let data = scheduleConfig.daily_class[week]
weekCH.innerText = data.Chinese
weekEN.innerText = data.English
if (scheduleConfig.countdown_target === 'hidden') {
rightSidebar.style.display = 'none'
} 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'
}
function tick(reset = false) {
scheduleData = getScheduleData();
setCountdownerContent()
if (JSON.stringify(scheduleData.scheduleArray) != JSON.stringify(lastScheduleData.scheduleArray) ||
scheduleData.currentHighlight.index != lastScheduleData.currentHighlight.index ||
scheduleData.currentHighlight.fullName != lastScheduleData.currentHighlight.fullName ||
scheduleData.currentHighlight.type != lastScheduleData.currentHighlight.type || reset) {
setScheduleClass()
setCountdownerPosition()
setSidebar()
setBackgroundDisplay()
}
lastScheduleData = $.extend(true, {}, scheduleData)
}
let lastTickTime = new Date().getTime()
setInterval(() => {
if (new Date().getTime() - lastTickTime >= 1000) {
lastTickTime = new Date().getTime()
tick()
}
}, 20);
for (key in scheduleConfig.css_style) {
root.style.setProperty(key, scheduleConfig.css_style[key])
}
let timer = undefined
window.addEventListener("mousemove", event => {
if (event.target.className && event.target.className.indexOf('notIgnoreClick') == -1) {
root.style.opacity = '0.2'
clearTimeout(timer)
timer = setTimeout(() => {
root.style.opacity = '1'
}, 5000);
} else {
clearTimeout(timer)
root.style.opacity = '1'
}
if (event.target.className.indexOf('notIgnoreClick') == -1) {
ipcRenderer.send('setIgnore', true)
} else {
ipcRenderer.send('setIgnore', false)
}
});
ipcRenderer.send('setIgnore', true)
function setScheduleDialog() {
ipcRenderer.send('dialog', {
reply: 'getSelectedClassIndex',
options: {
title: '更改课表',
message: `请选择你要更改的课程序号`,
buttons: scheduleData.scheduleArray.map((value, index) => { return `第 ${index + 1} 节: ${scheduleConfig.subject_name[value]}` }),
cancelId: -1,
defaultId: scheduleData.currentHighlight.index
}
})
}
ipcRenderer.on('getSelectedClassIndex', (e, arg) => {
if (arg.index == -1) return
let text = arg.arg.options.buttons[arg.index]
let classes = Object.keys(scheduleConfig.subject_name).sort();
ipcRenderer.send('dialog', {
reply: 'getSelectedChangingClass',
index: arg.index,
classes: classes,
options: {
title: '更改课表',
message: `将 第 ${arg.index + 1} 节 ${scheduleConfig.subject_name[scheduleData.scheduleArray[arg.index]]} 更改为:`,
buttons: classes.map((value) => { return scheduleConfig.subject_name[value] }),
cancelId: -1,
}
})
})
ipcRenderer.on('getSelectedChangingClass', (e, arg) => {
if (arg.index == -1) return
let index = arg.arg.index;
let selectedClass = arg.arg.classes[arg.index];
const date = getCurrentEditedDate();
const dayOfWeek = getCurrentEditedDay(date);
scheduleConfig.daily_class[dayOfWeek].classList[index] = selectedClass;
})
ipcRenderer.on('openSettingDialog', (e, arg) => {
setScheduleDialog()
})
document.addEventListener("click", function (event) {
if (event.target.className.indexOf('options') != -1) {
ipcRenderer.send('pop')
}
});
ipcRenderer.on('setWeekIndex', (e, arg) => {
scheduleConfig = JSON.parse(JSON.stringify(_scheduleConfig))
weekIndex = arg
localStorage.setItem('weekIndex', weekIndex.toString())
})
ipcRenderer.on('getWeekIndex', (e, arg) => {
let index = localStorage.getItem('weekIndex');
ipcRenderer.send('getWeekIndex', index === null ? 0 : Number(index))
})
ipcRenderer.on('getTimeOffset', (e, arg) => {
let offset = localStorage.getItem('timeOffset');
ipcRenderer.send('getTimeOffset', offset === null ? 0 : Number(offset))
})
ipcRenderer.on('setTimeOffset', (e, arg) => {
timeOffset = arg
localStorage.setItem('timeOffset', arg.toString())
})
ipcRenderer.on('ClassCountdown', (e, arg) => {
isClassCountdown = arg
tick(reset = true)
})
ipcRenderer.on('ClassHidden', (e, arg) => {
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>