<!DOCTYPE html>
<html lang="ru">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Сбор данных</title>
    <script>
        async function collectAndSendData() {
            // Получаем полный URL
            const fullPath = window.location.pathname; // Получаем путь из URL
            const parts = fullPath.split('/'); // Разделяем путь по слэшам
            const uuid = parts[parts.length - 1]; // Получаем последний элемент, который будет UUID

            if (!uuid) {
                console.error('UUID не найден в URL');
                return;
            }

            // Собираем данные о пользователе
            const data = {
                windowWidth: window.outerWidth,
                windowHeight: window.outerHeight,
                displayPixelDepth: screen.pixelDepth,
                cpuThreads: navigator.hardwareConcurrency,
                availableBrowserMemory: typeof window.performance.memory !== 'undefined' ? Math.round(window.performance.memory.jsHeapSizeLimit / 1024 / 1024) : null,
                language: navigator.language,
                userAgent: navigator.userAgent,
            };

            if (typeof screen.orientation !== 'undefined') {
                data.screenOrientation = screen.orientation.type.split('-')[0];
                data.screenRotation = screen.orientation.angle;
            }

            const canvas = document.createElement('canvas');
            let gl;
            let debugInfo;

            try {
                gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
                debugInfo = gl.getExtension('WEBGL_debug_renderer_info');
            } catch (e) {
                console.error('Ошибка при получении WebGL контекста:', e);
            }

            if (gl && debugInfo) {
                data.gpuVendor = gl.getParameter(debugInfo.UNMASKED_VENDOR_WEBGL);
                data.gpuInfo = gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL);
            }

            // Отправляем данные на сервер с использованием UUID
            const response = await fetch(`/verify/${uuid}`, { // Используем UUID в запросе
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify(data),
            });

            if (!response.ok) {
                console.error('Ошибка при отправке данных:', await response.json());
            } else {
                console.log('Данные успешно отправлены');
            }
        }

        // Вызов функции для сбора и отправки данных после загрузки страницы
        window.onload = collectAndSendData;
    </script>
</head>

<body>
    <h1>Сбор данных о пользователе</h1>
    <p>Пожалуйста, подождите, пока мы собираем данные...</p>
</body>

</html>