Last active
September 30, 2024 14:07
-
-
Save Erb3/fee619dd75b53a683f75b5c293aaf7be to your computer and use it in GitHub Desktop.
Shows all the badges on LABYnet instead of only some! To install click the `Raw` button on the file below.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name LABYnet all badges | |
// @namespace Erb3 | |
// @match https://laby.net/badges | |
// @grant none | |
// @version 1.0.3 | |
// @author Erb3 | |
// @downloadURL https://gist.githubusercontent.com/Erb3/fee619dd75b53a683f75b5c293aaf7be/raw/LABYnet-all-badges.user.js | |
// @supportURL https://gist.githubusercontent.com/Erb3/fee619dd75b53a683f75b5c293aaf7be/raw/LABYnet-all-badges.user.js | |
// @homepageURL https://gist.githubusercontent.com/Erb3/fee619dd75b53a683f75b5c293aaf7be/raw/LABYnet-all-badges.user.js | |
// @description Shows all the badges on LABYnet instead of only some! | |
// ==/UserScript== | |
const badgesEndpoint = "https://laby.net/api/badges"; | |
const badgeEndpoint = "https://laby.net/api/badge/"; | |
function generateCard(url, title, uuid, users) { | |
const container = document.createElement("div"); | |
const link = document.createElement("a"); | |
const name = document.createElement("h6"); | |
const picture = document.createElement("picture"); | |
const webp = document.createElement("source"); | |
const png = document.createElement("source"); | |
const img = document.createElement("img"); | |
const amountContainer = document.createElement("span"); | |
const amount = document.createTextNode(users); | |
const userIcon = document.createElement("i"); | |
container.classList.add("col-4", "col-md-3", "custom-col-lg-5", "texture-item", "text-center"); | |
link.href = url; | |
name.innerHTML = title; | |
webp.type = "image/webp"; | |
webp.srcset = `/texture/badge-1x/${uuid}.webp 50w, /texture/badge-2x/${uuid}.webp 100w, /texture/badge-3x/${uuid}.webp 150w, /texture/badge-4x/${uuid}.webp 200w`; | |
png.type = "image/png"; | |
png.srcset = `/texture/badge-1x/${uuid} 50w, /texture/badge-2x/${uuid} 100w, /texture/badge-3x/${uuid} 150w, /texture/badge-4x/${uuid} 200w` | |
img.src = `https://laby.net/texture/badge-3x/${uuid}`; | |
img.classList.add("texture", "img-fluid", "ln-shadow"); | |
img.width = 50; | |
img.height = 50; | |
amountContainer.classList.add("badge", "bg-dark", "mt-3"); | |
userIcon.classList.add("icon", "icon-user"); | |
amountContainer.appendChild(amount); | |
amountContainer.appendChild(userIcon); | |
picture.appendChild(webp); | |
picture.appendChild(png); | |
picture.appendChild(img); | |
link.appendChild(name); | |
link.appendChild(picture); | |
link.appendChild(amountContainer); | |
container.appendChild(link); | |
return container; | |
} | |
async function getBadges() { | |
const res = await fetch(badgesEndpoint); | |
return await res.json(); | |
} | |
async function getBadgeUsers(uuid) { | |
const res = await fetch(badgeEndpoint + uuid); | |
return (await res.json()).length; | |
} | |
setTimeout(async () => { | |
const badgesContainer = document.querySelector(".texture-container"); | |
document.querySelectorAll(".texture-container > h2").forEach((v) => v.remove()); | |
const title = document.createElement("h1"); | |
title.innerHTML = "MISC"; | |
title.classList.add("mb-2"); | |
badgesContainer.appendChild(title); | |
const badgeContainer = document.createElement("div"); | |
badgeContainer.classList.add("col-12", "row"); | |
const badges = await getBadges() | |
badges.forEach(async (badge) => { | |
if (badgesContainer.innerHTML.includes(badge.uuid)) return; | |
const users = await getBadgeUsers(badge.id) | |
const card = generateCard(`https://laby.net/badge/${badge.uuid}`, badge.name, badge.uuid, users); | |
badgeContainer.appendChild(card); | |
}); | |
badgesContainer.appendChild(badgeContainer); | |
}, 500); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment