mirror of
https://github.com/zyqunix/tools.git
synced 2025-07-06 06:20:30 +02:00
badge api
This commit is contained in:
parent
11ef9ce07e
commit
f193f1e86c
4 changed files with 51 additions and 3 deletions
29
assets/js/badgesapi.js
Normal file
29
assets/js/badgesapi.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
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);
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue