починил цвета

This commit is contained in:
2026-01-29 14:50:57 +03:00
parent 31fccd85f2
commit c348019bf5
3 changed files with 243 additions and 94 deletions
+53 -64
View File
@@ -295,6 +295,8 @@ QString HttpServerChat::generateHTML()
" opacity: 1;\n"
" max-width: 100%;\n"
" word-wrap: break-word;\n"
" padding: 5px 10px;\n"
" box-sizing: border-box;\n"
"}\n"
".message-icon { \n"
" width: 1.5em; \n"
@@ -308,31 +310,23 @@ QString HttpServerChat::generateHTML()
"let fetching = false;\n"
"const deleteByTime = %3;\n"
"\n"
"function hexToRgb(hex) {\n"
" console.log('hexToRgb input:', hex);\n"
" \n"
" // Создаем временный canvas элемент для парсинга цвета\n"
" const ctx = document.createElement('canvas').getContext('2d');\n"
" ctx.fillStyle = hex;\n"
" const color = ctx.fillStyle;\n"
" \n"
" // Если цвет не распознан, используем значение по умолчанию\n"
" if (!color || color === 'rgba(0, 0, 0, 0)') {\n"
" console.log('Color not recognized, using default');\n"
" return '74, 175, 80'; // #4CAF50\n"
" }\n"
" \n"
" // Парсим цвет в формате rgb(r, g, b)\n"
" const match = color.match(/rgb\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*\\)/);\n"
" \n"
" if (match) {\n"
" console.log('Parsed RGB:', match[1], match[2], match[3]);\n"
" return `${match[1]}, ${match[2]}, ${match[3]}`;\n"
" }\n"
" \n"
" console.log('Failed to parse, using default');\n"
" return '74, 175, 80'; // #4CAF50\n"
"}\n"
"function hexToRgba(hex, alpha) {\n"
" // Убираем # если есть\n"
" hex = hex.replace('#', '');\n"
" \n"
" // Расширяем короткую форму (#RGB -> #RRGGBB)\n"
" if (hex.length === 3) {\n"
" hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];\n"
" }\n"
" \n"
" // Конвертируем HEX в RGB\n"
" const r = parseInt(hex.substring(0, 2), 16);\n"
" const g = parseInt(hex.substring(2, 4), 16);\n"
" const b = parseInt(hex.substring(4, 6), 16);\n"
" \n"
" // Возвращаем RGBA строку\n"
" return `rgba(${r}, ${g}, ${b}, ${alpha})`;\n"
"}\n"
"\n"
"function fetchMessages() {\n"
" if (fetching) return;\n"
@@ -351,10 +345,8 @@ QString HttpServerChat::generateHTML()
" });\n"
" \n"
" // 2. УДАЛЯЕМ ТОЛЬКО ТЕ СООБЩЕНИЯ, КОТОРЫХ НЕТ В НОВЫХ ДАННЫХ\n"
" // И КОТОРЫЕ НЕ ЗАМОРОЖЕНЫ\n"
" existingMessages.forEach((div, msgId) => {\n"
" if (!newIds.has(msgId)) {\n"
" // Проверяем, заморожено ли сообщение\n"
" const isFreez = div.getAttribute('data-freez') === 'true';\n"
" if (!isFreez) {\n"
" div.style.opacity = '0';\n"
@@ -378,37 +370,36 @@ QString HttpServerChat::generateHTML()
" div.id = msgId;\n"
" div.setAttribute('data-freez', msg.freez ? 'true' : 'false');\n"
" \n"
" // ПРИМЕНЯЕМ СТИЛИ\n"
" function hexToRgb(hex) {\n"
" console.log('hexToRgb input:', hex);\n"
" if (!hex || !hex.startsWith('#')) {\n"
" console.log('Not a hex color, using default');\n"
" return '74, 175, 80'; // #4CAF50\n"
" }\n"
" // Убираем # и проверяем длину\n"
" let cleanHex = hex.substring(1);\n"
" // Убираем альфа-канал если есть\n"
" if (cleanHex.length === 8) {\n"
" cleanHex = cleanHex.substring(0, 6);\n"
" }\n"
" // Расширяем короткую форму (#rgb → #rrggbb)\n"
" if (cleanHex.length === 3) {\n"
" cleanHex = cleanHex[0] + cleanHex[0] + \n"
" cleanHex[1] + cleanHex[1] + \n"
" cleanHex[2] + cleanHex[2];\n"
" }\n"
" // Проверяем, что строка состоит из шестнадцатеричных символов\n"
" if (cleanHex.length !== 6 || !/^[0-9A-Fa-f]{6}$/.test(cleanHex)) {\n"
" console.log('Invalid hex format, using default');\n"
" return '74, 175, 80'; // #4CAF50\n"
" }\n"
" // Конвертируем HEX в RGB\n"
" const r = parseInt(cleanHex.substring(0, 2), 16);\n"
" const g = parseInt(cleanHex.substring(2, 4), 16);\n"
" const b = parseInt(cleanHex.substring(4, 6), 16);\n"
" console.log('Parsed RGB:', r, g, b);\n"
" return `${r}, ${g}, ${b}`;\n"
" }\n"
" // ПРИМЕНЯЕМ СТИЛИ С ПРОЗРАЧНОСТЬЮ\n"
" const alpha = msg.transparency / 255;\n"
" \n"
" // Цвет фона блока с прозрачностью\n"
" if (msg.color) {\n"
" div.style.backgroundColor = hexToRgba(msg.color, alpha);\n"
" }\n"
" \n"
" // Граница с прозрачностью\n"
" if (msg.borderColor && msg.borderSize > 0) {\n"
" div.style.border = msg.borderSize + 'px solid ' + hexToRgba(msg.borderColor, alpha);\n"
" } else {\n"
" div.style.border = 'none';\n"
" }\n"
" \n"
" // Внутренние отступы\n"
" if (msg.padding > 0) {\n"
" div.style.padding = msg.padding + 'px';\n"
" }\n"
" \n"
" // Шрифт\n"
" if (msg.family) {\n"
" div.style.fontFamily = msg.family;\n"
" }\n"
" if (msg.fontSize > 0) {\n"
" div.style.fontSize = msg.fontSize + 'px';\n"
" }\n"
" if (msg.fontColor) {\n"
" div.style.color = msg.fontColor;\n"
" }\n"
" \n"
" // ФОРМИРУЕМ СОДЕРЖИМОЕ\n"
" let content = '<span><b>' + msg.nickname + ':</b> ' + msg.content + '</span>';\n"
@@ -418,10 +409,8 @@ QString HttpServerChat::generateHTML()
" container.appendChild(div);\n"
" existingMessages.set(msgId, div);\n"
" \n"
" // 4. УСТАНАВЛИВАЕМ ТАЙМЕР УДАЛЕНИЯ ТОЛЬКО ЕСЛИ:\n"
" // - включено удаление по времени (deleteByTime)\n"
" // - сообщение НЕ заморожено (freez = false)\n"
" if (deleteByTime && (!msg.freez || msg.freez === false)) {\n"
" // 4. УСТАНАВЛИВАЕМ ТАЙМЕР УДАЛЕНИЯ\n"
" if (deleteByTime && !msg.freez) {\n"
" setTimeout(() => {\n"
" if (existingMessages.has(msgId)) {\n"
" const messageDiv = existingMessages.get(msgId);\n"
@@ -433,14 +422,14 @@ QString HttpServerChat::generateHTML()
" existingMessages.delete(msgId);\n"
" }, 500);\n"
" }\n"
" }, (parseInt(msg.timeMsg) || 10) * 1000);\n"
" }, (msg.timeMsg || 10) * 1000);\n"
" }\n"
" }\n"
" });\n"
" \n"
" // 5. ОБРАБОТКА РЕЖИМА УДАЛЕНИЯ ПО КОЛИЧЕСТВУ\n"
" if (!deleteByTime) {\n"
" const maxMessages = 100;\n"
" const maxMessages = msg.maxCount || 100;\n"
" if (existingMessages.size > maxMessages) {\n"
" const messagesArray = Array.from(existingMessages.entries());\n"
" messagesArray.sort((a, b) => {\n"