From 4b4990b123aab2e9bdf21285e919d3c54bedcd03 Mon Sep 17 00:00:00 2001 From: Zhora Shalyapin Date: Fri, 28 Mar 2025 12:47:01 +0000 Subject: [PATCH] add cp name to options on stages page --- main.js | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/main.js b/main.js index be0d356..574ad2c 100644 --- a/main.js +++ b/main.js @@ -312,10 +312,10 @@ }) } - async function getPointsByNumber(numbers) { + async function getPointsByField(field, values) { let params = new URLSearchParams() - for (const number of numbers) { - params.append("number[]", number) + for (const value of values) { + params.append(`${field}[]`, value) } let response = await fetch(`https://${adminSite}/api/competitions/${getCompetition()}/points?${params.toString()}`, { method: 'GET' @@ -1164,7 +1164,7 @@ on: { click: async function () { let number = document.querySelector("#go-to-cp").value - let json = await getPointsByNumber([number]) + let json = await getPointsByField("number", [number]) let id = json[number].cp_id if (id == null) { @@ -2153,7 +2153,7 @@ } async function getPointsFromRows() { - return await getPointsByNumber(Object.values(getPointNumbers())) + return await getPointsByField("number", Object.values(getPointNumbers())) } function countCp(points) { @@ -2210,7 +2210,7 @@ fullNeedHistoryCount++ stageNeedHistoryCount++ } - + if (point.history_ru) { fullHistoryCount++ stageHistoryCount++ @@ -2469,6 +2469,26 @@ addStylesToHead(styles) } + function addCpNameToOptions() { + let options = [...document.querySelectorAll(`option`)] + let cpIds = [...new Set( + options + .map($option => $option.value) + .filter($value => $value != null) + ) + ] + + ;(async () => { + let points = await getPointsByField("cp_id", cpIds) + + for (const option of options) { + if (option.value != null && points[option.value] != null) { + option.innerText = option.innerText + " - " + points[option.value].name_int + } + } + })() + } + function addCommonStyles() { addStylesToHead(` #content h1 { @@ -2636,6 +2656,7 @@ if (isRouteStagesPage()) { hideUselessRowsFromRouteStagesPage() + addCpNameToOptions() } }