This commit is contained in:
2026-10-23 03:02:55 +07:00
parent e2f8a3302e
commit 1ce8efeef5
21 changed files with 561 additions and 46 deletions
+24
View File
@@ -7,6 +7,8 @@ export const modeLabels: Record<ScreenMode, string> = {
6: 'Результаты',
7: 'Таймер',
8: 'Текст',
9: 'QR-код',
10: 'Список команд',
}
export function remainingTime(timer: TimerState, elapsedMs: number): number {
return Math.max(0, timer.remainingMs - (timer.status === 'running' ? Math.max(0, elapsedMs) : 0))
@@ -15,3 +17,25 @@ export function formatTimer(milliseconds: number): string {
const seconds = Math.ceil(Math.max(0, milliseconds) / 1000)
return `${String(Math.floor(seconds / 60)).padStart(2, '0')}:${String(seconds % 60).padStart(2, '0')}`
}
export const timerLabels = ['Перерыв', 'До начала игры', 'До конца игры'] as const
export function changeTimerType(label: string, previous = 0, next = 0): string {
return !label.trim() || label === timerLabels[previous] ? timerLabels[next]! : label
}
export function validQR(link: string, caption = ''): boolean {
try {
const url = new URL(link)
return (
/^https?:\/\/[^/\\\s?#]/.test(link) &&
['http:', 'https:'].includes(url.protocol) &&
!!url.hostname &&
!url.username &&
!url.password &&
link === link.trim() &&
new TextEncoder().encode(link).length <= 2048 &&
new TextEncoder().encode(caption).length <= 10000
)
} catch {
return false
}
}