From a4ac19e5168071ffba642fa1f4d6c67c3b0b5b6b Mon Sep 17 00:00:00 2001 From: Zhora Shalyapin Date: Wed, 26 Mar 2025 08:36:27 +0000 Subject: [PATCH] use same request for receiving point by number --- main.js | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/main.js b/main.js index abfb105..6c47802 100644 --- a/main.js +++ b/main.js @@ -312,8 +312,12 @@ }) } - async function getPointIdByNumber(number) { - let response = await fetch(`https://${adminSite}/api/competitions/${getCompetition()}/${number}`, { + async function getPointIdByNumber(numbers) { + let params = new URLSearchParams() + for (const number of numbers) { + params.append("number[]", number) + } + let response = await fetch(`https://${adminSite}/api/competitions/${getCompetition()}/points?${params.toString()}`, { method: 'GET' }) return await response.json() @@ -1171,8 +1175,8 @@ on: { click: async function () { let number = document.querySelector("#go-to-cp").value - let json = await getPointIdByNumber(number) - let id = json.id + let json = await getPointIdByNumber([number]) + let id = json[number].cp_id if (id == null) { alert("Нет КП с таким номером") @@ -2192,21 +2196,28 @@ function addLinksToCp() { let pointCells = [...document.querySelectorAll(`#props table td:first-child`)] - for (const pointCell of pointCells) { - let cellContent = pointCell.textContent - let pointNumber = cellContent.trim().match(/^\d+/) - if (pointNumber == null) continue + let pointNumbers = {} + for (const [i, pointCell] of pointCells.entries()) { + let pointNumber = pointCell.textContent.trim().match(/^\d+/)?.[0] + if (pointNumber != null) + pointNumbers[i] = pointNumber + } - ;(async () => { - let cpId = (await getPointIdByNumber(pointNumber)).id + ;(async () => { + let cpIds = await getPointIdByNumber(Object.values(pointNumbers)) + + for (const [i, pointCell] of pointCells.entries()) { + if (pointNumbers[i] == null) continue + + let cellContent = pointCell.textContent pointCell.innerHTML = '' pointCell.append(Tag.a({ - href: cpLink(cpId), + href: cpLink(cpIds[pointNumbers[i]].cp_id), target: "_blank", textContent: cellContent })) - })() - } + } + })() } function getRouteName() {