From 866ddf9a1a04c0b5a19fc3799bc637d9ee37a876 Mon Sep 17 00:00:00 2001 From: Bonchellon Date: Tue, 27 Jan 2026 23:05:14 +0300 Subject: [PATCH] 123 --- public/game.js | 62 ++++++++++++++++++++++++++++++++++++++--------- public/index.html | 14 +++++++++-- 2 files changed, 63 insertions(+), 13 deletions(-) diff --git a/public/game.js b/public/game.js index 2e36e37..5501344 100644 --- a/public/game.js +++ b/public/game.js @@ -285,9 +285,17 @@ const badge = document.createElement('div'); badge.id = 'spectator-badge'; badge.style.cssText = 'position: fixed; top: 1rem; right: 1rem; background: rgba(212,168,75,0.9); color: #000; padding: 0.5rem 1rem; border-radius: 8px; font-weight: 700; z-index: 200; display: flex; align-items: center; gap: 0.5rem;'; - badge.innerHTML = 'НАБЛЮДАТЕЛЬ'; - document.body.appendChild(badge); - if (typeof lucide !== 'undefined') lucide.createIcons(); + badge.innerHTML = 'НАБЛЮДАТЕЛЬ'; + document.body.appendChild(badge); + if (typeof lucide !== 'undefined') { + setTimeout(() => { + try { + lucide.createIcons(); + } catch (e) { + console.warn('Error updating Lucide icons:', e); + } + }, 50); + } } } else { const spectatorBadge = $('spectator-badge'); @@ -371,7 +379,13 @@ // Обновляем иконки Lucide после рендеринга if (typeof lucide !== 'undefined') { - setTimeout(() => lucide.createIcons(), 100); + setTimeout(() => { + try { + lucide.createIcons(); + } catch (e) { + console.warn('Error updating Lucide icons:', e); + } + }, 100); } } @@ -2200,7 +2214,13 @@ // Обновляем иконки Lucide после создания кнопок if (typeof lucide !== 'undefined') { - setTimeout(() => lucide.createIcons(), 100); + setTimeout(() => { + try { + lucide.createIcons(); + } catch (e) { + console.warn('Error updating Lucide icons:', e); + } + }, 100); } }; $('btn-instructions')?.addEventListener('click', () => { @@ -2786,16 +2806,36 @@ // Инициализация Lucide Icons после загрузки DOM if (typeof lucide !== 'undefined') { lucide.createIcons(); - // Обновляем иконки при изменении DOM - const observer = new MutationObserver(() => { - lucide.createIcons(); - }); - observer.observe(document.body, { childList: true, subtree: true }); + // Обновляем иконки при изменении DOM с debounce, чтобы избежать бесконечного цикла + if (!window.lucideObserver) { + let iconUpdateTimer = null; + window.lucideObserver = new MutationObserver(() => { + // Отменяем предыдущий таймер + if (iconUpdateTimer) clearTimeout(iconUpdateTimer); + // Устанавливаем новый таймер с задержкой + iconUpdateTimer = setTimeout(() => { + try { + lucide.createIcons(); + } catch (e) { + console.warn('Error updating Lucide icons:', e); + } + }, 200); + }); + window.lucideObserver.observe(document.body, { childList: true, subtree: true }); + } } }); } else { init(); - if (typeof lucide !== 'undefined') lucide.createIcons(); + if (typeof lucide !== 'undefined') { + setTimeout(() => { + try { + lucide.createIcons(); + } catch (e) { + console.warn('Error updating Lucide icons:', e); + } + }, 100); + } if (window.Music) { window.Music.init(); } diff --git a/public/index.html b/public/index.html index b4f0677..5617a6e 100644 --- a/public/index.html +++ b/public/index.html @@ -372,9 +372,19 @@ if (typeof lucide !== 'undefined') { document.addEventListener('DOMContentLoaded', () => { lucide.createIcons(); - // Обновляем иконки при изменении DOM + // Обновляем иконки при изменении DOM с debounce, чтобы избежать бесконечного цикла + let iconUpdateTimer = null; const observer = new MutationObserver(() => { - lucide.createIcons(); + // Отменяем предыдущий таймер + if (iconUpdateTimer) clearTimeout(iconUpdateTimer); + // Устанавливаем новый таймер с задержкой + iconUpdateTimer = setTimeout(() => { + try { + lucide.createIcons(); + } catch (e) { + console.warn('Error updating Lucide icons:', e); + } + }, 200); }); observer.observe(document.body, { childList: true, subtree: true }); });