| () => { |
| |
| const landingPage = document.getElementById('landing-page-container'); |
| const chatbot = document.getElementById('chatbot'); |
| const msgInput = document.querySelector('#input-row textarea, #input-row input[type="text"]'); |
|
|
| if (!landingPage || !chatbot) return; |
|
|
| function toggleLanding() { |
| |
| const messages = chatbot.querySelectorAll('[data-testid="bot"], [data-testid="user"], [class*="message"]'); |
| const hasMessages = messages.length > 0; |
|
|
| |
| const emptyState = chatbot.querySelector('.empty-state, .placeholder, [class*="empty"]'); |
| const chatColumn = document.getElementById('chat-column'); |
|
|
| if (hasMessages && !emptyState) { |
| landingPage.classList.add('hidden'); |
| if (chatColumn) chatColumn.classList.remove('landing-active'); |
| } else { |
| landingPage.classList.remove('hidden'); |
| if (chatColumn) chatColumn.classList.add('landing-active'); |
| } |
| } |
|
|
| |
| toggleLanding(); |
|
|
| |
| const observer = new MutationObserver((mutations) => { |
| let shouldToggle = false; |
| for (const mutation of mutations) { |
| if (mutation.type === 'childList' || mutation.type === 'subtree') { |
| shouldToggle = true; |
| break; |
| } |
| } |
| if (shouldToggle) { |
| |
| clearTimeout(window._landingToggleTimeout); |
| window._landingToggleTimeout = setTimeout(toggleLanding, 100); |
| } |
| }); |
|
|
| observer.observe(chatbot, { |
| childList: true, |
| subtree: true, |
| attributes: true, |
| attributeFilter: ['class'] |
| }); |
|
|
| |
| const inputRow = document.getElementById('input-row'); |
| if (inputRow) { |
| observer.observe(inputRow, { |
| childList: true, |
| subtree: true |
| }); |
| } |
|
|
| |
| const landingPrompt = document.querySelector('.landing-prompt'); |
| if (landingPrompt && msgInput) { |
| landingPrompt.addEventListener('click', () => { |
| msgInput.focus(); |
| msgInput.click(); |
| }); |
| } |
|
|
| |
| window._landingPageObserver = observer; |
| window._landingPage = landingPage; |
| |
| function setVH() { |
| document.documentElement.style.setProperty( |
| '--vh', |
| `${window.innerHeight}px` |
| ); |
| } |
|
|
| setVH(); |
| |
| } |