-
Notifications
You must be signed in to change notification settings - Fork 0
/
event.js
369 lines (316 loc) · 9.94 KB
/
event.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
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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
import { USER_KEYS, USER_KEYS_BLOCK } from "./database.js";
const electron = window.require("electron");
const os = require("os");
const URL_UPDATE =
"https://api.github.com/repos/paveldrobny/EasyMoodle/branches/master";
const CHECK_VERSION_MINUTES = 5;
let UI_VERSION = "";
const webView = document.getElementById("web-view");
const webView2 = document.getElementById("web-view2");
const minBtn = document.getElementById("min-btn");
const maxBtn = document.getElementById("max-btn");
const closeBtn = document.getElementById("close-btn");
const titleBarName = document.getElementsByClassName("title-bar-name");
const viewBack = document.getElementsByClassName("back-btn");
const viewRefresh = document.getElementById("view-refresh");
const viewAbout = document.getElementById("view-about");
const viewDevTools = document.getElementById("view-devTools");
const viewSplit = document.getElementById("view-split");
const timerAction = document.getElementById("timer-action");
const remainingTime = document.getElementById("remaining-time");
const updateReady = document.getElementsByClassName("update-ready");
const updateApp = document.getElementById("update-ready-button");
const userIDBtn = document.getElementById("user-id");
const userCurrentID = document.getElementById("user-current-id");
const accessBlock = document.getElementById("access-block");
const loader = document.getElementById("loader");
const loaderProgress = document.getElementById("loader-progress");
const aboutApp = document.getElementById("aboutApp");
const faColumns = document.getElementsByClassName("fa-columns");
const checkVersion = () => {
setInterval(function () {
fetch(URL_UPDATE)
.then((res) => res.json())
.then((out) => {
if (UI_VERSION == out.commit.commit.author.date) {
updateReady[0].classList.remove("is-show");
} else {
updateReady[0].classList.add("is-show");
}
})
.catch((err) => {
return err;
});
}, CHECK_VERSION_MINUTES * 1000 * 60);
};
window.addEventListener("loadeddata", function () {
getWindowsColors();
});
window.addEventListener("load", function () {
fetch(URL_UPDATE)
.then((res) => res.json())
.then((out) => {
UI_VERSION = out.commit.commit.author.date;
});
checkVersion();
getWindowsColors();
getUserID();
checkDatabaseID();
});
const getUserID = () => {
const createID = (
os.hostname() +
os.userInfo().username +
os.cpus()[0].model +
os.cpus().length
)
.replace(/ /g, "")
.toLocaleLowerCase();
return createID;
};
const disableLoader = () => {
setTimeout(function () {
loader.style.display = "none";
}, 2000);
};
const checkDatabaseID = () => {
const userIDInput = document.getElementById("user-id-input");
const notNowID = document.getElementById("notNow-message-id");
userIDInput.value = getUserID();
notNowID.innerHTML = `Ваш уникальный идентификатор: </br> ${getUserID()}`;
if (USER_KEYS.includes(getUserID())) {
disableLoader();
userCurrentID.style.display = "none";
accessBlock.style.display = "none";
} else {
disableLoader();
userCurrentID.style.display = "block";
accessBlock.style.display = "block";
}
};
const getWindowsColors = () => {
electron.ipcRenderer.send("app-windows-color");
electron.ipcRenderer.on("app-get-windows-color", (event, data) => {
if (os.release().indexOf("10.", 0) != -1) {
titleBarName[0].style.background = `#${data}`;
loaderProgress.style.background = `#${data}`;
}
});
};
const getAboutVersion = () => {
const aboutVersionWindow = document.getElementById("aboutApp-window");
const aboutVersionUI = document.getElementById("aboutApp-ui");
aboutVersionUI.innerHTML = `Версия интерфейса: ${UI_VERSION}`;
};
minBtn.addEventListener("click", function () {
electron.ipcRenderer.send("app-minimize");
});
maxBtn.addEventListener("click", function () {
electron.ipcRenderer.send("app-maximize");
});
closeBtn.addEventListener("click", function () {
electron.ipcRenderer.send("app-close");
});
updateApp.addEventListener("click", function () {
electron.ipcRenderer.send("app-reload");
});
userIDBtn.addEventListener("click", function () {
if (aboutApp.style.display == "block") {
aboutApp.style.display = "none";
viewAbout.style.background = "transparent";
}
if (userCurrentID.style.display == "none") {
userIDBtn.style.background = "#2f53a8";
userCurrentID.style.display = "block";
return;
}
userCurrentID.style.display = "none";
userIDBtn.style.background = "transparent";
});
// TIMERS
let isStart = false;
let timer;
let courseTimer;
let isSplit = false;
const TIME_IN_MINUTES = 2;
const TARGET_TIME = TIME_IN_MINUTES * 60;
const startAction = () => {
timerAction.classList.add("is-start");
remainingTime.classList.add("is-active");
};
const stopAction = () => {
timerAction.classList.remove("is-start");
remainingTime.classList.remove("is-active");
};
timerAction.addEventListener("click", function () {
let distance;
if (!isStart) {
isStart = true;
startAction();
checkCourse();
distance = TARGET_TIME;
timer = setInterval(function () {
distance--;
let minutes = Math.floor(distance / 60);
let seconds = Math.floor(distance % 60);
remainingTime.innerHTML = `0${minutes}:${seconds}`;
if (distance <= 0) {
distance = TARGET_TIME;
}
}, 1000);
courseTimer = setInterval(function () {
checkCourse();
}, TIME_IN_MINUTES * 60000);
} else {
isStart = false;
stopAction();
clearInterval(timer);
clearInterval(courseTimer);
distance = TARGET_TIME;
remainingTime.innerHTML = "00:00";
}
});
viewBack[0].addEventListener("click", function () {
webView.goBack();
});
webView.addEventListener("did-navigate", function () {
if (webView.canGoBack()) {
viewBack[0].classList.add("is-active");
} else {
viewBack[0].classList.remove("is-active");
}
});
viewRefresh.addEventListener("click", function () {
electron.ipcRenderer.send("app-reload");
});
viewAbout.addEventListener("click", function () {
if (userCurrentID.style.display == "block") {
userCurrentID.style.display = "none";
userIDBtn.style.background = "transparent";
}
if (aboutApp.style.display == "block") {
aboutApp.style.display = "none";
viewAbout.style.background = "transparent";
return;
}
aboutApp.style.display = "block";
viewAbout.style.background = "#2f53a8";
getAboutVersion();
});
viewDevTools.addEventListener("click", function () {
webView.openDevTools();
});
viewSplit.addEventListener("click", function () {
if (!USER_KEYS_BLOCK.includes(getUserID())) {
if (isSplit) {
isSplit = false;
viewSplit.classList.remove("is-split");
splitDisable();
} else {
isSplit = true;
viewSplit.classList.add("is-split");
splitEnable();
}
} else {
alert("Функция 'Split screen' недоступна для вашего ID");
}
});
const splitEnable = () => {
webView.className = "split";
webView2.className = "split";
faColumns[0].style.transform = "rotate(45deg) scale(1.1)";
};
const splitDisable = () => {
webView.className = "";
webView2.className = "";
faColumns[0].style.transform = "rotate(0deg) scale(1)";
};
const loadLink = (target) => {
webView.src = target;
};
const loadLink_2 = (target) => {
webView2.src = target;
};
const checkTime = (date, start, end) => {
return date.getTime() > start.getTime() && date.getTime() < end.getTime();
};
const DAY_1 = [
"",
"",
"",
""
];
const DAY_2 = [
"",
"",
"",
""
];
const DAY_3 = [
"http://e.adidonntu.ru/course/view.php?id=290",
"",
"http://e.adidonntu.ru/course/view.php?id=392",
"http://e.adidonntu.ru/course/view.php?id=392"
];
const DAY_4 = [
"",
"http://e.adidonntu.ru/course/view.php?id=290",
"http://e.adidonntu.ru/course/view.php?id=290",
""
];
const DAY_5 = [
"http://e.adidonntu.ru/course/view.php?id=392",
"http://e.adidonntu.ru/course/view.php?id=392",
"http://e.adidonntu.ru/course/view.php?id=290",
""
];
const dayTemplate = (numDay, subject) => {
const date = new Date(),
day = date.getDay(),
mounth = date.getMonth(),
_date = date.getDate(),
//
startFirstPair = new Date(2022, mounth, _date, 7, 55),
endFirstPair = new Date(2022, mounth, _date, 9, 30),
//
startSecondPair = new Date(2022, mounth, _date, 9, 50),
endSecondPair = new Date(2022, mounth, _date, 11, 25),
//
startThirdPair = new Date(2022, mounth, _date, 11, 40),
endThirdPair = new Date(2022, mounth, _date, 13, 15),
//
startFourthPair = new Date(2022, mounth, _date, 13, 30),
endFourthPair = new Date(2022, mounth, _date, 15, 0);
//////////////////////////////////////////////////////////////
if (day == numDay) {
if (checkTime(date, startFirstPair, endFirstPair)) {
loadLink(subject[0]);
if (isSplit) {
loadLink_2(subject[0]);
}
} else if (checkTime(date, startSecondPair, endSecondPair)) {
loadLink(subject[1]);
if (isSplit) {
loadLink_2(subject[1]);
}
} else if (checkTime(date, startThirdPair, endThirdPair)) {
loadLink(subject[2]);
if (isSplit) {
loadLink_2(subject[2]);
}
} else if (checkTime(date, startFourthPair, endFourthPair)) {
loadLink(subject[3]);
if (isSplit) {
loadLink_2(subject[3]);
}
}
}
//////////////////////////////////////////////////////////////
};
const checkCourse = () => {
dayTemplate(1, DAY_1);
dayTemplate(2, DAY_2);
dayTemplate(3, DAY_3);
dayTemplate(4, DAY_4);
dayTemplate(5, DAY_5);
};