diff options
| -rw-r--r-- | cockpit/js/cockpit.js | 9 | ||||
| -rw-r--r-- | cockpit/js/config.js | 10 | ||||
| -rw-r--r-- | cockpit/js/student-common.js | 4 |
3 files changed, 16 insertions, 7 deletions
diff --git a/cockpit/js/cockpit.js b/cockpit/js/cockpit.js index f701706..30fc2a0 100644 --- a/cockpit/js/cockpit.js +++ b/cockpit/js/cockpit.js @@ -197,7 +197,14 @@ async function fetchAndUpdateStudentInfo() { } function updateStudentInfo() { - document.getElementById("student-info-icon").src = student.getIconUrl(); + // Try to replace the generic icon with the user's icon + var img = document.createElement('img'); + img.onload = function() { + document.getElementById("student-info-icon").src = img.src; + img = img.onload = null; + }; + student.getIconUrl().then( (url) => img.src = url ); + document.getElementById("student-info-name").innerHTML = `${student.name}`; if (student.graduation) { diff --git a/cockpit/js/config.js b/cockpit/js/config.js index 6ec5831..94dbfc2 100644 --- a/cockpit/js/config.js +++ b/cockpit/js/config.js @@ -22,14 +22,16 @@ function getCourseId() { return courseId; } -function getUserIconUrl(userId) { - return `https://lernplattform.bycs.de/pluginfile.php/${userId}/user/icon`; -} - function getCourseParticipantsUrl() { return `https://lernplattform.bycs.de/user/index.php?id=${courseId}`; } +async function getUserIconUrl(userId) { + const userRes = await fetch(`https://lernplattform.bycs.de/user/profile.php?id=${userId}`) + const userDoc = new DOMParser().parseFromString(await userRes.text(), 'text/html') + return userDoc.querySelector(".userpicture").src; +} + export { GRADUATION_DB, GRADUATION_DB_PARAMS_MAP, getCourseId, diff --git a/cockpit/js/student-common.js b/cockpit/js/student-common.js index 74cc845..3938380 100644 --- a/cockpit/js/student-common.js +++ b/cockpit/js/student-common.js @@ -9,8 +9,8 @@ class Student { this.group = group; } - getIconUrl() { - return getUserIconUrl(this.id); + async getIconUrl() { + return await getUserIconUrl(this.id); } } |
