-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtuwel-plus.user.js
More file actions
187 lines (134 loc) · 5.57 KB
/
tuwel-plus.user.js
File metadata and controls
187 lines (134 loc) · 5.57 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
// ==UserScript==
// @name TUWEL+
// @namespace https://fsinf.at/
// @match https://tuwel.tuwien.ac.at/*
// @grant none
// @version 1.4
// @icon https://i.imgur.com/gJ9tqWL.png
// @description Various small improvements to TUWEL including LVA-abbreviations and "Select All" for Kreuzerl
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js
// ==/UserScript==
this.$ = this.jQuery = jQuery.noConflict(true);
const DictLVA = { // keyword : abbreviation
"Algebra und Diskrete Mathematik": "ADM",
"Grundzüge digitaler Systeme": "GDS",
"Angleichungskurs Mathematik": "AKMath",
"Einführung in die Programmierung 1": "EP1",
"Einführung in die Programmierung 2": "EP2",
"Denkweisen der Informatik": "Denki",
"Mathematisches Arbeiten": "MathArb",
"Orientierung Informatik": "Ori",
"Algorithmen und Datenstrukturen": "AlgoDat",
}
const seperator = "<b> » </b>"
const courseTileSelector = 'a.coursename[href*="https://tuwel.tuwien.ac.at/course/view.php?id="] > span.multiline > span[aria-hidden="true"]';
const courseListSelector = 'a.coursename[href*="https://tuwel.tuwien.ac.at/course/view.php?id="]'
const mobileDrawerSelector = 'div.drawer a.list-group-item[href*="https://tuwel.tuwien.ac.at/course/view.php?id="]'
const courseTitleSelector = 'h1.h2.mb-0'
const courseDropdownMenuItemSelector = 'div.carousel-inner > a.dropdown-item[role="menuitem"][href*="https://tuwel.tuwien.ac.at/course/view.php?id="]';
const breadcrumbSelector = 'li.breadcrumb-item:first > a';
// prepend the LVA abbreviation for a selected element
function editGeneric (selector) {
$(selector).each(function() {
//get text of selected element, excluding it's decendents
const fullName = $(this).clone().children().remove().end().text();
if (fullName) {
// if the LVA-name has a specified abbreviation in DictLVA, use it
for (LVA in DictLVA) {
if (fullName.includes(LVA)) {
shortName = DictLVA[LVA];
// set the new text in the menu item
var newName = "<b class='shortLvaName'>" + shortName + "</b>" + seperator + fullName;
$(this).html(newName);
}
}
}
});
}
// edit the breadcrumb to contain a readable abbreviation of the LVA name
function editBreadcrumb(selector) {
const fullName = $(selector).attr("title");
if (fullName) {
const match = fullName.match(/^([a-zA-Z]).{8}/);
// set the shortName to a truncated version (…) of fullName for now
if (match) {
var shortName = match[0] + "…";
}
// if the LVA-name has a specified abbreviation in DictLVA, use it
for (LVA in DictLVA) {
if (fullName.includes(LVA)) {
shortName = DictLVA[LVA];
}
}
// set the new text in the breadcrumb (shortName + semester)
var newName = "<b class='shortLvaName'>" + shortName + "</b>" + seperator + fullName.match(/.{5}$/)[0];
$("li.breadcrumb-item:first > a").html(newName);
}
}
// highlight quiz result
function highlightQuizResult() {
gradeCell = "table.quizreviewsummary tr:includes('Bewertung') > td"
if ($(gradeCell).text().includes("100%")) {
$(gradeCell).css("background-color", "lightgreen");
} else {
$(gradeCell).css("background-color", "pink");
}
}
function addtickAllKreuzerlButton() {
$("#fgroup_id_buttonar > div > div > div").append('<input class="btn btn-secondary mr-1" id="select-all-button" type="button" value="Alle auswählen"">')
document.querySelector("#select-all-button").addEventListener("click", tickAllKreuzerl);
checkboxes = $("div.checkboxgroup1 input.checkboxgroup1");
}
function tickAllKreuzerl() {
checkboxes.each(function() {
(this).checked = true;
})
document.querySelector("#select-all-button").removeEventListener("click", tickAllKreuzerl);
document.querySelector("#select-all-button").value = "Keine auswählen";
document.querySelector("#select-all-button").addEventListener("click", untickAllKreuzerl);
}
function untickAllKreuzerl() {
checkboxes.each(function() {
(this).checked = false;
})
document.querySelector("#select-all-button").removeEventListener("click", untickAllKreuzerl);
document.querySelector("#select-all-button").value = "Alle auswählen";
document.querySelector("#select-all-button").addEventListener("click", tickAllKreuzerl);
}
function tickSubmissionStatement() {
$("input#id_submissionstatement").prop('checked', true);
}
function smallerEditButton() {
$("label[for$='-editingswitch']").replaceWith("<i class='icon fa fa-edit fa-fw'></i>");
}
function init() {
const href = window.location.href;
editGeneric(mobileDrawerSelector);
editGeneric(courseDropdownMenuItemSelector);
//set dropdown text to blue color to stand out more (OG TUWEL blue: #006699, no contrast on hover)
$(courseDropdownMenuItemSelector + " b.shortLvaName").css("color", "#013d5b");
editBreadcrumb(breadcrumbSelector);
//if "my courses" page is open
if (href.includes("/my")) {
smallerEditButton();
// wait for content to load on "my courses"
setTimeout(() => { editGeneric(courseTileSelector) }, 1600);
setTimeout(() => { editGeneric(courseListSelector) }, 1600);
}
//if course main page is open
if (href.includes("/course/view.php?id=")) {
editGeneric(courseTitleSelector);
}
if (href.includes("/mod/quiz/review.php")) {
highlightQuizResult();
}
if (href.includes("/mod/checkmark")) {
addtickAllKreuzerlButton();
}
if (href.includes("/mod/assign/view.php")) {
tickSubmissionStatement();
}
}
$(document).ready(function() {
init();
});