-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetShedules.js
88 lines (82 loc) · 3.03 KB
/
setShedules.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
import shedule from "./shedule.js";
const timeNextKadino = document.getElementById("timeNextKadino");
const timeNextKirova = document.getElementById("timeNextKirova");
const timeNextRomanovichi = document.getElementById("timeNextRomanovichi");
const timeNextVokzal = document.getElementById("timeNextVokzal");
const sheduleKadino = document.getElementById("sheduleKadino");
const sheduleKirova = document.getElementById("sheduleKirova");
const sheduleRomanovichi = document.getElementById("sheduleRomanovichi");
const sheduleVokzal = document.getElementById("sheduleVokzal");
let timer
let day
let hours
let showingDay
export default function setShedules(showDay) {
showingDay = showDay
const date = new Date();
const cday = date.getDay();
day = showDay !== undefined ? showDay : cday;
if (day === 0) day = 7;
hours = date.getHours();
const mins = date.getMinutes();
if (showDay !== undefined) {
clearTimeout(timer);
hours = 0;
}
let kirova, elNow, elBack, kadino, romanovichi, vokzal;
if(day < 6) {
kirova = shedule.kirova;
kadino = shedule.kadino;
romanovichi = shedule.romanovichi;
vokzal = shedule.vokzal;
} else {
if(day === 6) {
kirova = shedule.kirova6;
kadino = shedule.kadino6;
romanovichi = shedule.romanovichi6;
vokzal = shedule.vokzal6;
}
if(day === 7) {
kirova = shedule.kirova7;
kadino = shedule.kadino7;
romanovichi = shedule.romanovichi7;
vokzal = shedule.vokzal7;
}
};
function sheduling(sheduleArr, nextEl, sheduleEl) {
sheduleEl.innerText = ""; nextEl.innerText = "";
nextEl.classList.remove('hidden');
elNow = []; elBack = [];
sheduleArr.forEach(el => {
const arrEl = el.split(":");
const newEl = document.createElement("span");
if(Number(arrEl[0]) >= hours) {
newEl.classList.add("shedule");
if(Number(arrEl[0]) === hours && Number(arrEl[1]) < mins) newEl.classList.add("oldshedule")
if(Number(arrEl[0]) === hours && Number(arrEl[1]) >= mins) {
newEl.classList.add("shedulenow");
elNow.push(el);
}
if((Number(arrEl[0]) - hours) === 1) elNow.push(el);
if((Number(arrEl[0]) - hours) > 1) {
newEl.classList.add("shedulelong");
elBack.push(el);
};
} else {
newEl.classList.add("shedule")
newEl.classList.add("oldshedule")
}
nextEl.innerText = elNow.join(", ");
newEl.innerText = el;
sheduleEl.appendChild(newEl);
});
if(elBack && elNow.length < 1) nextEl.innerText = elBack.join(", ");
if(showingDay === undefined && nextEl.childNodes.length < 1) nextEl.classList.add('hidden');
// if(showingDay === undefined && nextEl.childNodes.length < 1) nextEl.innerText = 'Завтра';
}
sheduling(kirova, timeNextKirova, sheduleKirova);
sheduling(kadino, timeNextKadino, sheduleKadino);
sheduling(romanovichi, timeNextRomanovichi, sheduleRomanovichi);
sheduling(vokzal, timeNextVokzal, sheduleVokzal);
timer = setTimeout(() => setShedules(showingDay), 10000);
};