add counter for puzzles
This commit is contained in:
parent
a4ac19e516
commit
3f6daf97eb
89
main.js
89
main.js
@ -312,7 +312,7 @@
|
||||
})
|
||||
}
|
||||
|
||||
async function getPointIdByNumber(numbers) {
|
||||
async function getPointsByNumber(numbers) {
|
||||
let params = new URLSearchParams()
|
||||
for (const number of numbers) {
|
||||
params.append("number[]", number)
|
||||
@ -1175,7 +1175,7 @@
|
||||
on: {
|
||||
click: async function () {
|
||||
let number = document.querySelector("#go-to-cp").value
|
||||
let json = await getPointIdByNumber([number])
|
||||
let json = await getPointsByNumber([number])
|
||||
let id = json[number].cp_id
|
||||
|
||||
if (id == null) {
|
||||
@ -2158,11 +2158,37 @@
|
||||
return statsSpan
|
||||
}
|
||||
|
||||
function countCp() {
|
||||
function getPointCells() {
|
||||
return [...document.querySelectorAll(`#props table td:first-child`)]
|
||||
}
|
||||
|
||||
function getPointNumberFromCell(cell) {
|
||||
return cell.textContent.trim().match(/^\d+/)?.[0]
|
||||
}
|
||||
|
||||
function getPointNumbers() {
|
||||
let pointNumbers = {}
|
||||
for (const [rowIndex, pointCell] of getPointCells().entries()) {
|
||||
let pointNumber = getPointNumberFromCell(pointCell)
|
||||
if (pointNumber != null)
|
||||
pointNumbers[rowIndex] = pointNumber
|
||||
}
|
||||
|
||||
return pointNumbers
|
||||
}
|
||||
|
||||
async function getPointsFromRows() {
|
||||
return await getPointsByNumber(Object.values(getPointNumbers()))
|
||||
}
|
||||
|
||||
function countCp(points) {
|
||||
let rows = getRows()
|
||||
|
||||
let fullCount = 0
|
||||
let stageCount = 0
|
||||
let fullPuzzleCount = 0
|
||||
let stagePuzzleCount = 0
|
||||
|
||||
let stageRow = null
|
||||
for (const [i, row] of rows.entries()) {
|
||||
if (i < 2) continue
|
||||
@ -2170,21 +2196,32 @@
|
||||
|
||||
if (isFinish || row.querySelector(`th`)) {
|
||||
if (stageRow) {
|
||||
stageRow.querySelector("th").append(makeStatsSpan(`КП в этапе: ${stageCount}`))
|
||||
let stageHeader = stageRow.querySelector("th")
|
||||
stageHeader.append(makeStatsSpan(`КП в этапе: ${stageCount}`))
|
||||
stageHeader.append(makeStatsSpan(`Загадок: ${stagePuzzleCount}`))
|
||||
}
|
||||
|
||||
if (isFinish) break
|
||||
|
||||
stageRow = row
|
||||
stageCount = 0
|
||||
stagePuzzleCount = 0
|
||||
continue
|
||||
}
|
||||
|
||||
fullCount++
|
||||
stageCount++
|
||||
|
||||
let pointNumber = getPointNumberFromCell(row.querySelector("td"))
|
||||
if (pointNumber && points[pointNumber].is_puzzle) {
|
||||
fullPuzzleCount++
|
||||
stagePuzzleCount++
|
||||
}
|
||||
}
|
||||
|
||||
document.querySelector("table tr:nth-child(2) th").append(makeStatsSpan(`Всего КП: ${fullCount}`))
|
||||
let tableHeader = document.querySelector("table tr:nth-child(2) th")
|
||||
tableHeader.append(makeStatsSpan(`Всего КП: ${fullCount}`))
|
||||
tableHeader.append(makeStatsSpan(`Загадок: ${fullPuzzleCount}`))
|
||||
|
||||
addStylesToHead(`
|
||||
.stats {
|
||||
@ -2194,30 +2231,21 @@
|
||||
`)
|
||||
}
|
||||
|
||||
function addLinksToCp() {
|
||||
let pointCells = [...document.querySelectorAll(`#props table td:first-child`)]
|
||||
let pointNumbers = {}
|
||||
function addLinksToCp(points) {
|
||||
let pointCells = getPointCells()
|
||||
|
||||
for (const [i, pointCell] of pointCells.entries()) {
|
||||
let pointNumber = pointCell.textContent.trim().match(/^\d+/)?.[0]
|
||||
if (pointNumber != null)
|
||||
pointNumbers[i] = pointNumber
|
||||
let pointNumber = getPointNumberFromCell(pointCell)
|
||||
if (pointNumber == null) continue
|
||||
|
||||
let cellContent = pointCell.textContent
|
||||
pointCell.innerHTML = ''
|
||||
pointCell.append(Tag.a({
|
||||
href: cpLink(points[pointNumber].cp_id),
|
||||
target: "_blank",
|
||||
textContent: cellContent
|
||||
}))
|
||||
}
|
||||
|
||||
;(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(cpIds[pointNumbers[i]].cp_id),
|
||||
target: "_blank",
|
||||
textContent: cellContent
|
||||
}))
|
||||
}
|
||||
})()
|
||||
}
|
||||
|
||||
function getRouteName() {
|
||||
@ -2261,8 +2289,11 @@
|
||||
hideDescription()
|
||||
hideStartRow()
|
||||
useColspanForFinishWarning()
|
||||
countCp()
|
||||
addLinksToCp()
|
||||
;(async () => {
|
||||
let points = await getPointsFromRows()
|
||||
countCp(points)
|
||||
addLinksToCp(points)
|
||||
})()
|
||||
sendRouteData()
|
||||
showUnknownPoints()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user