From b962853b6973e583d4af13cfe25500e4757e9923 Mon Sep 17 00:00:00 2001 From: Eduard Prigoana Date: Thu, 26 Mar 2026 20:36:42 +0200 Subject: [PATCH] weights --- js/storage.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/js/storage.js b/js/storage.js index f4884a2..570f1cc 100644 --- a/js/storage.js +++ b/js/storage.js @@ -58,8 +58,8 @@ export const apiSettings = { let data = null; let fetchError = null; - // Shuffle URLs to pick a random one first - const urls = [...this.INSTANCES_URLS].sort(() => Math.random() - 0.5); + // Prefer first URL, only try others as fallback + const urls = [...this.INSTANCES_URLS]; for (const url of urls) { try { @@ -200,12 +200,26 @@ export const apiSettings = { return array; }; + const prioritySort = (array) => { + const getUrl = (item) => (typeof item === 'string' ? item : item.url || ''); + const top = []; + const middle = []; + const bottom = []; + for (const item of array) { + const url = getUrl(item); + if (url.includes('hifi.geeked.wtf')) top.push(item); + else if (url.includes('.qqdl.site')) bottom.push(item); + else middle.push(item); + } + return [...top, ...shuffle(middle), ...shuffle(bottom)]; + }; + if (instances.api && instances.api.length) { - instances.api = shuffle([...instances.api]); + instances.api = prioritySort([...instances.api]); } if (instances.streaming && instances.streaming.length) { - instances.streaming = shuffle([...instances.streaming]); + instances.streaming = prioritySort([...instances.streaming]); } this.saveInstances(instances);