Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
The code downloads active users from the api and adds it to the page
$(window).on("action:ajaxify.end", () => {
"use strict";
if (ajaxify.data.template.name === "categories") {
try {
/**
* @param {String} discordApi Api to ur server
* Ex. https://discordapp.com/api/guilds/xxxxxxx/widget.json
*/
const discordApi = "https://discordapp.com/api/guilds/xxxxxxx/widget.json";
const fragmentDiscord = document.createDocumentFragment();
const discordContainer = document.querySelector("#active-users-discord");
const sectionContainer = discordContainer.querySelector("#discord-section");
const linkContainer = discordContainer.querySelector("#link-to-discord");
fetch(discordApi)
.then(response => response.json())
.then(({ instant_invite, name, members }) => {
linkContainer.textContent = `Connect to ${name}`;
linkContainer.setAttribute("href", instant_invite);
members.forEach(({ username, discriminator, status, avatar_url }) => {
status === "idle" ? status = "away" : null;
const discordSpan = document.createElement("span");
const discordI = document.createElement("i");
const discordImage = document.createElement("img");
discordSpan.className = "discord-user";
discordSpan.id = `${username}#${discriminator}`;
discordI.className = `fa fa-fw fa-circle status ${status}`;
discordImage.src = avatar_url;
discordImage.className = "avatar avatar-sm avatar-rounded";
discordImage.title = `${username}#${discriminator}`;
discordSpan.appendChild(discordI);
discordSpan.appendChild(discordImage);
fragmentDiscord.appendChild(discordSpan);
});
sectionContainer.appendChild(fragmentDiscord);
app.createUserTooltips();
});
} catch (e) {}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.