// ========================================================= // Kronic UI fixes - 2026-10-31 // ========================================================= window.Kronick = window.Kronick || {}; /* * Flash only the top chat icon when a new chat notification * arrives while chat is not visibly open. */ (function setupChatNotificationFlash() { const chatButton = document.getElementById( 'chatToolButton' ); const chatWrap = document.getElementById( 'chatFrameWrap' ); const chatFrame = document.getElementById( 'chatFrame' ); if (!chatButton) { return; } function chatIsVisible() { if (!chatWrap) { return false; } const style = window.getComputedStyle( chatWrap ); return ( style.display !== 'none' && style.visibility !== 'hidden' && !chatWrap.classList.contains( 'window-minimized' ) ); } function clearChatFlash() { chatButton.classList.remove( 'chat-notification-pulse' ); } function flashChatIcon() { if ( !chatIsVisible() ) { chatButton.classList.add( 'chat-notification-pulse' ); } } chatButton.addEventListener( 'click', clearChatFlash ); window.addEventListener( 'message', event => { if ( event.origin !== Kronick.config?.APP_ORIGIN && event.origin !== window.location.origin ) { return; } if ( chatFrame?.contentWindow && event.source !== chatFrame.contentWindow ) { return; } if ( event.data?.type === 'KRONICK_CHAT_NEW_MESSAGE' ) { flashChatIcon(); } } ); /* * Existing chat-controller code may maintain the unread * badge. Observe it too, but display only the icon pulse. */ const unread = document.getElementById( 'chatUnreadCount' ); if (unread) { const observer = new MutationObserver( () => { const count = Number( unread.dataset.count || unread.textContent || 0 ); if ( count > 0 && !chatIsVisible() ) { flashChatIcon(); } } ); observer.observe( unread, { attributes: true, childList: true, characterData: true, subtree: true } ); } /* * If another part of the app opens the chat window, * clear the pulse as soon as it becomes visible. */ if (chatWrap) { const observer = new MutationObserver( () => { if ( chatIsVisible() ) { clearChatFlash(); } } ); observer.observe( chatWrap, { attributes: true, attributeFilter: [ 'style', 'class' ] } ); } })();