summaryrefslogtreecommitdiff
path: root/scripts/common/current-user.js
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/common/current-user.js')
-rw-r--r--scripts/common/current-user.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/scripts/common/current-user.js b/scripts/common/current-user.js
new file mode 100644
index 0000000..9e29927
--- /dev/null
+++ b/scripts/common/current-user.js
@@ -0,0 +1,34 @@
+var User = {};
+
+/**
+ * Handles
+ * @param {ProgressEvent} event
+ * @this {XMLHttpRequest}
+ */
+function update_user_data (event) {
+ let result = JSON.parse(this.responseText);
+
+ if (this.status >= 400)
+ return;
+
+ User = result;
+
+ // Grab and change user links to point at user orofile, link text to username
+ /** @type {HTMLLinkElement} */
+ let link = document.getElementById("user-link");
+ /** @type {HTMLImageElement} */
+ let profile_icon = document.getElementById("user-profile");
+
+ link.href = "/user/"
+ profile_icon.parentElement.href = "/user/"
+ link.innerText = "Go To Profile"
+}
+
+// Run at start, grab user information and replace the login link as well as the user object
+(() => {
+ let user_req = new XMLHttpRequest();
+ user_req.addEventListener("load", update_user_data);
+ user_req.open("GET", API_BASE_URL + "/user");
+ user_req.send();
+})();
+