-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinit.js
191 lines (160 loc) · 4.93 KB
/
init.js
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
if ((document.referrer == "https://www.digikabu.de") || (document.referrer == "https://www.digikabu.de/Main/TestRedirect")) {
window.location.href = "https://www.digikabu.de/Stundenplan/Klasse";
}
if ((document.referrer == "https://digikabu.de") || (document.referrer == "https://digikabu.de/Main/TestRedirect")) {
window.location.href = "https://digikabu.de/Stundenplan/Klasse";
}
timeTable = [
{
start: [8, 30],
end: [9, 15],
},
{
start: [9, 15],
end: [10, 0],
},
{
start: [10, 0],
end: [11, 0],
},
{
start: [11, 0],
end: [11, 45],
},
{
start: [11, 45],
end: [12, 30],
},
{
start: [12, 30],
end: [13, 15],
},
{
start: [13, 15],
end: [14, 0],
},
{
start: [14, 0],
end: [14, 45],
},
{
start: [14, 45],
end: [15, 30],
},
{
start: [15, 30],
end: [16, 15],
},
];
const refreshTimeout = 10000;
const hourOver = "grey";
const hourNow = "#7CBB00";
function startInfiniteLoop() {
setTimeout(function() {
timeTable.forEach(checkTime);
startInfiniteLoop();
}, refreshTimeout)
}
document.onreadystatechange = () => {
if (document.readyState === "complete") {
console.log("BetterKabu running");
const urlpath = window.location.pathname;
if (urlpath.includes("SchulaufgabenPlan")) {
markCurrentDay();
}
if (urlpath.includes("Stundenplan") || urlpath.includes("Main")) {
setTimeout(() => {
hidePassedDays();
showTimer();
timeTable.forEach(checkTime);
startInfiniteLoop();
}, 600);
}
}
}
function getTimeObject(hours, minutes) {
let obj = new Date();
obj.setHours(hours);
obj.setMinutes(minutes);
obj.setSeconds(0);
return obj
}
function checkTime(item, index) {
currentTime = new Date();
const startTime = getTimeObject(item.start[0], item.start[1]);
const endTime = getTimeObject(item.end[0], item.end[1]);
let box;
if (window.location.pathname.includes("Stundenplan")) {
box = document.getElementById('umgebung').children[0];
} else {
box = document.getElementById('umgebung').children[0].children[1].children[0];
}
const currentBox = box.children[index];
if (currentTime > endTime) {
currentBox.children[0].classList.remove('weekdayToday');
currentBox.children[1].style.fill = hourOver;
currentBox.children[2].style.fill = hourOver;
currentBox.children[3].style.fill = hourOver;
} else if ((currentTime > startTime) && (currentTime < endTime)) {
currentBox.children[0].classList.add('weekdayToday');
}
}
function showTimer() {
if (window.location.pathname.includes("Stundenplan")) {
const box = document.getElementById("stdplanheading");
const timerText = document.createElement("span");
timerText.id = "timerText";
box.append(timerText);
function updateTimerDisplay(minutes, seconds) {
const timerText = `${minutes}m ${seconds}s`;
document.querySelector("#timerText").textContent = timerText;
}
function calculateTimeDiff() {
const currentTime = new Date();
let nextLessonStart;
for (let i = 0; i < timeTable.length; i++) {
const startTime = getTimeObject(timeTable[i].start[0], timeTable[i].start[1]);
if (currentTime < startTime) {
nextLessonStart = startTime;
break;
}
}
const timeDiff = Math.max(nextLessonStart - currentTime, 0);
const minutes = Math.floor(timeDiff / 60000);
const seconds = Math.floor((timeDiff % 60000) / 1000);
updateTimerDisplay(minutes, seconds);
}
calculateTimeDiff();
setInterval(calculateTimeDiff, 1000);
}
}
function hidePassedDays() {
let box;
if (window.location.pathname.includes("Stundenplan")) {
box = document.getElementById('umgebung');
for (let i = 1; i < 5; i++) {
if (box.children[i].children[0].children[0].classList.contains('weekdayToday')) {
break
} else {
box.children[i].children[0].children[1].classList.add('passedDay');
}
}
}
}
function markCurrentDay() {
var today = new Date(),
day = String(today.getDate()).padStart(2, "0"),
month = String(today.getMonth() + 1).padStart(2, "0"),
date = day + "." + month + ".";
var tables = document.getElementsByTagName("table");
for (var i = 0; i < tables.length; i++) {
var strongs = tables[i].getElementsByTagName("strong");
for (var j = 0, len = strongs.length; j < len; j++) {
var strong = strongs[j];
if (strong.textContent.includes(date)) {
strong.closest("tr").style.backgroundColor = "#4281ff";
return;
}
}
}
}