Compare commits
No commits in common. "5ad5d7181f5b139314171a7a0a99b315941da952" and "784330b5a61ee50b4bc37642c312377588807bce" have entirely different histories.
5ad5d7181f
...
784330b5a6
2 changed files with 10 additions and 63 deletions
|
@ -76,7 +76,6 @@ These can be defined in Lanyard's KV store to customize the page:
|
||||||
| `badges` | Enables badge fetching (`true` / `false`) |
|
| `badges` | Enables badge fetching (`true` / `false`) |
|
||||||
| `readme` | URL to a README displayed on the profile (`.md` or `.html`) |
|
| `readme` | URL to a README displayed on the profile (`.md` or `.html`) |
|
||||||
| `css` | URL to a css to change styles on the page, no import or require allowed |
|
| `css` | URL to a css to change styles on the page, no import or require allowed |
|
||||||
| `optout` | Allows users to stop sharing there profile on the website (`true` / `false`) |
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
@ -335,10 +335,9 @@ async function loadBadges(userId, options = {}) {
|
||||||
|
|
||||||
async function populateReadme(data) {
|
async function populateReadme(data) {
|
||||||
const readmeSection = document.querySelector(".readme");
|
const readmeSection = document.querySelector(".readme");
|
||||||
const kv = data.kv || {};
|
|
||||||
|
|
||||||
if (readmeSection && kv.readme) {
|
if (readmeSection && data.kv?.readme) {
|
||||||
const url = kv.readme;
|
const url = data.kv.readme;
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`/api/readme?url=${encodeURIComponent(url)}`);
|
const res = await fetch(`/api/readme?url=${encodeURIComponent(url)}`);
|
||||||
if (!res.ok) throw new Error("Failed to fetch readme");
|
if (!res.ok) throw new Error("Failed to fetch readme");
|
||||||
|
@ -356,46 +355,8 @@ async function populateReadme(data) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updatePresence(initialData) {
|
async function updatePresence(data) {
|
||||||
if (
|
const cssLink = data.kv?.css;
|
||||||
!initialData ||
|
|
||||||
typeof initialData !== "object" ||
|
|
||||||
initialData.success === false ||
|
|
||||||
initialData.error
|
|
||||||
) {
|
|
||||||
const loadingOverlay = document.getElementById("loading-overlay");
|
|
||||||
if (loadingOverlay) {
|
|
||||||
loadingOverlay.innerHTML = `
|
|
||||||
<div class="error-message">
|
|
||||||
<p>${initialData?.error?.message || "Failed to load presence data."}</p>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
loadingOverlay.style.opacity = "1";
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const data =
|
|
||||||
initialData?.d && Object.keys(initialData.d).length > 0
|
|
||||||
? initialData.d
|
|
||||||
: initialData;
|
|
||||||
|
|
||||||
const kv = data.kv || {};
|
|
||||||
|
|
||||||
if (kv.optout === "true") {
|
|
||||||
const loadingOverlay = document.getElementById("loading-overlay");
|
|
||||||
if (loadingOverlay) {
|
|
||||||
loadingOverlay.innerHTML = `
|
|
||||||
<div class="error-message">
|
|
||||||
<p>This user has opted out of sharing their presence.</p>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
loadingOverlay.style.opacity = "1";
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const cssLink = kv.css;
|
|
||||||
if (cssLink) {
|
if (cssLink) {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`/api/css?url=${encodeURIComponent(cssLink)}`);
|
const res = await fetch(`/api/css?url=${encodeURIComponent(cssLink)}`);
|
||||||
|
@ -410,7 +371,7 @@ async function updatePresence(initialData) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!badgesLoaded && data?.kv && data.kv.badges !== "false") {
|
if (!badgesLoaded && data && data.kv.badges !== "false") {
|
||||||
loadBadges(userId, {
|
loadBadges(userId, {
|
||||||
services: [],
|
services: [],
|
||||||
seperated: true,
|
seperated: true,
|
||||||
|
@ -554,9 +515,9 @@ async function updatePresence(initialData) {
|
||||||
getAllNoAsset();
|
getAllNoAsset();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kv.snow === "true") loadEffectScript("snow");
|
if (data.kv?.snow === "true") loadEffectScript("snow");
|
||||||
if (kv.rain === "true") loadEffectScript("rain");
|
if (data.kv?.rain === "true") loadEffectScript("rain");
|
||||||
if (kv.stars === "true") loadEffectScript("stars");
|
if (data.kv?.stars === "true") loadEffectScript("stars");
|
||||||
|
|
||||||
const loadingOverlay = document.getElementById("loading-overlay");
|
const loadingOverlay = document.getElementById("loading-overlay");
|
||||||
if (loadingOverlay) {
|
if (loadingOverlay) {
|
||||||
|
@ -682,19 +643,6 @@ if (userId && instanceUri) {
|
||||||
socket.addEventListener("message", (event) => {
|
socket.addEventListener("message", (event) => {
|
||||||
const payload = JSON.parse(event.data);
|
const payload = JSON.parse(event.data);
|
||||||
|
|
||||||
if (payload.error || payload.success === false) {
|
|
||||||
const loadingOverlay = document.getElementById("loading-overlay");
|
|
||||||
if (loadingOverlay) {
|
|
||||||
loadingOverlay.innerHTML = `
|
|
||||||
<div class="error-message">
|
|
||||||
<p>${payload.error?.message || "An unknown error occurred."}</p>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
loadingOverlay.style.opacity = "1";
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (payload.op === 1 && payload.d?.heartbeat_interval) {
|
if (payload.op === 1 && payload.d?.heartbeat_interval) {
|
||||||
heartbeatInterval = setInterval(() => {
|
heartbeatInterval = setInterval(() => {
|
||||||
socket.send(JSON.stringify({ op: 3 }));
|
socket.send(JSON.stringify({ op: 3 }));
|
||||||
|
@ -711,8 +659,8 @@ if (userId && instanceUri) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (payload.t === "INIT_STATE" || payload.t === "PRESENCE_UPDATE") {
|
if (payload.t === "INIT_STATE" || payload.t === "PRESENCE_UPDATE") {
|
||||||
updatePresence(payload);
|
updatePresence(payload.d);
|
||||||
requestAnimationFrame(updateElapsedAndProgress);
|
requestAnimationFrame(() => updateElapsedAndProgress());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue