forked from mangei/tissquickregistrationscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtiss_quick_registration_script.user.js
executable file
·640 lines (525 loc) · 21.4 KB
/
tiss_quick_registration_script.user.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
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
// ==UserScript==
// @name TISS Quick Registration Script
// @namespace http://www.manuelgeier.com/
// @version 1.6.0
// @description Script to help you to get into the group you want. Opens automatically the right panel, registers automatically and confirms your registration automatically. If you don't want the script to do everything automatically, the focus is already set on the right button, so you only need to confirm. There is also an option available to auto refresh the page, if the registration button is not available yet, so you can open the site and watch the script doing its work. You can also set a specific time when the script should reload the page and start.
// @match https://tiss.tuwien.ac.at/*
// @copyright 2012+, Manuel Geier
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// ==/UserScript==
/*
Changelog:
v.1.6.0 [28.11.2018]
+ Added: exam-registration support (Thanks to @XtomtomX, #11)
v1.5.3 [29.02.2016]
~ Added: .gitignore
~ Fix: missing reference to 'options' object
~ Fix: wrong option name ('semesterCheckEnabled' instead of 'lvaSemesterCheckEnabled')
~ String/Number compare with === instead of ==, and !== instead of !=
~ Fix #9: id no longer available for wrapper element. replace it by element itself and adjust selectors.
~ Fix: toggle for groups (now without id selector)
~ Fix: group name selector now matches the exact name and not only if it contains the name
v1.5.2 [?]
- went missing :P
v1.5.1 [09.10.2015]
~ Fix: adjusts group label selector
~ Fix: Remove leading zero for month which leads to unintended octal interpretation
v1.5 [04.10.2015]
+ allow to enter a study code, if you have multiple ones
+ add flags to en-/disable checks
~ Code cleanup
v1.4 [07.09.2013]
+ show or hide logoutput on screen (option: showLog [true/false])
+ many improvements
~ Code refactoring
v1.3 [01.03.2013]
+ Feature: automatically presses the Ok button at the final info page
~ Code refactoring
v1.2 [27.02.2013]
+ Feature: ability to register to a LVA; just set 'isGroupRegistration' to 'false'
+ Feature: selected group label is now marked with light green
~ Bugfix/Quickfix: overflow in setTimeout causes an constant refresh of the page; now the page gets refreshed at least often if the specific start time is in the future
v1.1
+ Feature: Let the script start at a specific time.
v1.0 (2012)
Initial release
*/
(function TissQuickRegistrationClass() {
var self = this;
///////////////////////////////////////////////////////////////////////
// Configurate the script here
//
var options = {
// global option to enable or disable the script [true,false]
scriptEnabled: true,
// define here the type of registration [lva,group,exam]
registrationType: "group",
// name of you the group you want to join (only for registrationType 'group') [String]
nameOfGroup: "Gruppe 001",
// name of the exam which you want to join (only for registrationType 'exam') [String]
nameOfExam: "fillInNameOfExam",
dateOfExam: '', // not used yet
// checks if you are at the correct lva page
lvaCheckEnabled: true,
// only if the number is right, the script is enabled [String]
lvaNumber: "123.456",
// if you have multiple study codes, enter here the study code number you want
// to register for eg. '123456' (no blanks). Otherwise leave empty. [String]
studyCode: '',
// autoGoToLVA: true, // coming soon
// checks if you are at the correct semester
lvaSemesterCheckEnabled: true,
// only if the semester is right, the script is enabled [String]
lvaSemester: "2018W",
// autoGoToSemester: true, // coming soon
// automatically opens the detail panel of a group [true,false]
openPanel: true,
// automatically presses the register button if it is available [true,false]
autoRegister: true,
// automatically presses the confirm button for your registration [true,false]
autoConfirm: true,
// continuously refresh the page until the script can register you [true,false]
autoRefresh: true,
// automatically presses the ok button on the confirmation info page [true,false]
autoOkPressAtEnd: true,
// a delay on the confirm info page, until the ok button gets pressed
// this is useful if you want to continuously cycle through the registration process
// until you are registered and with this parameter you can define a "cycle delay" at the end.
// This could happen, if (for some reason) you are not on the whitelist for this course.
// [Integer]
okPressAtEndDelayInMs: 1000,
// let the script start at a specific time [true,false]
startAtSpecificTime: true,
// define the specific time the script should start [Date]
// new Date(year, month, day, hours, minutes, seconds, milliseconds)
// note: months start with 0
specificStartTime: new Date(2018, 1 - 1, 1, 11, 11, 11, 0),
// if a specific time is defined, the script will refresh some ms sooner to adjust a delay [Integer]
delayAdjustmentInMs: 300,
// show log output of the script on screen [true,false]
showLog: true
};
//
// End of configuration
///////////////////////////////////////////////////////////////////////
self.init = function () {
self.extendJQuery();
self.tissQuickRegistration();
};
self.extendJQuery = function () {
jQuery.fn.justtext = function () {
return $(this).clone()
.children()
.remove()
.end()
.text().trim();
};
};
self.tissQuickRegistration = function () {
if (options.scriptEnabled) {
self.pageLog("TISS Quick Registration Script enabled");
self.pageLog("LVA Number: " + self.getLVANumber());
self.pageLog("LVA Name: " + self.getLVAName());
self.pageLog("Selected Tab: " + self.getSelectedTab());
if (options.registrationType === "lva") {
options.nameOfGroup = "LVA-Anmeldung";
}
// test if the lva and group exists
if (!options.lvaCheckEnabled || self.doLvaCheck()) {
if (!options.lvaSemesterCheckEnabled || self.doSemesterCheck()) {
if(options.registrationType !== "exam") { // own code
var groupLabel = self.doGroupCheck();
if (groupLabel !== null) {
self.highlight(groupLabel);
}
} else {
var examLabel = self.doExamCheck();
if (examLabel !== null) {
self.highlight(examLabel);
}
}
}
}
if (options.startAtSpecificTime) {
self.pageLog("Scripts starts at: " + self.getFormatedDate(options.specificStartTime));
self.pageLog("Delay adjustment in ms: " + options.delayAdjustmentInMs);
self.startTimer(options.specificStartTime.getTime() - options.delayAdjustmentInMs);
} else {
self.analysePage();
}
} else {
self.pageLog("TISS Quick Registration Script disabled");
}
};
self.startTimer = function (startTime) {
var offset = startTime - new Date().getTime();
if (offset > 0) {
self.startRefreshTimer(startTime);
} else {
self.analysePage();
}
};
self.startRefreshTimer = function (startTime) {
self.printTimeToStart(startTime);
var maxMillis = 2147483647;
var offset = startTime - new Date().getTime();
// prevent an overflow
if (offset > maxMillis) {
offset = maxMillis;
}
window.setTimeout(self.refreshPage, offset);
};
self.printTimeToStart = function (startTime) {
var offset = (startTime - new Date().getTime()) / 1000;
var out = "Refresh in: " + offset + " seconds";
self.log(out);
self.pageCountdown(out);
window.setTimeout(function () {
self.printTimeToStart(startTime);
}, 1000);
};
self.refreshPage = function () {
location.reload();
};
self.analysePage = function () {
var tab = self.getSelectedTab();
var confirmButton = self.getConfirmButton();
var okButton = self.getOkButton();
var studyCodeSelect = self.getStudyCodeSelect();
self.log("tab: " + tab);
self.log("confirmButton: " + confirmButton);
self.log("okButton: " + okButton);
if (tab === "LVA-Anmeldung") {
self.onLVAPage();
} else if (tab === "Gruppen") {
self.onGroupPage();
} else if (tab === "Prüfungen") {
self.onExamPage();
} else if (studyCodeSelect.length > 0) {
self.onStudyCodeSelectPage();
} else if (confirmButton.length > 0) {
self.onConfirmPage();
} else if (okButton.length > 0) {
self.onConfirmInfoPage();
}
};
self.getLVANumber = function () {
return $('#contentInner').find('h1 span:first').text().trim();
};
self.getLVAName = function () {
return $('#contentInner').find('h1').justtext();
};
self.getSemester = function () {
return $('#contentInner').find('h1 select').val();
};
self.getSelectedTab = function () {
return $('li.ui-tabs-selected').text().trim();
};
self.getSubHeader = function () {
return $('#contentInner').find('#subHeader').text().trim();
};
self.onLVAPage = function () {
self.onGroupPage();
};
self.onGroupPage = function () {
if (options.lvaCheckEnabled && !self.doLvaCheck()) {
return;
}
if (options.lvaSemesterCheckEnabled && !self.doSemesterCheck()) {
return;
}
var groupLabel = self.doGroupCheck();
if (groupLabel === null) {
return;
}
self.highlight(groupLabel);
var groupWrapper = groupLabel.closest('.groupWrapper');
// open the panel if the option is activated
if (options.openPanel) {
groupWrapper.children().show();
// for some reason, we have to wait some time here and try it again :/
setTimeout(function () {
groupWrapper.children().show();
}, 100);
}
// search for the registration button
var regButton = self.getRegistrationButton(groupWrapper);
self.log('regButton: ' + regButton);
// push the button
if (regButton.length > 0) {
self.highlight(regButton);
regButton.focus();
if (options.autoRegister) {
regButton.click();
}
} else {
if (self.getGroupCancelButton(groupWrapper).length > 0) {
self.pageOut('you are registered in group: ' + options.nameOfGroup);
} else {
// Only refresh the page if the option is set and if the registration is not yet completed.
if (options.autoRefresh) {
refreshPage();
}
self.pageOut('no registration button found');
}
}
};
self.onExamPage = function () {
if (options.lvaCheckEnabled && !self.doLvaCheck()) {
return;
}
if (options.lvaSemesterCheckEnabled && !self.doSemesterCheck()) {
return;
}
var examLabel = self.doExamCheck();
if (examLabel === null) {
return;
}
self.highlight(examLabel);
var examWrapper = examLabel.closest('.groupWrapper');
// open the panel if the option is activated
if (options.openPanel) {
examWrapper.children().show();
// for some reason, we have to wait some time here and try it again :/
setTimeout(function () {
examWrapper.children().show();
}, 100);
}
// search for the registration button
var regButton = self.getRegistrationButton(examWrapper);
self.log('regButton: ' + regButton);
// push the button
if (regButton.length > 0) {
self.highlight(regButton);
regButton.focus();
if (options.autoRegister) {
regButton.click();
}
} else {
if (self.getGroupCancelButton(examWrapper).length > 0) {
self.pageOut('you are registered in exam: ' + options.nameOfExam);
} else {
// Only refresh the page if the option is set and if the registration is not yet completed.
if (options.autoRefresh) {
refreshPage();
}
self.pageOut('no registration button found');
}
}
};
self.onStudyCodeSelectPage = function () {
var studyCodeSelect = self.getStudyCodeSelect();
var confirmButton = self.getConfirmButton();
self.highlight(confirmButton);
if (options.studyCode !== undefined && options.studyCode.length > 0) {
self.setSelectValue(studyCodeSelect, options.studyCode);
}
confirmButton.focus();
if (options.autoConfirm) {
confirmButton.click();
}
};
self.onConfirmPage = function () {
var confirmButton = self.getConfirmButton();
self.highlight(confirmButton);
confirmButton.focus();
if (options.autoConfirm) {
confirmButton.click();
}
};
self.onConfirmInfoPage = function () {
var okButton = self.getOkButton();
self.highlight(okButton);
if (options.autoOkPressAtEnd) {
setTimeout(function () {
var okButton = self.getOkButton();
okButton.click();
}, options.okPressAtEndDelayInMs);
}
};
self.pageOut = function (text) {
var out = self.getOutputField();
out.text(text);
};
self.pageCountdown = function (text) {
var out = self.getCountdownField();
out.text(text);
};
self.pageLog = function (text) {
self.appendToLogField(text);
};
self.getOutputField = function () {
var outputField = $('#TQRScriptOutput');
if (outputField.length === 0) {
self.injectOutputField();
outputField = self.getOutputField();
}
return outputField;
};
self.getCountdownField = function () {
var countdownField = $('#TQRScriptCountdown');
if (countdownField.length === 0) {
self.injectCountdownField();
countdownField = self.getCountdownField();
}
return countdownField;
};
self.getLogField = function () {
var logField = $('#TQRScriptLog');
if (logField.length === 0) {
self.injectLogField();
logField = self.getLogField();
if (options.showLog) {
logField.show();
} else {
logField.hide();
}
}
return logField;
};
self.injectOutputField = function () {
var el = $('#contentInner');
var log = $('#TQRScriptLog');
if (log.length) {
el = log;
}
el.before('<div id="TQRScriptOutput" style="color: red; font-weight: bold; font-size: 14pt; padding: 8px 0px;"></div>');
};
self.injectCountdownField = function () {
var el = $('#contentInner');
var log = $('#TQRScriptLog');
if (log.length) {
el = log;
}
el.before('<div id="TQRScriptCountdown" style="color: blue; font-weight: bold; font-size: 14pt; padding: 8px 0px;"></div>');
};
self.injectLogField = function () {
$('#contentInner').before('<div id="TQRScriptLog" style="color: black; background-color: #FFFCD9; font-size: 10pt;"><b>Information Log:</b></div>');
};
self.appendToLogField = function (text) {
var log = self.getLogField();
var newText = log.html() + "<br />" + text;
log.html(newText);
};
self.getRegistrationButton = function (groupWrapper) {
var regButton;
if (options.registrationType === "group") {
regButton = $(groupWrapper).find("input:submit[value='Anmelden']");
if (regButton.length === 0) {
regButton = $(groupWrapper).find("input:submit[value='Voranmelden']");
if (regButton.length === 0) {
regButton = $(groupWrapper).find("input:submit[value='Voranmeldung']");
}
}
} else if (options.registrationType === "exam") {
regButton = $(groupWrapper).find("input:submit[value='Anmelden']");
} else if (options.registrationType === "lva") {
regButton = $(groupWrapper).find("input:submit[value='Anmelden']");
} else {
self.pageLog("registrationType Error: unknown type '" + options.registrationType + "'");
}
return regButton;
};
self.getGroupCancelButton = function (groupWrapper) {
var unregButton = null;
if (options.registrationType === "group") {
unregButton = $(groupWrapper).find("input:submit[value='Abmelden']");
} else if (options.registrationType === "exam") {
unregButton = $(groupWrapper).find("input:submit[value='Abmelden']");
} else if (options.registrationType === "lva") {
unregButton = $(groupWrapper).find("input:submit[value='Abmelden']").filter(function (index) {
return $(this).attr("id") !== 'registrationForm:confirmOkBtn';
});
} else {
self.pageLog("registrationType Error: unknown type '" + options.registrationType + "'");
}
return unregButton;
};
self.getConfirmButton = function () {
var confirmButton = $("form#regForm input:submit[value='Anmelden']");
if (confirmButton.length === 0) {
confirmButton = $("form#regForm input:submit[value='Voranmelden']");
if (confirmButton.length === 0) {
confirmButton = $("form#regForm input:submit[value='Voranmeldung']");
}
}
return confirmButton;
};
self.getOkButton = function () {
return $("form#confirmForm input:submit[value='Ok']");
};
self.getStudyCodeSelect = function () {
return $("#regForm").find("select");
};
self.getGroupLabel = function (nameOfGroup) {
return $(".groupWrapper .header_element span").filter(function () {
return $(this).text().trim() === nameOfGroup;
});
};
self.getExamLabel = function (nameOfExam) {
return $(".groupWrapper .header_element span").filter(function () {
var tmp = $(this).text().trim();
return tmp.match(nameOfExam);
});
};
self.getExamDate = function (dateOfExam) {
return $(".groupWrapper .header_element").filter(function () {
return $(this).text().trim() === dateOfExam;
});
};
self.highlight = function (object) {
object.css("background-color", "lightgreen");
};
self.isCorrectSemester = function () {
return self.getSubHeader().contains(options.lvaSemester);
};
self.setSelectValue = function ($element, value) {
$element.find('option').removeAttr('selected');
$element.find('option[value="' + value + '"]').attr('selected', 'selected');
};
self.doGroupCheck = function () {
var groupLabel = self.getGroupLabel(options.nameOfGroup);
if (groupLabel.length === 0) {
self.pageOut('group not found error: ' + options.nameOfGroup);
return null;
} else {
return groupLabel;
}
};
self.doLvaCheck = function () {
var lvaNumber = self.getLVANumber();
lvaNumber = lvaNumber.replace(/[^\d]/, '');
var optionsLvaNumber = options.lvaNumber.replace(/[^\d]/, '');
if (lvaNumber !== optionsLvaNumber) {
self.pageOut('wrong lva number error: expected: ' + optionsLvaNumber + ', got: ' + lvaNumber);
return false;
}
return true;
};
self.doSemesterCheck = function () {
var subheader = self.getSubHeader();
if (subheader.indexOf(options.lvaSemester) === -1) {
self.pageOut('wrong semester error: expected: ' + options.lvaSemester + ', got: ' + subheader.substring(0, 5));
return false;
}
return true;
};
self.doExamCheck = function () {
var examLabel = self.getExamLabel(options.nameOfExam);
var examDate = self.getExamDate(options.dateOfExam);
if (examLabel.length === 0) {
self.pageOut('exam not found error: ' + options.nameOfExam);
return null;
} else {
return examLabel;
}
};
self.getFormatedDate = function (date) {
return "" + date.getDate() + "." + (date.getMonth() + 1) + "." + date.getFullYear() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds() + ":" + date.getMilliseconds();
};
self.log = function (message) {
console.log(message);
};
// Initialize the script
self.init();
})();