All Videos


Ask me about:

`; // Add the chat CSS const chatStyle = document.createElement('style'); chatStyle.textContent = ` /* Base Widget Styling */ .tta-chat-widget { position: fixed; bottom: 90px; right: 20px; width: 400px; height: 650px; max-height: 85vh; background-color: #ffffff; border-radius: 20px; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.16); display: none; flex-direction: column; overflow: hidden; z-index: 9998; transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; } /* Floating Chat Button */ .tta-chat-button { position: fixed; bottom: 20px; right: 20px; width: 60px; height: 60px; border-radius: 50%; background-color: ${config.theme.primary}; color: white; border: none; box-shadow: 0 6px 16px rgba(53, 80, 217, 0.3); display: flex; align-items: center; justify-content: center; cursor: pointer; z-index: 9999; transition: all 0.3s ease; animation: pulse-attention 2s infinite; } @keyframes pulse-attention { 0% { box-shadow: 0 0 0 0 rgba(53, 80, 217, 0.7); } 70% { box-shadow: 0 0 0 15px rgba(53, 80, 217, 0); } 100% { box-shadow: 0 0 0 0 rgba(53, 80, 217, 0); } } .tta-chat-button:hover { transform: scale(1.05); box-shadow: 0 8px 20px rgba(53, 80, 217, 0.4); animation: none; } .tta-chat-button:focus { outline: 3px solid rgba(53, 80, 217, 0.3); outline-offset: 2px; } .tta-chat-button svg { stroke: white; fill: none; } .tta-chat-button span { display: none; margin-left: 8px; white-space: nowrap; font-weight: 500; } @media (min-width: 768px) { .tta-chat-button { width: auto; padding: 0 24px; border-radius: 30px; } .tta-chat-button span { display: inline; } } /* Header Section */ .tta-chat-header { background-color: ${config.theme.primary}; color: ${config.theme.text.light}; padding: 20px 24px; display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 1px solid rgba(255, 255, 255, 0.1); } .tta-header-content h3 { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: 0.2px; } .tta-header-content p { margin: 6px 0 0; font-size: 14px; opacity: 0.9; font-weight: 400; } .tta-chat-controls { display: flex; gap: 12px; margin-top: 2px; } .tta-chat-controls button { background: rgba(255, 255, 255, 0.15); border: none; color: white; width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: background 0.2s, transform 0.2s; } .tta-chat-controls button:hover { background: rgba(255, 255, 255, 0.3); transform: scale(1.05); } .tta-chat-controls button:focus { outline: 2px solid rgba(255, 255, 255, 0.5); outline-offset: 2px; } /* Login Banner Style */ .tta-login-banner { background-color: #FFF8E1; /* Light yellow background */ color: #C05621; /* Darker yellow text */ padding: 12px 24px; text-align: center; font-size: 15px; border-bottom: 1px solid #F6AD55; /* Slightly darker border */ } /* Messages Area */ .tta-chat-messages { flex: 1; overflow-y: auto; padding: 24px; background-color: #F8FAFD; scroll-behavior: smooth; display: flex; flex-direction: column; gap: 16px; } .tta-chat-messages::-webkit-scrollbar { width: 6px; } .tta-chat-messages::-webkit-scrollbar-track { background: #f1f1f1; } .tta-chat-messages::-webkit-scrollbar-thumb { background: #c1c1c1; border-radius: 3px; } .tta-chat-messages::-webkit-scrollbar-thumb:hover { background: #a8a8a8; } .tta-message { margin-bottom: 6px; max-width: 85%; padding: 16px 18px; border-radius: 18px; font-size: 16px; line-height: 1.5; word-break: break-word; position: relative; animation: message-appear 0.3s ease-out; box-shadow: 0 1px 3px rgba(0,0,0,0.05); } @keyframes message-appear { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } } .tta-message-bot { background-color: white; color: ${config.theme.text.dark}; border: 1px solid #e9e9f0; border-bottom-left-radius: 5px; align-self: flex-start; } .tta-message-user { background-color: ${config.theme.primary}; color: white; border-bottom-right-radius: 5px; align-self: flex-end; margin-left: auto; } /* Dark mode support */ @media (prefers-color-scheme: dark) { .tta-chat-widget { background-color: #1E1E2D; border: 1px solid #2D3748; } .tta-chat-messages { background-color: #2A2A3A; } .tta-message-bot { background-color: #3A3A4A; color: #F7FAFC; border: 1px solid #4A4A5A; } .tta-chat-input, .tta-chat-suggestions { background-color: #1E1E2D; border-top: 1px solid #3A3A4A; } .tta-chat-input input { background-color: #2A2A3A; border: 1px solid #3A3A4A; color: #F0F0F0; } .tta-chat-suggestions h4 { color: #CBD5E0; } .tta-suggestion-btn { background-color: #3A3A4A; border: 1px solid #4A4A5A; color: #F0F0F0; } .tta-suggestion-btn:hover { background-color: #4A4A5A; } .tta-tab-btn { color: #CBD5E0; } .tta-tab-btn:hover { background-color: #3A3A4A; } .tta-message-bot strong { color: #A3BFFA !important; } .tta-message-bot code { background: #3A3A4A !important; color: #F7FAFC !important; } .tta-message-bot a { color: #90CDF4 !important; } } /* Format links in bot messages */ .tta-message-bot a { color: ${config.theme.primary}; text-decoration: underline; font-weight: 500; transition: color 0.2s; } .tta-message-bot a:hover { color: #2840BF; text-decoration: underline; } /* Support for message formatting */ .tta-message-bot ul, .tta-message-bot ol { margin: 12px 0; padding-left: 20px; } .tta-message-bot li { margin-bottom: 8px; } .tta-message-bot strong { font-weight: 600; color: ${config.theme.primary}; } .tta-message-bot code { background: #F5F7FF; padding: 3px 6px; border-radius: 4px; font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace; font-size: 14px; } /* Input Area */ .tta-chat-input { padding: 16px 20px; background-color: white; border-top: 1px solid #eaecef; } .tta-chat-input form { display: flex; gap: 12px; align-items: center; } .tta-chat-input input { flex: 1; padding: 14px 20px; border: 2px solid #E2E8F0; border-radius: 24px; outline: none; font-size: 16px; background-color: #F8FAFD; transition: all 0.2s; } .tta-chat-input input:focus { border-color: ${config.theme.primary}; box-shadow: 0 0 0 3px rgba(53, 80, 217, 0.15); background-color: #FFFFFF; } .tta-chat-input input::placeholder { color: #94A3B8; } .tta-chat-input button { background-color: ${config.theme.primary}; color: white; border: none; width: 48px; height: 48px; border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all 0.2s; flex-shrink: 0; } .tta-chat-input button:hover { background-color: #2840BF; transform: scale(1.05); } .tta-chat-input button:focus { outline: 3px solid rgba(53, 80, 217, 0.2); outline-offset: 2px; } .tta-chat-input button svg { stroke: white; } /* Suggestions Area */ .tta-chat-suggestions { padding: 16px 20px 20px; background-color: white; border-top: 1px solid #eaecef; } .tta-chat-suggestions h4 { margin: 0 0 12px; font-size: 15px; color: #64748B; font-weight: 500; cursor: pointer; /* Make the heading clickable */ } /* Style for the collapse icon */ .tta-collapse-icon { margin-left: 5px; transition: transform 0.3s ease; /* Smooth rotation */ } /* Rotate icon when suggestions are expanded */ .tta-chat-suggestions.expanded .tta-collapse-icon { transform: rotate(180deg); } .tta-suggestions-tabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; } .tta-tab-btn { background: none; border: none; padding: 8px 14px; font-size: 14px; color: #64748B; cursor: pointer; border-radius: 30px; transition: all 0.2s; font-weight: 500; } .tta-tab-btn:hover { background-color: #F1F5F9; } .tta-tab-btn:focus { outline: 2px solid rgba(53, 80, 217, 0.2); outline-offset: 2px; } .tta-tab-btn.active { background-color: ${config.theme.primary}; color: white; font-weight: 500; } .tta-suggestions-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; } .tta-suggestion-btn { background-color: ${config.theme.secondary}; border: 1px solid #E2E8F0; border-radius: 12px; padding: 12px 14px; font-size: 14px; cursor: pointer; text-align: left; transition: all 0.2s; color: #424242; line-height: 1.4; font-weight: 400; } .tta-suggestion-btn:hover { background-color: #EBF0FF; border-color: #D8DCE8; transform: translateY(-1px); } .tta-suggestion-btn:focus { outline: 2px solid rgba(53, 80, 217, 0.2); outline-offset: 2px; } .tta-chat-widget.minimized { height: auto; } .tta-chat-widget.minimized .tta-chat-messages, .tta-chat-widget.minimized .tta-chat-input, .tta-chat-widget.minimized .tta-chat-suggestions { display: none; } /* Responsive Design */ @media (max-width: 480px) { .tta-chat-widget { width: calc(100% - 30px); height: 75vh; right: 15px; left: 15px; bottom: 80px; border-radius: 16px; } .tta-suggestions-grid { grid-template-columns: 1fr; } .tta-message { font-size: 15px; padding: 14px 16px; } } /* Loading animation */ .tta-typing { display: flex; align-items: center; column-gap: 6px; padding: 10px 0; margin-left: 10px; } .tta-typing span { display: block; width: 8px; height: 8px; background-color: ${config.theme.primary}; border-radius: 50%; opacity: 0.8; animation: typing-dot 1.4s infinite both; } .tta-typing span:nth-child(2) { animation-delay: 0.2s; } .tta-typing span:nth-child(3) { animation-delay: 0.4s; } @keyframes typing-dot { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-6px); } } /* Format table data */ .tta-table { width: 100%; border-collapse: collapse; margin: 16px 0; font-size: 14px; border-radius: 10px; overflow: hidden; border: 1px solid #E2E8F0; box-shadow: 0 2px 6px rgba(0,0,0,0.05); } .tta-table th, .tta-table td { border: 1px solid #E2E8F0; padding: 12px; text-align: left; } .tta-table th { background-color: ${config.theme.secondary}; font-weight: 600; color: #333; } .tta-table tr:nth-child(even) { background-color: #F8FAFD; } /* Progress bar for analytics */ .tta-progress-container { width: 100%; background-color: #EDF2F7; border-radius: 12px; margin: 12px 0 16px; height: 14px; overflow: hidden; } .tta-progress-bar { height: 14px; border-radius: 12px; transition: width 1s cubic-bezier(0.25, 0.8, 0.25, 1); } .tta-progress-good { background-color: #48BB78; } .tta-progress-average { background-color: #F6AD55; } .tta-progress-needs-work { background-color: #F56565; } /* Add improved styling for structured content */ .tta-structured-content { background-color: #fff; border: 1px solid #E2E8F0; border-radius: 12px; margin: 16px 0; overflow: hidden; transition: all 0.2s; box-shadow: 0 2px 8px rgba(0,0,0,0.07); } .tta-structured-content:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.1); } /* Style for recommendation cards */ .tta-recommendation-card { border: 1px solid #E2E8F0; border-radius: 12px; margin: 16px 0; overflow: hidden; background: #F9FAFB; transition: all 0.3s ease; box-shadow: 0 2px 6px rgba(0,0,0,0.05); } .tta-recommendation-card:hover { box-shadow: 0 6px 16px rgba(0,0,0,0.1); transform: translateY(-2px); } .tta-recommendation-title { font-weight: 600; padding: 14px 16px; background: ${config.theme.primary}; color: white; font-size: 15px; } .tta-recommendation-description { padding: 14px 16px; color: #333; font-size: 14px; line-height: 1.5; } .tta-recommendation-button { display: block; text-align: center; background: ${config.theme.primary}; color: white !important; padding: 12px 16px; text-decoration: none !important; margin: 5px 16px 16px; border-radius: 8px; font-weight: 500; transition: all 0.2s; } .tta-recommendation-button:hover { background: #2840BF; transform: translateY(-1px); } /* Section headers in responses */ .tta-section-header { font-weight: 600; color: ${config.theme.primary}; margin-top: 16px; margin-bottom: 8px; border-bottom: 1px solid #E2E8F0; padding-bottom: 6px; font-size: 16px; } /* Visual feedback for actions */ .tta-action-success { background-color: #E6F7E9; padding: 12px 16px; border-radius: 10px; border-left: 4px solid #48BB78; margin: 12px 0; color: #276749; } .tta-action-warning { background-color: #FFF8E1; padding: 12px 16px; border-radius: 10px; border-left: 4px solid #F6AD55; margin: 12px 0; color: #C05621; } .tta-action-error { background-color: #FEE2E2; padding: 12px 16px; border-radius: 10px; border-left: 4px solid #F56565; margin: 12px 0; color: #C53030; } /* Accessibility improvements */ .tta-sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; } /* Enhanced focus styles for keyboard navigation */ *:focus-visible { outline: 3px solid rgba(53, 80, 217, 0.3); outline-offset: 2px; } `; // Append elements to the document document.head.appendChild(chatStyle); document.body.appendChild(chatButton); document.body.appendChild(chatWidget); // Get DOM elements const messages = document.getElementById('tta-chat-messages'); const chatForm = document.getElementById('tta-chat-form'); const messageInput = document.getElementById('tta-message-input'); const minimizeBtn = document.getElementById('tta-minimize-btn'); const closeBtn = document.getElementById('tta-close-btn'); const suggestionGrid = document.querySelector('.tta-suggestions-grid'); const tabButtons = document.querySelectorAll('.tta-tab-btn'); const suggestionsToggle = document.getElementById('tta-suggestions-toggle'); const suggestionsContent = document.querySelector('.tta-suggestions-content'); const loginBanner = document.getElementById('tta-login-banner'); // Get login banner element // Toggle suggestions visibility suggestionsToggle.addEventListener('click', function() { state.isSuggestionsCollapsed = !state.isSuggestionsCollapsed; suggestionsContent.style.display = state.isSuggestionsCollapsed ? 'none' : 'block'; chatWidget.classList.toggle('expanded', !state.isSuggestionsCollapsed); // Add/remove class for styling // Update the collapse icon const collapseIcon = suggestionsToggle.querySelector('.tta-collapse-icon'); collapseIcon.innerHTML = state.isSuggestionsCollapsed ? '▼' : '▲'; // Down or Up arrow }); // Populate suggestions function populateSuggestions(category = 'all') { suggestionGrid.innerHTML = ''; config.suggestedQuestions.forEach(question => { if (category === 'all' || question.category === category) { const btn = document.createElement('button'); btn.className = 'tta-suggestion-btn'; btn.textContent = question.text; btn.setAttribute('data-question', question.text); suggestionGrid.appendChild(btn); } }); // Add event listeners to new buttons document.querySelectorAll('.tta-suggestion-btn').forEach(btn => { btn.addEventListener('click', function() { const question = btn.getAttribute('data-question'); messageInput.value = question; chatForm.dispatchEvent(new Event('submit')); }); }); } // Initialize suggestions populateSuggestions(); // Tab switching tabButtons.forEach(tab => { tab.addEventListener('click', function() { // Remove active class from all tabs tabButtons.forEach(t => t.classList.remove('active')); // Add active class to clicked tab this.classList.add('active'); // Update suggestions based on category populateSuggestions(this.getAttribute('data-category')); }); }); // Show/hide chat widget chatButton.addEventListener('click', function() { toggleChat(); }); // Minimize chat minimizeBtn.addEventListener('click', function() { toggleMinimize(); }); // Close chat closeBtn.addEventListener('click', function() { hideChat(); }); // Submit message chatForm.addEventListener('submit', function(e) { e.preventDefault(); const message = messageInput.value.trim(); if (!message) return; // Add user message to chat addMessage('user', message); state.messageHistory.push({ role: 'user', content: message }); messageInput.value = ''; // Prevent multiple submissions if (state.isTyping) return; state.isTyping = true; // Add typing indicator const typingId = addTypingIndicator(); // Get CSRF token const token = document.querySelector('meta[name="csrf-token"]')?.getAttribute('content') || ''; // Send message to server using fetch API fetch(config.apiEndpoint, { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': token, 'Accept': 'application/json' }, body: JSON.stringify({ message, session_id: state.sessionId, history: state.messageHistory }) }) .then(response => { if (!response.ok) { throw new Error('Network response was not ok: ' + response.status); } return response.json(); }) .then(data => { // Remove typing indicator removeElement(typingId); state.isTyping = false; // Add response message if (data.status === 'success') { addMessage('bot', formatBotMessage(data.message)); state.messageHistory.push({ role: 'assistant', content: data.message }); } else { addMessage('bot', 'Sorry, I encountered an error: ' + data.message); } // Update last activity time state.lastActivity = Date.now(); }) .catch(error => { console.error('Error:', error); // Remove typing indicator removeElement(typingId); state.isTyping = false; // Add error message addMessage('bot', 'Sorry, I encountered an error. Please try again later.'); }); }); // Helper functions function formatBotMessage(message) { // Check if the message already contains HTML (for structured recommendations) if (message.includes('
$1') // Handle bold .replace(/\*\*([^*]+)\*\*/g, '$1') // Handle line breaks (but not inside HTML tags) .replace(/\n(?![^<]*>)/g, '
'); } // Regular markdown formatting for text-only messages try { return message // Handle links .replace(/\[([^\]]+)\]\(([^)]+)\)/g, '$1') // Handle bold .replace(/\*\*([^*]+)\*\*/g, '$1') // Handle headings .replace(/^### (.*$)/gm, '

$1

') .replace(/^## (.*$)/gm, '

$1

') // Handle emphasis .replace(/\*([^*]+)\*/g, '$1') // Handle lists .replace(/^\s*-\s+(.+)$/gm, '
  • $1
  • ') // Wrap lists .replace(/(
  • .+<\/li>\s*)+/g, '') // Handle line breaks .replace(/\n/g, '
    '); } catch (e) { console.error('Error formatting message:', e); return message; // Return original message if formatting fails } } function addMessage(type, content) { const messageEl = document.createElement('div'); messageEl.className = `tta-message tta-message-${type === 'user' ? 'user' : 'bot'}`; messageEl.id = 'msg-' + Date.now(); // Set content based on type (HTML for bot, text for user) if (type === 'bot') { messageEl.innerHTML = content; } else { messageEl.textContent = content; } messages.appendChild(messageEl); scrollToBottom(); return messageEl.id; } function addTypingIndicator() { const typingId = 'typing-' + Date.now(); const typingEl = document.createElement('div'); typingEl.id = typingId; typingEl.className = 'tta-message tta-message-bot'; typingEl.innerHTML = '
    '; messages.appendChild(typingEl); scrollToBottom(); return typingId; } function removeElement(id) { const el = document.getElementById(id); if (el) el.remove(); } function scrollToBottom() { messages.scrollTop = messages.scrollHeight; } function toggleChat() { if (state.isOpen) { hideChat(); } else { showChat(); } } function showChat() { chatWidget.style.display = 'flex'; chatWidget.setAttribute('aria-hidden', 'false'); state.isOpen = true; chatButton.style.animation = 'none'; // **Show/Hide Login Banner based on login status** if (config.requireLoginBanner) { loginBanner.style.display = state.isUserLoggedIn ? 'none' : 'block'; } else { loginBanner.style.display = 'none'; // Hide banner if disabled in config } // Add initial message if first time opening if (messages.children.length === 0) { addMessage('bot', config.welcomeMessage); } // Focus input setTimeout(() => messageInput.focus(), 300); } function hideChat() { chatWidget.style.display = 'none'; chatWidget.setAttribute('aria-hidden', 'true'); state.isOpen = false; } function toggleMinimize() { state.isMinimized = !state.isMinimized; chatWidget.classList.toggle('minimized', state.isMinimized); } function generateSessionId() { return 'tta-' + Math.random().toString(36).substring(2, 15); } // Auto-resize input field based on content messageInput.addEventListener('input', function() { this.style.height = 'auto'; const maxHeight = 100; const newHeight = Math.min(this.scrollHeight, maxHeight); if (newHeight > 50) { this.style.height = newHeight + 'px'; } else { this.style.height = ''; } }); // Save chat state in localStorage when window is closed window.addEventListener('beforeunload', function() { if (state.messageHistory.length > 0) { try { localStorage.setItem('tta-chat-history', JSON.stringify(state.messageHistory)); localStorage.setItem('tta-session-id', state.sessionId); } catch (e) { console.log('Could not save chat history', e); } } }); // Restore chat state when page loads function restoreChatState() { try { const savedHistory = localStorage.getItem('tta-chat-history'); const savedSessionId = localStorage.getItem('tta-session-id'); if (savedHistory && savedSessionId) { state.messageHistory = JSON.parse(savedHistory); state.sessionId = savedSessionId; // Rebuild the conversation UI state.messageHistory.forEach(msg => { if (msg.role === 'user') { addMessage('user', msg.content); } else if (msg.role === 'assistant') { addMessage('bot', formatBotMessage(msg.content)); } }); } } catch (e) { console.log('Could not restore chat history', e); } } // Inactivity detection setInterval(() => { if (state.isOpen && (Date.now() - state.lastActivity > 300000) && !state.isTyping) { // 5 minutes addMessage('bot', "Are you still there? I'm here if you have any more questions about your test prep."); state.lastActivity = Date.now(); } }, 60000); // Check every minute // Auto-resize when window is resized window.addEventListener('resize', function() { if (state.isOpen) { scrollToBottom(); } }); // Initialize any needed features based on page function initializePageSpecificFeatures() { // Check if we're on a skill drill test page if (window.location.pathname.includes('/skill-drill-test-details/')) { // Extract the test ID from the URL const testIdMatch = window.location.pathname.match(/\/skill-drill-test-details\/(\d+)/); if (testIdMatch && testIdMatch[1]) { // Add test-specific suggestions config.suggestedQuestions.unshift( { text: "How should I prepare for this test?", category: "test" }, { text: "What skills does this test focus on?", category: "test" } ); // Update the suggestions populateSuggestions('all'); } } // Check if we're on a test page if (window.location.pathname.includes('/test/') || window.location.pathname.includes('/tests/')) { // Add test-specific suggestions config.suggestedQuestions.push( { text: "How do I interpret this passage?", category: "test" }, { text: "What's a good strategy for this question type?", category: "test" } ); // Update the suggestions populateSuggestions('all'); } } // Restore chat history when available restoreChatState(); // Initialize with page-specific features initializePageSpecificFeatures(); })(); -->