Skip to content

Commit

Permalink
v0.3.1 for BeatLeader API Rate Limiting
Browse files Browse the repository at this point in the history
  • Loading branch information
hatopopvr committed Sep 18, 2023
1 parent 308a1f6 commit 1273507
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions scoresaber-enhanced-bl-replays.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
// ==UserScript==
// @name ScoreSaber Enhanced BL Replays (Modified by hatopopvr)
// @namespace hatopopvr
// @version 0.3.0
// @version 0.3.1
// @description ScoreSaber Enhancements with additional features (Based on version 0.4 of the original script)
// @author hatopopvr (Original author: motzel)
// @icon https://scoresaber.com/favicon-32x32.png
Expand Down Expand Up @@ -433,6 +433,10 @@
return playerId + hash + difficulty + modifiedScore + mode;
}

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}

/**
* This function is aimed to retrieve the score data including ReplayId from the BeatLeader API.
* Note: This script has a known issue with CORS (Cross-Origin Resource Sharing) policy,
Expand Down Expand Up @@ -460,8 +464,10 @@
let beatLeaderScoreData = GM_getValue(key);

if (!beatLeaderScoreData) {
const url = `https://api.beatleader.xyz/player/${playerId}/scores?sortBy=date&page=1&count=5000&search=${hash}&diff=${difficulty}&mode=${mode}`;
console.log(url);
await sleep(1000); // Adding sleep to handle API Rate Limiting
// const url = `https://api.beatleader.xyz/player/${playerId}/scores?sortBy=date&page=1&count=5000&search=${hash}&diff=${difficulty}&mode=${mode}`;
const url = `https://api.beatleader.xyz/player/${playerId}/scores?sortBy=date&page=1&count=1&search=${hash}&diff=${difficulty}&mode=${mode}`;
console.log(url);
const response = await fetch(url);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
Expand Down

0 comments on commit 1273507

Please sign in to comment.