fix script failing to load on page load
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m19s
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m19s
This commit is contained in:
parent
4cd6c27b2b
commit
2b8b135cf8
@ -7,12 +7,13 @@
|
||||
// @match https://scoresaber.com/*
|
||||
// @icon https://www.google.com/s2/favicons?sz=64&domain=scoresaber.com
|
||||
// @license MIT
|
||||
// @run-at document-end
|
||||
// @updateURL https://git.fascinated.cc/Fascinated/ScoreSaberUtils-Backend/raw/branch/master/scoresaber-utils.user.js
|
||||
// @downloadURL https://git.fascinated.cc/Fascinated/ScoreSaberUtils-Backend/raw/branch/master/scoresaber-utils.user.js
|
||||
// @grant none
|
||||
// @run-at document-end
|
||||
// ==/UserScript==
|
||||
|
||||
let loaded = false;
|
||||
|
||||
/**
|
||||
* Fetches the player from ScoreSaber Utils.
|
||||
*
|
||||
@ -28,6 +29,7 @@ async function fetchPlayer(id) {
|
||||
* Handles the player page logic.
|
||||
*/
|
||||
async function playerPage() {
|
||||
console.log("Player page loaded!");
|
||||
const id = window.location.pathname.split("/")[2];
|
||||
const player = await fetchPlayer(id);
|
||||
|
||||
@ -59,13 +61,27 @@ function addStat(stat, value, hoverText) {
|
||||
statsElement.appendChild(statElement);
|
||||
}
|
||||
|
||||
(function async() {
|
||||
function sleep(ms) {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
async function load() {
|
||||
"use strict";
|
||||
if (loaded) return;
|
||||
|
||||
const path = window.location.pathname;
|
||||
const isPlayerPage = path.startsWith("/u/");
|
||||
|
||||
if (isPlayerPage) {
|
||||
// Wait for the stats container to load
|
||||
while (document.getElementsByClassName("stats-container").length === 0) {
|
||||
await sleep(250);
|
||||
}
|
||||
|
||||
playerPage();
|
||||
}
|
||||
})();
|
||||
|
||||
loaded = true;
|
||||
}
|
||||
|
||||
load();
|
||||
|
Loading…
Reference in New Issue
Block a user