mirror of
https://github.com/zyqunix/tools.git
synced 2025-07-05 14:00:31 +02:00
29 lines
861 B
JavaScript
29 lines
861 B
JavaScript
import { user } from "./index.js";
|
|
const apiUrl = "https://badges.atums.world";
|
|
|
|
|
|
export async function getBadges(user) {
|
|
const response = await fetch(`${apiUrl}/${user}`);
|
|
if (!response.ok) throw new Error(`Error fetching reviews: ${response.status} ${response.statusText}`);
|
|
const data = await response.json();
|
|
return data;
|
|
}
|
|
|
|
export async function populateBadges(element) {
|
|
const target = document.querySelector(element);
|
|
const data = await getBadges(user);
|
|
|
|
target.innerHTML = "";
|
|
|
|
data.badges.forEach(badge => {
|
|
const badgeEl = document.createElement("div");
|
|
const badgeImg = document.createElement("img");
|
|
badgeImg.src = badge.badge;
|
|
badgeEl.classList.add("tooltip");
|
|
badgeEl.setAttribute("data-tooltip", badge.tooltip);
|
|
badgeImg.style.width = "32px";
|
|
|
|
badgeEl.appendChild(badgeImg);
|
|
target.appendChild(badgeEl);
|
|
})
|
|
}
|