Skip to content

Commit f7fe836

Browse files
committed
Fix discord widget
1 parent b2b68af commit f7fe836

3 files changed

Lines changed: 47 additions & 16 deletions

File tree

src/_style-vars.scss

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
--text-color: white;
88
--scrollbar-color: #302235;
99
--code-background: #130d15;
10-
11-
--discord-dnd: hsl(358.16 calc(1*68.776%)53.529% /1);
12-
--discord-idle: hsl(37.792 calc(1*78.571%)38.431% /1);
13-
--discord-online: hsl(142.703 calc(1*60.656%)35.882% /1);
1410
}
1511

1612
* {

src/pages/index.html

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,13 @@ <h2>Downloads</h2>
9898
<i>You can find the engine source by going to the <i class="fa fa-github"></i> <a href="https://github.com/CodenameCrew/CodenameEngine">Engine&nbsp;repository</a></i>
9999
</div>
100100
</div>
101-
101+
102102
<div class="discordWidget">
103103
<div class="discordWidget-header">
104104
<h2 style="text-align: center; margin: 0; transform: translateY(50%);">Discord Server</h2>
105105
</div>
106106
<div class="discordWidget-content">
107107
<span>Members online</span>
108-
<div class="discordWidget-user">
109-
<img style="margin-right: 8px;"; src=""/>
110-
<span></span>
111-
</div>
112108
</div>
113109
<div class="discordWidget-footer">
114110
<span>Want to chat?</span>
@@ -218,15 +214,23 @@ <h3>{{ safeish name }}</h3>
218214
<script>
219215
const widgetContent = document.querySelector(".discordWidget-content");
220216
const widgetFooter = document.querySelector(".discordWidget-footer");
221-
const userTemplate = document.querySelector(".discordWidget-user");
222-
userTemplate.remove();
223217
fetch("https://discord.com/api/guilds/860561967383445535/widget.json").then(response => response.json()).then(data => {
224218
widgetFooter.querySelector("a").href = data.instant_invite;
225219
for (const member of data.members) {
226-
const user = userTemplate.cloneNode(true);
227-
user.querySelector("img").src = member.avatar_url + "?size=16";
228-
user.querySelector("span").innerText = member.username;
229-
user.querySelector("img").style.border = "solid var(--discord-" + member.status + ") 2px";
220+
const user = document.createElement("div");
221+
user.classList.add("discordWidget-user");
222+
223+
const avatar = document.createElement("img");
224+
avatar.classList.add("avatar");
225+
avatar.src = member.avatar_url + "?size=16";
226+
avatar.setAttribute("data-status", member.status);
227+
user.appendChild(avatar);
228+
229+
const username = document.createElement("span");
230+
username.classList.add("username");
231+
username.innerText = member.username;
232+
user.appendChild(username);
233+
230234
widgetContent.appendChild(user);
231235
}
232236
})
@@ -237,7 +241,7 @@ <h3>{{ safeish name }}</h3>
237241
if (main && discord) {
238242
discord.style.height = `${main.offsetHeight}px`;
239243
const mainStyles = window.getComputedStyle(main);
240-
discord.style.marginTop = mainStyles.marginTop;
244+
discord.style.marginTop = mainStyles.marginTop;
241245
}
242246
}
243247

src/pages/index.scss

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,36 @@
11
@use "sass:color";
22

3+
:root {
4+
--discord-dnd: hsl(358.16 calc(1*68.776%)53.529% /1);
5+
--discord-idle: hsl(37.792 calc(1*78.571%)38.431% /1);
6+
--discord-online: hsl(142.703 calc(1*60.656%)35.882% /1);
7+
}
8+
9+
.discordWidget-user {
10+
//.username {
11+
// text-overflow: ellipsis;
12+
// white-space: nowrap;
13+
// overflow: hidden;
14+
//}
15+
16+
.avatar {
17+
margin-right: 8px;
18+
border: solid white 2px;
19+
20+
&[data-status="online"] {
21+
border-color: var(--discord-online);
22+
}
23+
24+
&[data-status="idle"] {
25+
border-color: var(--discord-idle);
26+
}
27+
28+
&[data-status="dnd"] {
29+
border-color: var(--discord-dnd);
30+
}
31+
}
32+
}
33+
334
.content {
435
margin: 0;
536
padding: 0!important;

0 commit comments

Comments
 (0)