mirror of
https://github.com/deadcxap/bs-overlay.git
synced 2026-07-02 05:43:39 +03:00
Add files via upload
fix download beatleader data
This commit is contained in:
+50
-16
@@ -566,8 +566,20 @@
|
|||||||
let reconnectTimeout = null;
|
let reconnectTimeout = null;
|
||||||
let debugTimeout = null;
|
let debugTimeout = null;
|
||||||
let duration = 0;
|
let duration = 0;
|
||||||
|
|
||||||
|
// Переменные для BeatLeader
|
||||||
let lastBlFetch = 0;
|
let lastBlFetch = 0;
|
||||||
let blFailCount = 0;
|
let isFetchingBL = false;
|
||||||
|
let currentProxyIdx = 0;
|
||||||
|
|
||||||
|
// Массив прокси (первый элемент пустой - попытка загрузки напрямую, т.к. API BL поддерживает CORS)
|
||||||
|
const proxies = [
|
||||||
|
"",
|
||||||
|
"https://api.codetabs.com/v1/proxy?quest=",
|
||||||
|
"https://api.allorigins.win/raw?url=",
|
||||||
|
"https://corsproxy.io/?",
|
||||||
|
"https://thingproxy.freeboard.io/fetch/"
|
||||||
|
];
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
els.app.style.display = 'none';
|
els.app.style.display = 'none';
|
||||||
@@ -578,6 +590,9 @@
|
|||||||
applyGlow();
|
applyGlow();
|
||||||
connectWS();
|
connectWS();
|
||||||
|
|
||||||
|
// Фоновое обновление профиля каждые 15 минут
|
||||||
|
setInterval(() => fetchBL(), 900000);
|
||||||
|
|
||||||
document.addEventListener('keydown', (e) => {
|
document.addEventListener('keydown', (e) => {
|
||||||
if (e.key === 'F2') els.settings.classList.toggle('show');
|
if (e.key === 'F2') els.settings.classList.toggle('show');
|
||||||
});
|
});
|
||||||
@@ -793,19 +808,28 @@
|
|||||||
|
|
||||||
async function fetchBL(force = false) {
|
async function fetchBL(force = false) {
|
||||||
if (!config.blId || !config.showBL) return;
|
if (!config.blId || !config.showBL) return;
|
||||||
|
if (isFetchingBL) return;
|
||||||
if (!force && Date.now() - lastBlFetch < 900000) return;
|
if (!force && Date.now() - lastBlFetch < 900000) return;
|
||||||
|
|
||||||
try {
|
isFetchingBL = true;
|
||||||
const isNumeric = /^\d+$/.test(config.blId);
|
|
||||||
let originalUrl;
|
|
||||||
if (isNumeric) {
|
|
||||||
originalUrl = `https://api.beatleader.xyz/player/${config.blId}?stats=true`;
|
|
||||||
} else {
|
|
||||||
originalUrl = `https://api.beatleader.xyz/players?search=${encodeURIComponent(config.blId)}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const proxiedUrl = `https://api.codetabs.com/v1/proxy?quest=${encodeURIComponent(originalUrl)}`;
|
const isNumeric = /^\d+$/.test(config.blId);
|
||||||
const res = await fetch(proxiedUrl, { headers: { 'Accept': 'application/json' } });
|
const originalUrl = isNumeric
|
||||||
|
? `https://api.beatleader.com/player/${config.blId}?stats=true`
|
||||||
|
: `https://api.beatleader.com/players?search=${encodeURIComponent(config.blId)}`;
|
||||||
|
|
||||||
|
let success = false;
|
||||||
|
let attempts = 0;
|
||||||
|
const maxAttempts = 5;
|
||||||
|
|
||||||
|
while (!success && attempts < maxAttempts) {
|
||||||
|
try {
|
||||||
|
const proxy = proxies[currentProxyIdx % proxies.length];
|
||||||
|
const targetUrl = proxy ? proxy + encodeURIComponent(originalUrl) : originalUrl;
|
||||||
|
|
||||||
|
showDebug(`BL Fetch [${attempts + 1}/${maxAttempts}] via ${proxy ? 'Proxy' : 'Direct'}`);
|
||||||
|
|
||||||
|
const res = await fetch(targetUrl, { headers: { 'Accept': 'application/json' } });
|
||||||
|
|
||||||
if (!res.ok) throw new Error(`Network error: ${res.status}`);
|
if (!res.ok) throw new Error(`Network error: ${res.status}`);
|
||||||
|
|
||||||
@@ -827,15 +851,25 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
lastBlFetch = Date.now();
|
lastBlFetch = Date.now();
|
||||||
blFailCount = 0;
|
success = true;
|
||||||
|
showDebug(`BL Profile Loaded Successfully!`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
blFailCount++;
|
attempts++;
|
||||||
if (blFailCount >= 5) {
|
currentProxyIdx++; // Пробуем следующий прокси
|
||||||
showDebug(`BL Error: ${err.message} (${blFailCount} fails)`);
|
showDebug(`BL Error: ${err.message}. Retrying...`);
|
||||||
|
|
||||||
|
if (attempts < maxAttempts) {
|
||||||
|
await new Promise(r => setTimeout(r, 2000)); // Задержка 2 сек перед следующей попыткой
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!success) {
|
||||||
els.blName.textContent = "Error loading profile";
|
els.blName.textContent = "Error loading profile";
|
||||||
console.error("BeatLeader fetch failed:", err);
|
showDebug(`BL Fetch failed completely after ${maxAttempts} attempts.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isFetchingBL = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function connectWS() {
|
function connectWS() {
|
||||||
|
|||||||
Reference in New Issue
Block a user