-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
892 lines (892 loc) · 23.2 KB
/
index.html
File metadata and controls
892 lines (892 loc) · 23.2 KB
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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
<!DOCTYPE html>
<html lang="et">
<head>
<meta charset="UTF-8" name="viewport" content="width=device-width, height=device-height, initial-scale=1.0" />
<title>Tunniplaan</title>
</head>
<body>
<div class="page" id="home">
<div class="pd">
<h1 class="gradient-text" style="--c1: var(--fg); --c2: var(--purple-fg);">ProTERA tunniplaani koostamise rakendus</h1>
<p>
<a class="lnk" href="https://github.com/mk4i/tt/blob/main/README.md">README.md</a><br>
<a class="lnk" href="https://github.com/mk4i/tt">GitHub</a><br>
<a class="lnk" href="https://tera.edupage.org/timetable/">Alginfo</a>
</p>
</div>
<div class="pd">
<button class="primary large" onclick="setup();">Koosta →</button>
</div>
</div>
<div class="page" id="setup">
<div class="pd">
<div id="pre"></div>
<hr>
<div class="flex opt">
<button id="abort">Katkesta</button>
</div>
</div>
<div class="pd">
<div class="flex opt" id="opt"></div>
</div>
</div>
<div class="page" id="timetable">
<div class="is" id="share-warning">
<p style="color: var(--purple-fg)">
Sa oled avanud tunniplaani, mis on Sinuga jagatud. Seda ei salvestata veebilehitsejasse enne, kui vajutad <strong>Salvesta</strong>.
</p>
<div class="flex">
<button onclick="save();notSharedTimetable()">Salvesta</button>
<button onclick="notSharedTimetable()">Peida</button>
</div>
</div>
<dit id="tt"></dit>
<hr>
<div class="flex">
<button onclick="setup();">Genereeri tunniplaan</button>
<button onclick="clearAll();">Kustuta küpsised</button>
<button onclick="share();">Kopeeri link</button>
<button onclick="sTheme(th + 1);">Taust: <span id="theme" style="font-weight: bold;"></span></button>
<button onclick="sHilighting();">Markeeri tänane tunniplaan: <span id="hilighting" style="font-weight: bold;"></span></button>
</div>
</div>
<style>
@font-face {
font-family: "Inter";
src:
url("/tt/assets/font/Inter/InterVariable.ttf") format("truetype"),
}
@font-face {
font-family: "Exo_2";
src:
url("/tt/assets/font/Exo_2/Exo2-VariableFont_wght.ttf") format("truetype"),
}
:root {
font-size: max(min(24px, 8vw), 2vw);
--max-safe-width: calc(100vw - 2rem);
font-family: Inter;
}
body {
background-color: var(--bg);
color: var(--fg);
font-family: Inter, system-ui;
margin: 0 auto;
min-width: 100vw;
text-overflow: clip;
font-size: 16px;
--qo: cubic-bezier(.25, 1, .5, 1); /* quadratic ease-out */
--qs: cubic-bezier(0.4, 0.1, 0.5, 1);
}
h1 { font-size: 1.75rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.375rem; }
p { font-size: 1rem; }
h1, h2, h3, p {
padding: .25rem 0;
margin: 0;
}
hr {
width: 100%;
margin: 1rem 0;
border: .04rem solid var(--gray);
}
a {
color: var(--purple);
}
.lnk {
color: var(--ltrans);
font-weight: 600;
text-decoration: none;
}
.lnk:hover {
text-decoration: underline;
}
.is {
min-width: 24rem;
width: 80%;
max-width: 32rem;
}
input {
font-family: inherit;
background-color: var(--bg);
border: #888 2px solid;
border-radius: 4px;
}
.page {
display: flex;
width: 100vw;
min-height: 100vh;
flex-wrap: wrap;
}
.pd {
display: flex;
min-width: min(20rem, var(--max-safe-width));
max-width: var(--max-safe-width);
flex: 1 1;
color: var(--fg);
flex-direction: column;
align-items: center;
justify-content: center;
padding: 1rem;
}
.pd:is(:first-child) {
background-color: var(--bg);
align-items: baseline;
}
.pd:is(:last-child) {
background-color: var(--bg-m);
}
#timetable {
display: flex;
justify-content: center;
}
#timetable > *:not(#tt) {
max-width: calc(100% - 2rem);
}
#pre p {
color: var(--lighter-gray)
}
.flex {
display: flex;
flex-wrap: wrap;
gap: 0 .5rem;
}
.flex button {
flex: 1 1;
text-wrap: nowrap;
}
.opt {
flex-grow: 0;
height: min-content;
}
button {
cursor: pointer;
border: none;
font-family: inherit;
background: var(--darksky);
color: var(--fg);
font-size: 1rem;
border-radius: 0.375rem;
padding: 0.25rem 0.5rem;
font-weight: 500;
transition-duration: 100ms;
outline: none;
margin: .25rem 0;
transition: 0.3s var(--qo);
box-sizing: content-box;
}
button:is(.large) {
font-size: 1.125rem;
padding: .4rem .8rem;
border-radius: .6rem;
}
button:is(.primary) {
background-color: var(--purple-fg);
color: var(--bg);
}
button:focus {
background: var(--bg-m);
color: var(--fg);
}
button:hover {
background: var(--bg);
color: var(--fg);
scale: 1.025;
transition-duration: .2s;
}
button:hover, button:focus {
box-shadow: -0.25rem -0.0625rem 0.75rem #8bfc, 0.25rem 0.0625rem 0.75rem #cafc;
}
button:active {
box-shadow: 0 0 0.75rem var(--ltrans);
scale: 0.985;
}
#tt {
font-family: Exo_2;
text-wrap: nowrap;
text-rendering: geometricPrecision;
--w: 0.96vw;
font-size: var(--w);
margin: 1rem;
width: 100em;
height: 50em;
outline: var(--gray-bg) .2em solid;
display: grid;
position: relative;
padding: 0 0.7em 0.7em 0;
grid-template-rows: 2em repeat(5, 1fr);
grid-template-columns: 3em repeat(10, 1fr);
row-gap: 1em;
}
#tt:empty {
display: none;
}
#tt .num {
color: var(--light-fg);
display: block;
grid-row: 1;
text-align: center;
font-size: 2.5em;
font-weight: 600;
position: relative;
top: calc(-0.04 * var(--w));
}
#tt .num:is(.s) {
font-size: 2.2em;
}
#tt .wkd {
color: var(--light-fg);
padding-top: 130%;
font-size: 3.5em;
line-height: 0;
grid-column: 1;
text-align: center;
}
#tt .item {
text-align: center;
position: relative;
display: block;
outline-offset: -0.06em;
}
#tt .item label {
position: absolute;
translate: -50% -50%;
left: 50%;
top: 22%;
font-weight: 600;
font-size: 3em;
}
#tt .item time {
position: absolute;
top: 58%;
font-size: 1.55em;
left: 50%;
font-weight: 450;
translate: -50% -50%;
}
#tt .item .bottom {
margin: 0;
position: absolute;
bottom: 6%;
font-size: 1.5em;
translate: -50% -50%;
white-space: pre;
font-weight: 350;
line-height: 0;
}
#tt .bottom:is(.left) { left: 25%; }
#tt .bottom:is(.center) { left: 50%; }
#tt .bottom:is(.right) { left: 75%; }
#tt .item:is(.lesson) {
outline: var(--lighter-gray) calc(0.12 * var(--w)) solid;
}
#tt .item:is(.break) {
color: var(--light-fg);
border: var(--gray) calc(0.12 * var(--w)) dashed;
}
#tt .item:not(.last) {
border-right: none;
}
#tt .item:not(.first) {
border-left: none;
}
#tt .item:is(.first) {
border-radius: var(--w) 0 0 var(--w);
}
#tt .item:is(.last) {
border-radius: 0 var(--w) var(--w) 0;
}
#tt .unhilighted {
opacity: 0.5;
}
</style>
<script>
let
op = [],
pkt = [],
tt = [],
ttc = null,
th,
hilighting,
code,
weekday,
gr = null;
const
Pos = {
FIRST: "first",
MID: false,
LAST: "last"
},
PATH = "/tt",
SRC_PKT = `Ehitus- ja puidutöö | 14:00 | 15:30 | Kopli 1 B r 159 | Kaido Toobal / Tiiu Laid
Pagari- ja kondiitritoodete valmistamine | 14:00 | 15:30 | Kopli 1 A r 119 | Ülle Soeson
Kokkamine ja küpsetamine | 14:00 | 15:30 | Kopli 1 B r 317 | Maire Linsi
Autotehnika kursus | 14:00 | 15:30 | Põllu 11 F r 330 | Hindrek Sokk / Vallo Abel
Taaskasutus, disain ja käsitöö | 14:00 | 15:30 | Kopli 1 A r 139 | Merike Raudnagel
Graafiline disain | 14:00 | 15:30 | Tartu Kunstikool r 405 | Maria Kilk
Tervist, tervis! | 14:00 | 15:30 | Tartu Tervishoiu Kõrgkool |
Sissejuhatus filosoofiasse | 13:45 | 15:15 | 205 | Andre Pettai
Ettevõtlusõpe | 13:45 | 15:15 | 302 | Karol Tšarnetski
Fotograafia ja helisüntees | 13:45 | 15:15 | 105 | Ardo Rohtla
Keraamika | 14:00 | 15:30 | TäheTERA | Monika Zirkel
Rahvatants | 14:00 | 15:30 | suur ala | Mariliis Tasuja
Ajalooring | 13:45 | 15:15 | 302 | Jaanus Gorain
Lühifilmid | 13:45 | 15:15 | 207 | Valdek Ott
Etiketiõpetus | 13:45 | 15:15 | 206 | Olga Kitsing
Meelerahu kritseldused | 13:45 | 15:15 | 203 | Kristi Kartašev`,
SRC_OP = `Anžela Lember | bvk3
Deisy Nursi | e6 kir4
Egle Tamm | m1 m6
Epp Ruuder | bio2 bio3 kem1 kem3 kem4 kem5 kem6 lg1 t1
Hanna-Stina Vigel | e3 e4 kir2 kir3
Hannes Tamm / Mari Nurklik | li1 li2 li3 li4 li5 li6
Hedvy Tiitsmaa | bvk6
Irmeli Tõniste | m4
Jaanus Gorain | aj1 aj2 aj3 aj4 aj5 lg2 t2
Jane Eskla | i2
Kaidi Menšikova | e2
Karol Tšarnetski | bvk0 lg3 t3
Karoliina Kurvits | m3
Kristi Kartašev | i3 i5
Liisa Liivak | i4
Marge Lahe | m5
Marie Tempel | m2
Mariliis Tasuja | kem2 lg4 t4
Meelis Brikker | bio1 bio4 bio5 fys3 lg0 t0
Merle Pindmaa | e1 e5 kir1 kir5
Merli Leemet | i1 i6
Robert Metsik | yh1 yh2 yh3 yh4 yh5
Silver Aarna | fys1 fys2 fys4 fys5 fys6
Susi Ann Kaljas | bvk5 lg5 t5
Tanel Pärnamets | geo1 geo2 geo3 geo4 geo5
Theana Teder | bvk2
Tatjana Opikova | bvk1 bvk4`,
SRC_TT = `0 0 2 f | 9:00 | 10:20 | e1 108 / e2 110 / e3 109 / m4 104 / m5 101 / kem6 208
0 3 2 | 10:40 | 12:00 | aj1 301 / yh2 107 / bio3 208 / bio4 205 / geo5 104
0 5 1 | 12:05 | 12:35 | t0 205 / t1 208 / t2 302 / t3 301 / t4 204 / t5 201
0 6 1 | 12:40 | 13:25 | bvk1 206 / bvk2 204 / bvk5 201 / bvk6 108 / i4 107 / i5 203 / i6 202
1 0 2 f | 9:00 | 10:20 | geo1 104 / aj2 302 / yh3 301 / kir4 106 / bio5 205
1 3 2 | 10:40 | 12:00 | bvk1 206 / bvk2 110 / bvk5 201 / bvk6 204 / i4 107 / i5 203 / i6 202
1 5 1 | 12:05 | 12:35 | lg0 205 / lg1 208 / lg2 302 / lg3 301 / lg4 204 / lg5 201
1 6 1 | 12:40 | 13:25 | m1 102 / m2 101 / m3 103 / e4 109 / e5 108 / e6 106
2 0 2 f | 9:00 | 10:20 | bvk0 301 / bvk3 204 / bvk4 206 / i1 202 / i2 107 / i3 203
2 3 2 | 10:40 | 12:00 | m1 102 / fys2 110 / m3 103 / e4 109 / e5 108 / e6 106
2 6 2 | 12:40 | 14:00 | bio1 205 / bio2 204 / aj3 302 / geo4 104 / yh5 301
2 9 1 l | 14:20 | 15:05 | e1 108 / e2 106 / e3 109 / m4 110 / m5 101 / m6 102
3 0 2 f | 9:00 | 10:20 | yh1 110 / kir2 109 / geo3 104 / aj4 302 / kir5 108
3 3 2 | 10:40 | 12:00 | m1 102 / m2 101 / m3 103 / kem4 208 / kem5 205 / fys6 202
3 6 2 | 12:40 | 14:00 | kem2 208 / fys3 205 / fys4 206 / m6 102
3 7 2 l | 13:00 | 14:20 | li1 sh / li5 sh
4 0 2 f | 9:00 | 10:20 | kem1 208 / m2 101 / li3 sh / li4 sh / fys5 206 / m6 102
4 3 2 | 10:40 | 12:00 | kir1 108 / geo2 104 / kir3 109 / yh4 106 / aj5 302
4 6 1 | 12:40 | 13:25 | bvk0 107 / bvk3 204 / bvk4 206 / i1 202 / i2 106 / i3 203
4 8 2 l | 13:45 | 15:05 | fys1 206 / li2 sh / kem3 208 / m4 110 / m5 106 / li6 sh`,
pages = Array.from(document.getElementsByClassName("page")),
allCookies = () => { return document.cookie.split(";"); },
setCookie = (k, v) => {
document.cookie = String(k) + "=" + String(v) + `; path=${PATH}; SameSite=Strict; Secure; expires=` + (new Date(Date.now()+8e9)).toUTCString();
},
getCookie = (k) => {
k += "=";
const a = allCookies();
const l = a.length;
for (let i=0; i<l; i++) {
let c = a[i];
while (c.charAt(0) == " ") {
c = c.substring(1);
}
if (c.indexOf(k) == 0) {
return c.substring(k.length, c.length);
}
}
return null;
},
clearAll = () => {
const
a = allCookies(),
l = a.length,
zd = (new Date(0)).toUTCString();
for (let i=0; i<l; i++) {
document.cookie = a[i] + `=;expires=${zd}`;
}
}
getData = async (url) => {
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`Võrgu vastuse viga: ${response.status}`);
}
const result = await response.text();
return result;
} catch (err) {
console.error(err.message);
}
},
getURLParams = (url) => {
let obj = {};
url.searchParams.entries().forEach(k => {
obj[k[0]] = k[1];
});
return obj;
},
sTheme = (a = 0) => {
th = Math.round(a%3);
const s =
th==0 ? (window.matchMedia("(prefers-color-scheme: dark)").matches ? 1 : 2)
: th;
document.getElementById("theme").innerText = ["vaikimisi", "tume", "hele"][th];
const d = document.documentElement.style;
[
["--bg-brightness", 0.5, 2],
["--bg", "#000", "#fff"],
["--bg-m", "#222", "#eee"],
["--gray-bg", "#333", "#ccc"],
["--gray", "#666", "#999"],
["--lighter-gray", "#888", "#666"],
["--ltrans", "#cccc", "#444c"],
["--light-fg", "#ccc", "#555"],
["--fg-m", "#ddd", "#555"],
["--fg", "#fff", "#000"],
["--darksky", "#445", "#dde"],
["--purple", "#86f", "#86f"],
["--purple-fg", "#cbf", "#435"],
].forEach(k => {
d.setProperty(k[0], k[s]);
});
setCookie("t", th);
},
sHilighting = (a) => {
hilighting = a ?? (!hilighting);
document.getElementById("hilighting").innerText = hilighting
? "jah"
: "ei";
setWeekday();
graphTT();
setCookie("h", hilighting ? "1" : "0");
}
load = (h) => {
if (h === null) {
return;
}
try {
gr = {
m: parseInt(h[0]),
e: parseInt(h[1]),
bvk: parseInt(h[2]),
i: parseInt(h[3]),
t: parseInt(h[4]),
s: parseInt(h[5]),
pkt: parseInt(h[6], 36)
};
if (gr.e < 1 || gr.e > 6) { throw new Error("Vale eesti keele kood."); }
if (gr.e < 1 || gr.e > 6) { throw new Error("Vale matemaatika kood."); }
if (gr.bvk > 6) { throw new Error("Vale b-võõrkeele kood."); }
if (gr.e < 1 || gr.e > 6) { throw new Error("Vale inglise keele kood."); }
if (gr.t > 5) { throw new Error("Vale tiimi kood."); }
if (gr.e < 1 || gr.e > 5) { throw new Error("Vale suure grupi kood."); }
if (gr.pkt > 16) { throw new Error("Vale praktikumi kood."); }
} catch (e) {
console.warn(`Viga salvestatud grupikombinatsiooni laadimisel (${e}). Salvestatud kood oli "${h}"`);
return;
}
genTT();
},
setWeekday = () => {
const w = [0,0,1,2,3,4,0][(new Date(Date.now()+25e6)).getDay()];
if (w !== weekday && hilighting) {
weekday = w;
graphTT();
}
},
save = () => {
code = `${gr.m}${gr.e}${gr.bvk}${gr.i}${gr.t}${gr.s}${(gr.pkt).toString(36)}`;
setCookie("g", code);
},
share = () => {
navigator.clipboard.writeText(`https://mk4i.github.io/tt?g=${code}`);
},
page = (n) => {
pages.forEach(k => {
k.style.display = (n===k.id)
? ""
: "none";
});
},
gg = (sub) => {
switch (sub) {
case "i":return gr.i;
case "e":return gr.e;
case "m":return gr.m;
case "fys":return gr.m;
case "kem":return gr.m;
case "bvk":return gr.bvk;
case "lg":return gr.t;
case "t":return gr.t;
case "pkt": return gr.pkt;
case "li":return gr.m;
default:return gr.s;
}
},
go = (id) => {
const t = op.find((k) => {
return (k.l == id);
});
if (t === undefined) {
console.warn(`Ei leitud sobivat õpetajat loetelust. Id: ${id}`);
return null;
}
return t.n;
},
gt = (sub) => {
switch (sub) {
case "aj":return "Ajalugu";
case "bio":return "Bioloogia";
case "bvk":return ["Saksa", "Prantsuse", "Vene"][[0, 2, 2, 2, 2, 1, 1][gr.bvk]];
case "e":return "Eesti";
case "fys":return "Füüsika";
case "i":return "Inglise";
case "kir":return "Kirjandus";
case "geo":return "Geograafia";
case "kem":return "Keemia";
case "kst":return "Kunst";
case "lg":return "Luge";
case "li":return "Keka";
case "m":return "Mate";
case "pkt":return "Praktikum";
case "t":return "Tiimit";
case "yh":return "Ühiskonnaõp";
}
},
pushItem = (
x, y, title = "-", start_time = undefined, end_time = undefined,
location = false, name = false, isBreak = false, pos = false, w = 1
) => {
const t_str = start_time ? (end_time ? start_time + " - " + end_time : start_time) : (end_time??"-");
const obj = { x: x, y: y, title: title, time: t_str };
if (w > 1) {
obj.w = w;
}
if (location !== false) {
obj.location = location;
}
if (name !== false) {
obj.name = name;
}
if (isBreak === true) {
obj.isBreak = true;
}
if (pos !== false) {
obj.position = pos;
}
tt.push(obj);
},
getScale = (t, c) => {
return (t < c)
? t/c
: 1;
},
shortName = (str) => {
let r = [];
str.split("/").forEach(k => {
const nl = k.trim().split(" ");
r.push(nl[0].split("-")[0] + " " + nl.at(-1).split("-")[0][0]);
});
return r.join(", ");
},
notSharedTimetable = () => {
const
url = new URL(window.location),
param = getURLParams(url);
if (param.g !== undefined) {
url.searchParams.delete("g");
window.history.replaceState({}, document.title, url.toString());
}
const c = getCookie("g");
if (c !== null) {
page("timetable");
load(c);
save();
} else {
page("home");
}
document.getElementById("share-warning").style.display = "none";
},
graphTT = () => {
const e = document.getElementById("tt");
e.innerHTML = `<div class="num" style="grid-column: 2 / span 2;">1</div>
<div class="num s" style="grid-column: 4;">Amps</div>
<div class="num" style="grid-column: 5 / span 2;">2</div>
<div class="num s" style="grid-column: 7;">Proaeg</div>
<div class="num" style="grid-column: 8 / span 2;">3</div>
<div class="num" style="grid-column: 10 / span 2;">4</div>`;
for (let i = 0; i < 5; i++) {
const div = document.createElement("div");
div.classList.add("wkd");
div.style.gridRow = i+2;
div.innerText = "ETKNR"[i];
if (hilighting && i != weekday) {
div.classList.add("unhilighted");
}
e.appendChild(div);
}
const len = tt.length;
for (let i = 0; i < len; i++) {
const k = tt[i];
const div = document.createElement("div");
div.classList.add("item", k.isBreak?"break":"lesson");
if (k.position !== undefined) {
div.classList.add(k.position);
}
div.style.gridArea = `${k.y+2} / ${k.x+2}${k.w>1?" / span 1 / span "+k.w:""}`;
const label = document.createElement("label");
label.innerText = k.title;
const time = document.createElement("time");
time.innerText = k.time;
div.appendChild(label);
div.appendChild(time);
if (hilighting && k.y != weekday) {
div.classList.add("unhilighted");
}
e.appendChild(div);
const
wl = div.getBoundingClientRect().width,
scl = getScale(0.96*wl, label.getBoundingClientRect().width);
if (scl < 1) {
label.style.scale = scl;
}
const nk = (k.name !== undefined) + (k.location !== undefined);
if (nk == 2) {
const br = document.createElement("p");
br.innerText = k.name;
br.classList.add("bottom", "right");
div.appendChild(br);
if (br.getBoundingClientRect().width > 0.48*wl) {
br.innerText = shortName(k.name);
}
const bl = document.createElement("p");
bl.innerText = k.location;
bl.classList.add("bottom", "left");
div.appendChild(bl);
if (
br.getBoundingClientRect().width <= 0.48*wl &&
bl.getBoundingClientRect().width <= 0.48*wl
) {
continue;
}
div.removeChild(bl);
div.removeChild(br);
}
const bc = document.createElement("p");
bc.innerText = nk==0 ? "-" : ((k.location??"") + (k.w>1 ? " " : " ") + (k.name??"")).trim();
bc.classList.add("bottom", "center");
div.appendChild(bc);
if (bc.getBoundingClientRect().width > 0.96*wl && k.name !== undefined) {
bc.innerText = (!k.location ? "" : k.location + (k.w>1 ? " " : " ")) + shortName(k.name);
}
const bcs = getScale(0.96*wl, bc.getBoundingClientRect().width);
if (bcs < 1) {
bc.style.scale = bcs;
}
}
},
waitForInput = async (acceptionList, rejection) => {
return new Promise((resolve, reject) => {
const accept = function() {
const r = parseInt(this.value);
resolve(isNaN(r) ? this.value : r);
};
const abort = function() {
this.removeEventListener("click", abort);
reject(new Error("Aborted"));
}
acceptionList.forEach(k => {
k.addEventListener("click", accept);
});
rejection.addEventListener("click", abort);
});
},
setupPage = (pre, options) => {
document.getElementById("pre").innerHTML = pre;
const opt = document.getElementById("opt");
let acceptionList = [];
opt.innerHTML = "";
options.forEach(k => {
const
b = document.createElement("button");
b.value = k.value;
b.innerHTML = k.title;
opt.appendChild(b);
acceptionList.push(b);
});
return(waitForInput(acceptionList, document.getElementById("abort")));
}
genTT = () => {
tt = [];
ttc.split("\n").forEach(k => {
if (k !== "" && k[0] !== "#") {
const
s = k.split("|"),
coord = s[0].split(" "),
y = Number(coord[0]),
x = Number(coord[1]),
w = Number(coord[2]),
pos = coord[3]==="f" ? Pos.FIRST : (coord[3]==="l" ? Pos.LAST : Pos.MID),
startTime = s[1].trim(),
endTime = s[2].trim(),
gi = s[3].trim().split("/"),
gil = gi.length;
let
title = undefined,
location = false,
name = false,
isBreak = false;
for (let i = 0; i < gil; i++) {
const
dat = gi[i].trim().split(" "),
id = dat[0],
loc = dat[1],
gnum = id.match(/\d/),
sub = id.replace(/\d/, ""),
ag = gg(sub);
if (ag == gnum || gnum === null) {
title = gt(sub);
name = go(sub + ag);
location = loc;
break;
}
}
if (title !== undefined) {
pushItem(
x, y,
title,
startTime, endTime,
location, name, isBreak,
pos, w
);
}
}
});
const p = pkt[gr.pkt];
pushItem(8, 1, "Praktikum", p.stime, p.etime, p.loc, p.n, false, Pos.LAST, 2);
for (let i = 0; i < 5; i++) {
pushItem(2, i, "Amps", "10:20", "10:40", "-", false, true);
}
for (let i = 2; i < 5; i++) {
pushItem(5, i, "Pro", "12:00", "12:40", "-", false, true);
}
pushItem(7, 0, "Lõuna", "13:25", "13:45", "-", false, true, Pos.LAST);
pushItem(7, 1, "Lõuna", "13:25", "13:45", "-", false, true);
pushItem(8, 2, "Lõuna", "14:00", "14:20", "-", false, true);
if (([1, 5]).includes(gr.m)) {
pushItem(6, 3, "Lõuna", "12:40", "13:00", "-", false, true);
} else {
pushItem(8, 3, "Lõuna", "14:00", "14:20", "-", false, true, Pos.LAST);
}
pushItem(7, 4, "Lõuna", "13:25", "13:45", "-", false, true);
graphTT();
}
main = async () => {
SRC_OP.split("\n").forEach(k => {
const
l = k.split("|"),
n = l[0].trim();
l[1].trim().split("\t").forEach(s => {
op.push({
l: s.trim(),
n: n
});
});
});
SRC_PKT.split("\n").forEach(k => {
const l = k.split("|").map(m => {
const v = m.trim();
return v=="" ? undefined : v;
});
pkt.push({
t: l[0],
stime: l[1],
etime: l[2],
loc: l[3],
n: l[4]
});
});
ttc = SRC_TT;
sTheme(getCookie("t")??0);
sHilighting(getCookie("h")==="1");
setWeekday();
const param = getURLParams(new URL(window.location));
if (param.g !== undefined) {
page("timetable");
load(param.g);
code = param.g;
} else {
notSharedTimetable();
}
window.addEventListener("focus", setWeekday);
}
setup = async () => {
page("setup");
let gn = {};
try {
let options = [];
for (let i = 1; i < 7; i++) {
options.push({title: `<strong>9.${i}</strong> (${go(`m${i}`)})`, value: i});
}
gn.m = await setupPage("<h1>Matemaatika grupp</h1><p>Millises matemaatika grupis Sa oled?</p>", options);
options = [];
for (let i = 1; i < 7; i++) {
options.push({title: `<strong>9.${i}</strong> (${go(`e${i}`)})`, value: i});
}
gn.e = await setupPage("<h1>Eesti keel</h1><p>Millises eesti keele grupis Sa oled?</p>", options);
options = [];
for (let i = 0; i < 7; i++) {
options.push({title: `<strong>${
["saksa keel", "vene keel 1", "vene keel 2", "vene keel 3", "vene keel 4", "prantsuse keel 1", "prantsuse keel 2"][i]
}</strong> (${go(`bvk${i}`)})`, value: i});
}
gn.bvk = await setupPage("<h1>B-võõrkeel</h1><p>Millises B-võõrkeele grupis Sa oled?</p>", options);
options = [];
for (let i = 1; i < 7; i++) {
options.push({title: `<strong>${["I", "II", "III"][(i-1)%3]} ${i<4?"A":"B"}</strong> (${go(`i${i}`)})`, value: i});
}
gn.i = await setupPage("<h1>Inglise keele grupp</h1><p>Millises inglise keele grupis Sa oled?</p>", options);
let fault = [];
if ((gn.m<4 && gn.e>3) || (gn.m>3 && gn.e<4)) {
fault.push(`Matemaatika grupp <strong>9.${gn.m}</strong> ja eesti keele grupp <strong>9.${gn.e}</strong>`);
}
const ib = gn.bvk==0 || gn.bvk==3 || gn.bvk==4;
if (ib ? (gn.ik<4) : (gn.ik>2)) {
fault.push(`Inglise keele grupp <strong>${["I", "II", "III"][(gn.i-1)%3]} ${gn.i<4?"A":"B"}</strong> ja b-võõrkeele grupp <strong>${["saksa keel", "vene keel 1", "vene keel 2", "vene keel 3", "vene keel 4", "prantsuse keel 1", "prantsuse keel 2"][gn.bvk]}</strong>`);
}
const fl = fault.length;
if (fl>0) {
await setupPage(`<h1>Gruppide viga</h1><h2>Järgnev${fl>1?"ad":""} grupikombinatsioon${fl>1?"id":""} on võimatu${fl>1?"d":""}.</h2><p>${fault.join("<br>")}<br><br>${fl>1?"Need":"See"} eelda${fl>1?"vad":"b"}, et Sul on võimalik olla mitmes kohas korraga, mis pole praktiliselt võimalik. Soovitatav on katkestada ja alustada otsast peale, kuid soovi korral saad ikkagi valitud grupikombinatsiooniga (vigase) tunniplaani genereerida, vajutades <strong>Jätka</strong>.</p>`, [{title: "Jätka", value: 0}]);
}
options = [];
for (let i = 0; i < 6; i++) {
options.push({title: `<strong>9${"aejkps"[i]}</strong> (${go(`t${i}`)})`, value: i});
}
gn.t = await setupPage("<h1>Tiim</h1><p>Millise tiimi liige Sa oled?</p>", options);
options = [];
for (let i = 1; i < 6; i++) {
options.push({title: ["alfa","beeta","gamma","delta","epsilon"][i-1], value: i});
}
gn.s = await setupPage("<h1>Suur grupp</h1><p>Millises suures grupis Sa oled?</p>", options);
options = [];
for (let i = 0; i < pkt.length; i++) {
options.push({title: pkt[i].t, value: i});
}
gn.pkt = await setupPage("<h1>Praktikum</h1><p>Millises praktikumis Sa käid?</p>", options);
gr = gn;
page("timetable");
save();
genTT();
} catch (e) {
if (gr === null) {
page("home");
} else {
page("timetable");}}}
main();
</script>
</body>
</html>