-
Notifications
You must be signed in to change notification settings - Fork 5
/
tiss-enhancement.user.js
192 lines (167 loc) · 9.67 KB
/
tiss-enhancement.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
// ==UserScript==
// @name VoWi and Mattermost links in TISS
// @description Add links to VoWi pages and Mattermost channels to TISS courses.
// @namespace https://fsinf.at/
// @match https://tiss.tuwien.ac.at/course/educationDetails.xhtml*
// @match https://tiss.tuwien.ac.at/course/courseDetails.xhtml*
// @match https://tiss.tuwien.ac.at/education/favorites.xhtml*
// @grant none
// @version 1.12
// @downloadURL https://fsinf.at/userscripts/tiss-enhancement.user.js
// @updateURL https://fsinf.at/userscripts/tiss-enhancement.user.js
// ==/UserScript==
// Inspired by https://greasyfork.org/de/scripts/9914-tiss-enhancer/
if (document.getElementsByClassName("loading").length > 0) {
// Don't run the script on sites which only contain the loading animation.
return;
}
function vowi_link(tissID) {
return "https://vowi.fsinf.at/wiki/Spezial:CourseById?ns=TU_Wien&id=" + tissID;
}
function mm_link(lvaTitle) {
var channame = lvaTitle.toLowerCase().replace('ä','ae').replace('ö','oe').replace('ü','ue');
channame = channame.replace(/[^a-zA-Z0-9_]/g,'-');
channame = channame.replace(/-+/g,'-');
channame = channame.substring(0,63);
channame = channame.replace(/-$/, '');
return "https://mattermost.fsinf.at/w-inf-tuwien/channels/" + encodeURIComponent(channame);
}
var page = window.location.href.match(/tiss.tuwien.ac.at\/([\w\/]+)\.xhtml/i)[1];
var locale = document.cookie.match(/TISS_LANG=([\w-]+)/);
locale = locale ? locale[1] : "de";
// course overview: add VoWi link
if (page == "course/educationDetails" || page == "course/courseDetails") {
var header = document.getElementById("subHeader").innerText;
var heading = document.getElementById("contentInner").getElementsByTagName("h1")[0].innerText;
var lvaTitle = /^\s*[A-Z0-9\.]{7} (.*)$/gm.exec(heading)[1];
var tissID = /^\s*([A-Z0-9.]{7})\s+(.*)$/gm.exec(heading)[1].replace(".", "");
var ul = document.getElementById("contentInner").getElementsByClassName("bulletList")[0];
var li = document.createElement("li");
li.innerHTML = '<a href="' + vowi_link(tissID) + '" target="_blank">' + (locale == "de" ? "Zum" : "To") + ' VoWi</a>';
ul.appendChild(li);
li = document.createElement("li");
li.innerHTML = '<a href="' + mm_link(lvaTitle) + '" target="_blank">' + (locale == "de" ? "Zum" : "To") + ' Mattermost-Channel</a>';
ul.appendChild(li);
}
// favorites page: add VoWi link icon
if (page == "education/favorites") {
// Creating the node once and cloning it is noticeably faster than modifying the original
// image element in place and overwriting the src attribute with the base64 string.
var tuwelTemplate = document.createElement("img");
tuwelTemplate.src = `
data:image/png;base64,
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAACjppQ0NQ
UGhvdG9zaG9wIElDQyBwcm9maWxlAABIiZ2Wd1RU1xaHz713eqHNMBQpQ++9DSC9N6nSRGGYGWAo
Aw4zNLEhogIRRUQEFUGCIgaMhiKxIoqFgGDBHpAgoMRgFFFReTOyVnTl5b2Xl98fZ31rn733PWfv
fda6AJC8/bm8dFgKgDSegB/i5UqPjIqmY/sBDPAAA8wAYLIyMwJCPcOASD4ebvRMkRP4IgiAN3fE
KwA3jbyD6HTw/0malcEXiNIEidiCzclkibhQxKnZggyxfUbE1PgUMcMoMfNFBxSxvJgTF9nws88i
O4u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1
AAAAIGNIUk0AAHomAACAhAAA+gAAAIDoAAB1MAAA6mAAADqYAAAXcJy6UTwAAAAGYktHRAD/AP8A
/6C9p5MAAAAJcEhZcwAACxMAAAsTAQCanBgAAAAHdElNRQfjCg4JCyLPLg++AAABNElEQVQ4y83S
vUpcURQF4M9xVKzsJAYRgp0QjEHyGJIHMAQR7kHtLIR0WkvEn8Z7FIuApskbWFhbCiKIjRAQQUzQ
QkR0xiJHHYeZW8TGBRsOe++z9t/ihWiR5a3owTv0YQif8B4lTIhhq4hgELvoKCh0h0EciKFaGyiJ
YQ+dmC4gaMU+9mR5x/MOHpDl0/iAE7zFbwzgcwPCTTGMQjl9/orvDRJPsZQKTWBGDIuyfPshodw+
uTZ2c1vZaNL6Gwwn+4HV5D+S5b0YLt3cVtaT8yO666wLh2nB42K4luX9+IZfuCilU8EslpMtiOFM
DJdoq+tqTAwX2BLDTrkmMFKX+KXJWOuyfAHzT0v8hzn8Te9K04PGcFx78lqCFTGc/4+UqwXxP/iJ
KVSf6eZRicW4aii6V4V7L7JLkeDanNUAAAAASUVORK5CYII=
`;
tuwelTemplate.alt = "TUWEL";
tuwelTemplate.title = "TUWEL";
tuwelTemplate.style = "margin-right: 5px";
var dlTemplate = document.createElement("img");
dlTemplate.src = `
data:image/png;base64,
iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAYAAABWzo5XAAAABmJLR0QA/wD/AP+gvaeTAAAACXBI
WXMAAC4jAAAuIwF4pT92AAABXUlEQVQ4y+2Tv0tCURzFP+/1VEoypCHCSAeJECGMpppaJHFpF6Kx
SWgQ+gcCh4aamiUborEIJCKMIIrAUpFCLLUfDipiIijos0HUTIJKh4bOdO/l8Ll8z7lXwHlQowcS
6ZH+HkhqLFwmLSpRIJgqYhxWcZosECi1x+cyaVGKMuvhfAdIaISddVvRKCT2jiM4bGYq1QpX4Tgr
u3eEynVz1m1lUFFGuervmEX6uKlRwhdKU6mFmbOMMTtlxKMSmd6O/DSjKjtPRZZ9ceY3L8gUy1gm
9SzphN+H/VyqEnvJAX3MGIa6a02W62GLotgdSDeiASCayn+//laPAouj/TjtE4xr1SRTKbaiVRDa
rzdI9YOCXCMrfwIJqPHa9DhsZgBe01nWPLdtEAE13gVD03N0HsS+n2yB/NcJBiSRUCLP4dk9wccM
Gzc5cnIL0vQk85xcPgAQiL21P8j/3/+l3gFrvHeTUEQuDAAAAABJRU5ErkJggg==
`;
dlTemplate.alt = "Distance Learning";
dlTemplate.style = "vertical-align: bottom";
Array.from(document.querySelectorAll("tr.ui-widget-content")).forEach(function(row, index) {
var titleCol = row.getElementsByClassName("favoritesTitleCol")[0];
var lvaTitle = titleCol.getElementsByTagName("a")[0].text.trim();
var tissID = titleCol.querySelector("span[title='LVA Nr.'],span[title='Course Nr.']").textContent.replace(".", "");
var a = document.createElement("a");
a.href = mm_link(lvaTitle);
a.target = "_blank";
var img = document.createElement("img");
img.src = "https://mattermost.fsinf.at/static/images/favicon/favicon-32x32.png";
img.title = "Mattermost";
img.alt = "Mattermost";
img.width = 16;
img.height = 16;
img.style = "margin-right: 5px";
a.appendChild(img);
var favoritesLinks = row.getElementsByClassName("favoritesLinks")[0];
favoritesLinks.insertBefore(a, favoritesLinks.childNodes[0]);
a = document.createElement("a");
a.href = vowi_link(tissID);
a.target = "_blank";
img = document.createElement("img");
img.src = "https://vowi.fsinf.at/favicon.ico";
img.title = "VoWi";
img.alt = "VoWi";
img.width = 16;
img.height = 16;
img.style = "margin-right: 5px";
a.appendChild(img);
favoritesLinks = row.getElementsByClassName("favoritesLinks")[0];
favoritesLinks.insertBefore(a, favoritesLinks.childNodes[0]);
favoritesLinks.style = "width: 120px !important";
var tuwel = row.querySelector("img[title='TUWEL']");
if (tuwel !== null) {
tuwel.parentElement.target = "_blank";
tuwel.replaceWith(tuwelTemplate.cloneNode(false));
}
var dl = row.querySelector("img[alt='Distance Learning']");
if (dl !== null) {
dl.replaceWith(dlTemplate.cloneNode(false));
}
});
}