Add JS to get Discord Username/Avatar on page load

This commit is contained in:
Aadi Desai 2023-09-08 00:33:00 +01:00
parent 4a85e20e38
commit 1d19db3876
Signed by: supleed2
SSH key fingerprint: SHA256:CkbNRs0yVzXEiUp2zd0PSxsfRUMFF9bLlKXtE1xEbKM

View file

@ -15,9 +15,24 @@
<link rel="icon" type="image/png" href="/favicon.ico"> <link rel="icon" type="image/png" href="/favicon.ico">
<title>IC Anime Society</title> <title>IC Anime Society</title>
<!--Script to set [[discordID]]-->
<script>
async function setDiscordID() {
const id = new URLSearchParams(window.location.search).get("id");
if (id == null) {
window.location.replace("/");
} else {
const { username, avatar_url } = await fetch(`/discord?id=${id}`).then((r) => r.json()).catch(console.error);
// const { username, avatar_url } = { username: `User #${id}`, avatar_url: "https://cdn.discordapp.com/embed/avatars/0.png" };
document.getElementById("discordID").value = id;
document.getElementById("discord-username").innerText = username;
document.getElementById("discord-avatar").src = avatar_url;
}
}
</script>
</head> </head>
<body> <body onload="setDiscordID()">
<!-- Navbar --> <!-- Navbar -->
<nav class="navbar navbar-inverse navbar-fixed-top"> <nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container"> <div class="container">