From ea8d540ba2170dff3dcb7f12d5e1d57a7007e382 Mon Sep 17 00:00:00 2001 From: Sibyl Date: Sun, 24 Jul 2022 13:34:03 +0300 Subject: [PATCH] keep track of global ranking --- src/utils.ts | 3 +++ src/views/Mutuals.vue | 59 ++++++++++++++++--------------------------- 2 files changed, 25 insertions(+), 37 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index a827c33..84844f3 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -348,5 +348,8 @@ export const jsonCountries: WebCountry[] = [ { flag_url: "1f1f3-1f1fa.svg", code: "NU", name: "Niue" }, { flag_url: "1f1f5-1f1f3.svg", code: "PN", name: "Pitcairn" }, { flag_url: "1f1e8-1f1eb.svg", code: "CF", name: "Central African Republic" }, + + // GLOBAL RANKING TO KEEP TRACK OF WHERE THE PROGRAM IS LEFT + { flag_url: "global.svg", code: "GLOBAL", name: "Global" }, ] diff --git a/src/views/Mutuals.vue b/src/views/Mutuals.vue index 323c34e..79ecf3d 100644 --- a/src/views/Mutuals.vue +++ b/src/views/Mutuals.vue @@ -40,8 +40,10 @@ const randomNumber = (): number => { } const threads: Threads = {} -const getUserElements = async (page: number, country?: string): Promise => { - const response = await http.fetch(`https://osu.ppy.sh/rankings/${gamemode.value}/performance?page=${page}${country ? `&country=${country}` : ''}`, { +const getUserElements = async (page: number, country: string): Promise => { + let countryParam = country == "GLOBAL" ? "" : `&country=${country}`; + + const response = await http.fetch(`https://osu.ppy.sh/rankings/${gamemode.value}/performance?page=${page}${countryParam}`, { method: "GET", responseType: 2 }) @@ -84,50 +86,33 @@ const add = async (element: Element) => { } } -const startCheck = async (id: number, country?: string) => { - let limit = { - countryCode: "?", - start: 1, - end: 200, - index: 0 - } +const startCheck = async (id: number, country: string) => { + let limit = settingsStore.getLimit(country) || { countryCode: country, end: 200, start: 1, index: 0 }; - if (country) { - let countryLimit = settingsStore.getLimit(country); - if (countryLimit) { - limit = countryLimit; - } - } - for (let page = limit.start; page <= limit.end; page++) { currentPage.value = page; - let slice_index = country ? settingsStore.getLimit(country)?.index : limit.index; - let elements = (await getUserElements(page, country)).slice(slice_index); + let elements = (await getUserElements(page, country)).slice(limit.index); for (const [index, element] of elements.entries()) { if (!threads[id]) return; await add(element); - if (country) { - settingsStore.updateLimit({ - countryCode: country, - start: page, - end: limit.end, - index - }); - } - } - - if (country) { settingsStore.updateLimit({ - countryCode: country, + countryCode: limit.countryCode, start: page, end: limit.end, - index: 0 - }) + index + }); } + settingsStore.updateLimit({ + countryCode: country, + start: page, + end: limit.end, + index: 0 + }) + // page change sleep. Just in case. await sleep(2000); } @@ -135,7 +120,7 @@ const startCheck = async (id: number, country?: string) => { const start = async (id: number) => { if (check.value == Check.Global) { - await startCheck(id); + await startCheck(id, "GLOBAL"); } else { for (let country of countries.value) { await startCheck(id, country); @@ -149,10 +134,10 @@ onDeactivated(() => { console.log("deactivated"); }); onActivated(() => { - if (import.meta.env.DEV) { - checked.value = [10440852]; - return - }; + // if (import.meta.env.DEV) { + // checked.value = [10440852]; + // return + // }; // Disable all threads for (const item in threads) {