Skip to content
This repository was archived by the owner on Dec 15, 2023. It is now read-only.

Commit a5ec7d0

Browse files
committed
added RAP to user profile
1 parent 22c7ef8 commit a5ec7d0

1 file changed

Lines changed: 37 additions & 1 deletion

File tree

userscript/src/index.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ async function getRank(groupId, playerId) {
2121
return dom.getElementsByTagName("Value")[0].textContent;
2222
}
2323

24+
async function getCollectibles(playerId) {
25+
// https://www.syntax.eco/public-api/v1/inventory/collectibles/id
26+
const url = `https://www.syntax.eco/public-api/v1/inventory/collectibles/${playerId}`;
27+
const response = await fetch(url);
28+
const json = await response.json();
29+
// check for "assets" in the json
30+
if ("data" in json) {
31+
return json["data"]
32+
} else {
33+
return [];
34+
}
35+
}
36+
2437
async function main() {
2538
// Find <body/>. This can be any element. We wait until
2639
// the page has loaded enough for that element to exist.
@@ -80,7 +93,30 @@ async function main() {
8093
logo.style = "height: 40px; width: 40px;";
8194
nameholder.insertBefore(logo, userelement.nextSibling);
8295
}
83-
// now check if the player is
96+
// User Recent Average Price sum of collectibles
97+
var rap = 0;
98+
const collectibles = await getCollectibles(userid);
99+
for (const collectible of collectibles) {
100+
rap += Number(collectible["asset"]["asset_rap"] || 0);
101+
}
102+
// get /html/body/div[2]/div/div[1]/div[1]/div[2]/div[2]
103+
const statbox = document.evaluate("/html/body/div[2]/div/div[1]/div[1]/div[2]/div[2]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
104+
const holder = document.createElement("div");
105+
holder.style = "width: fit-content;";
106+
holder.className = "me-3"
107+
const title = document.createElement("p");
108+
title.className = "m-0 text-secondary w-100 text-center d-block";
109+
title.innerText = "User RAP";
110+
title.style = "font-size: 15px;";
111+
const rapElement = document.createElement("p");
112+
rapElement.className = "m-0 text-decoration-none text-white w-100 text-center d-block";
113+
rapElement.innerText = rap;
114+
rapElement.style = "font-size: 25px;";
115+
holder.appendChild(title);
116+
holder.appendChild(rapElement);
117+
statbox.insertBefore(holder, statbox.firstChild);
118+
119+
84120
// }
85121
}
86122
}

0 commit comments

Comments
 (0)