
    document.addEventListener('DOMContentLoaded', function() {
        // Проверка URL страницы
        console.log('-- Запуск скриптов для карточки пользователя 1.2 --');
        const url = new URL(window.location.href);
        if (!url.pathname.includes('/user/control/user/update/id/')) {
            return; // Прекращаем выполнение скрипта, если URL не содержит нужный путь
        }
 console.log('-- Это карточка пользователя --');
        // Извлечение user id из URL
        const userId = url.pathname.split('/').pop();

        // Функция для добавления кнопок
        function addButtons() {
            const inputField = document.getElementById('field-input-10324949');
            if (!inputField) {
                // Если поле не найдено, повторяем проверку через 5 секунд
                setTimeout(addButtons, 5000);
                return;
            }

            // Создание контейнера для кнопок
            const buttonContainer = document.createElement('div');
            buttonContainer.style.display = 'flex';
            buttonContainer.style.gap = '5px';
            buttonContainer.style.marginTop = '10px';

            // Массив с информацией о кнопках
            const buttons = [
                { label: '→ ЭКС', color: 'red', level: 1 },
                { label: '→ АП', color: 'green', level: 2 },
                { label: '→ ПО', color: 'blue', level: 3 },
                { label: '→ ТЧ', color: 'purple', level: 4 },
            ];

            // Функция обработки клика
            function handleButtonClick(event) {
                const level = event.target.getAttribute('data-level');
                const uid = event.target.getAttribute('data-uid');
                console.log(`Button clicked: Level = ${level}, UID = ${uid}`);
                // Здесь вы можете добавить дополнительную логику обработки
            }

            // Создание и добавление кнопок в контейнер
            buttons.forEach(buttonInfo => {
                const button = document.createElement('button');
                button.textContent = buttonInfo.label;
                button.style.backgroundColor = buttonInfo.color;
                button.style.border = 'none';
                button.style.color = 'white';
                button.style.padding = '5px 10px';
                button.style.cursor = 'pointer';
                button.setAttribute('data-level', buttonInfo.level);
                button.setAttribute('data-uid', userId);
                button.onclick = handleButtonClick;
                buttonContainer.appendChild(button);
            });

            // Добавление контейнера с кнопками после инпута
            const fieldInputBlock = inputField.parentElement;
            fieldInputBlock.appendChild(buttonContainer);

            // Проверка значения в поле и изменение текста метки
            const fieldLabel = document.querySelector('label[for="field-input-10324949"] .label-value');
            const fieldValue = parseInt(inputField.value, 10);

            if (!isNaN(fieldValue) && fieldValue >= 1 && fieldValue <= 4) {
                const buttonInfo = buttons.find(button => button.level === fieldValue);
                if (buttonInfo) {
                    const additionalText = ` (${buttonInfo.label})`;
                    fieldLabel.textContent += additionalText;
                    fieldLabel.style.color = buttonInfo.color;
                }
            }
        }

        // Начальная попытка добавить кнопки
        addButtons();
    });
