1
// ==UserScript==
2
// @name LABYnet all badges
3
// @namespace Violentmonkey Scripts
4
// @match https://laby.net/badges
5
// @grant none
6
// @version 1.0.0
7
// @author Erb3
8
// @description 17/11/2023, 21:42:51
9
// ==/UserScript==
10
11
function log(...args) {
12
console.log(`USERSCRIPT : ${GM_info.script.name}:`, ...args)
13
}
14
15
function insertAfter(referenceNode, newNode) {
16
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
17
}
18
19
function removeAllAfter(element) {
20
let parent = element.parentNode;
21
let children = Array.from(parent.childNodes);
22
let pos = children.indexOf(element);
23
for(let i = children.length - 1; i > pos; i--) {
24
parent.removeChild(children[i]);
25
}
26
}
27
28
const endpoint = "https://laby.net/api/badges";
29
30
function generateCard(url, title, uuid, users) {
31
const container = document.createElement("div");
32
const link = document.createElement("a");
33
const name = document.createElement("h6");
34
const picture = document.createElement("picture");
35
const webp = document.createElement("source");
36
const png = document.createElement("source");
37
const img = document.createElement("img");
38
const amountContainer = document.createElement("span");
39
const amount = document.createTextNode(users);
40
const userIcon = document.createElement("i");
41
container.classList.add("col-4", "col-md-2", "texture-item");
42
link.href = url;
43
name.innerHTML = title;
44
webp.type = "image/webp";
45
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`;
46
png.type = "image/png";
47
png.srcset = `/texture/badge-1x/${uuid} 50w, /texture/badge-2x/${uuid} 100w, /texture/badge-3x/${uuid} 150w, /texture/badge-4x/${uuid} 200w`
48
img.src = `https://laby.net/texture/badge-3x/${uuid}`;
49
img.classList.add("texture", "img-fluid", "ln-shadow");
50
img.width = 50;
51
img.height = 50;
52
amountContainer.classList.add("badge", "bg-dark", "mt-3");
53
userIcon.classList.add("icon", "icon-user");
54
55
amountContainer.appendChild(amount);
56
amountContainer.appendChild(userIcon);
57
picture.appendChild(webp);
58
picture.appendChild(png);
59
picture.appendChild(img);
60
link.appendChild(name);
61
link.appendChild(picture);
62
link.appendChild(amountContainer);
63
container.appendChild(link);
64
return container;
65
}
66
67
async function getBadges() {
68
const res = await fetch(endpoint);
69
const data = await res.json();
70
console.log("Userscript: Found badges", data);
71
return data;
72
}
73
74
setTimeout(async () => {
75
const labyTitle = document.querySelector("h2.mt-5:nth-child(20)")
76
removeAllAfter(labyTitle)
77
const badges = await getBadges()
78
badges.forEach((badge) => {
79
const card = generateCard(
80
`https://laby.net/badge/${badge.uuid}`,
81
badge.name,
82
badge.uuid,
83
""
84
);
85
insertAfter(labyTitle, card)
86
})
87
}, 500);
88
89