diff --git a/README.md b/README.md index b44dfe4..ca49ac6 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ # ScoreSaber Beatsaver Buttons -Chrome extension that adds the one-click install, twitch !bsr, beatsaver link and download buttons to the ScoreSaber leaderboards. +Chrome extension that adds a one-click install, twitch !bsr, BeatSaver/Beatleader link, and download button to the ScoreSaber leaderboards. # How to install diff --git a/background.js b/background.js index 8cc20f5..26bd181 100644 --- a/background.js +++ b/background.js @@ -1,7 +1,7 @@ // Open a sample page where the buttons are added after installation chrome.runtime.onInstalled.addListener(function() { - chrome.tabs.create({ - url: 'https://scoresaber.com/leaderboard/371613', - }); + // chrome.tabs.create({ + // url: 'https://scoresaber.com/leaderboard/371613', + // }); }); diff --git a/demo.png b/demo.png index 65c9a08..d09cf1f 100644 Binary files a/demo.png and b/demo.png differ diff --git a/index.js b/index.js index cbff39d..310fe57 100644 --- a/index.js +++ b/index.js @@ -24,41 +24,52 @@ async function load() { // Get leaderboard id from url const leaderboardId = window.location.pathname.split('/').pop(); if (leaderboardId == null) { + log(`Failed to get leaderboard ID from URL ${window.location.pathname}`); return; } // Get leaderboardInfos from scoresaber leaderboard api const leaderboardInfos = await fetchLeaderboardInfos(leaderboardId); if (leaderboardInfos == null) { + log(`Failed to get leaderboard information from URL ${SCORESABER_LEADERBOARD_API.replace('{0}', leaderboardId)}`); return; } // Get the songHash from the leaderboardInfos - const songHash = leaderboardInfos.songHash; + const songHash = leaderboardInfos.songHash?.toLowerCase(); if (!songHash) { + log(`Couldn't find song hash in leaderboard information:`, leaderboardInfos); return; } - const beatsaverURL = BEATSAVER_API.replace('{0}', songHash); - const downloadURL = `https://eu.cdn.beatsaver.com/${songHash.toLowerCase()}.zip`; // Get the beatmap from beatsaver api - const beatmap = await fetchBeatmap(beatsaverURL); + const beatsaverURL = BEATSAVER_API.replace('{0}', songHash); + const beatleaderUIDFetchURL = `https://beatsaver.com/api/scores/${songHash}/1?difficulty=${leaderboardInfos.difficulty.difficulty}&type=BeatLeader`; // "?difficulty=9&gameMode=0&type=BeatLeader" + const [{ value: beatleader }, { value: beatmap }] = await Promise.allSettled([ + safeFetch(beatleaderUIDFetchURL), + safeFetch(beatsaverURL), + ]); if (beatmap == null) { + log(`Failed to get beatsaver data from URL:`, beatsaverURL); return; } const beatKey = beatmap.id; if (beatKey == null) { + log(`Failed to get map bsr code from beatsaver data:`, beatmap, beatsaverURL); return; } const quickInstallURL = QUICK_INSTALL_URL.replace('{0}', beatKey); const bsrCopy = `!bsr ${beatKey}`; const beatsaverPage = `https://beatsaver.com/maps/${beatKey}`; + const beatleaderLeaderboardURL = beatleader.uid ? `https://www.beatleader.xyz/leaderboard/global/${beatleader.uid}` : null; + const downloadURL = `https://eu.cdn.beatsaver.com/${songHash}.zip`; log(beatsaverURL); log(downloadURL); log(quickInstallURL); + log(beatleaderLeaderboardURL); log(bsrCopy); // Add buttons @@ -81,6 +92,19 @@ async function load() { `; const downloadButtonHTML = `