// Shared JavaScript across all pages class ThemeManager { constructor() { this.currentTheme = localStorage.getItem('theme') || 'light'; this.currentPalette = localStorage.getItem('palette') || 'her'; this.init(); } init() { this.applyTheme(this.currentTheme); this.applyPalette(this.currentPalette); this.setupEventListeners(); } applyTheme(theme) { document.documentElement.classList.remove('light', 'dark'); document.documentElement.classList.add(theme); localStorage.setItem('theme', theme); } applyPalette(palette) { document.documentElement.classList.remove('theme-her', 'theme-lost', 'theme-blade'); document.documentElement.classList.add(`theme-${palette}`); localStorage.setItem('palette', palette); } setupEventListeners() { // Theme toggles will be handled by individual components } toggleTheme() { const newTheme = this.currentTheme === 'light' ? 'dark' : 'light'; this.currentTheme = newTheme; this.applyTheme(newTheme); } setPalette(palette) { this.currentPalette = palette; this.applyPalette(palette); } } // Initialize theme manager const themeManager = new ThemeManager(); // Chat functionality class ChatManager { constructor() { this.messages = []; this.isStreaming = false; } addMessage(content, isUser = false) { const message = { id: Date.now(), content, isUser, timestamp: new Date() }; this.messages.push(message); this.renderMessage(message); } renderMessage(message) { // Implementation will be page-specific } streamMessage(content, callback) { this.isStreaming = true; // Simulate streaming for demo const words = content.split(' '); let currentContent = ''; const streamInterval = setInterval(() => { if (words.length === 0) { clearInterval(streamInterval); this.isStreaming = false; if (callback) callback(); return; } currentContent += words.shift() + ' '; // Update message content in UI const messageElement = document.querySelector(`[data-message-id="${message.id}"]`); if (messageElement) { messageElement.textContent = currentContent; } }, 50); } } // Responsive utilities class ResponsiveManager { constructor() { this.currentBreakpoint = this.getBreakpoint(); this.init(); } init() { this.setupResizeListener(); } getBreakpoint() { const width = window.innerWidth; if (width <= 480) return 'xs'; if (width <= 768) return 'sm'; if (width <= 1024) return 'md'; if (width <= 1440) return 'lg'; return 'xl'; } setupResizeListener() { let resizeTimeout; window.addEventListener('resize', () => { clearTimeout(resizeTimeout); resizeTimeout = setTimeout(() => { const newBreakpoint = this.getBreakpoint(); if (newBreakpoint !== this.currentBreakpoint) { this.currentBreakpoint = newBreakpoint; this.onBreakpointChange(newBreakpoint); } }, 100); }); } onBreakpointChange(breakpoint) { // Dispatch custom event for components to listen to window.dispatchEvent(new CustomEvent('breakpointChange', { detail: { breakpoint } })); } } // Initialize responsive manager const responsiveManager = new ResponsiveManager(); // Utility functions const utils = { debounce(func, wait) { let timeout; return function executedFunction(...args) { const later = () => { clearTimeout(timeout); func(...args); }; clearTimeout(timeout); timeout = setTimeout(later, wait); }; }, throttle(func, limit) { let inThrottle; return function() { const args = arguments; const context = this; if (!inThrottle) { func.apply(context, args); inThrottle = true; setTimeout(() => inThrottle = false, limit); }; }, formatTime(seconds) { const mins = Math.floor(seconds / 60); const secs = seconds % 60; return `${mins}:${secs.toString().padStart(2, '0')}`; }, generateId() { return Date.now().toString(36) + Math.random().toString(36).substr(2); } }; // API integration class APIManager { constructor() { this.baseURL = 'https://api.auraforge.ai/v1'; } async makeRequest(endpoint, options = {}) { try { const response = await fetch(`${this.baseURL}${endpoint}`, { headers: { 'Content-Type': 'application/json', ...options.headers }, ...options }); if (!response.ok) { throw new Error(`API request failed: ${response.statusText}`); } return await response.json(); } async getInterviews() { return this.makeRequest('/interviews'); } async getVoices() { return this.makeRequest('/voices'); } async startInterview(type, options = {}) { return this.makeRequest(`/interviews/${type}/start`, { method: 'POST', body: JSON.stringify(options) }); } } // Initialize API manager const apiManager = new APIManager(); // Export for use in components window.ThemeManager = themeManager; window.ChatManager = ChatManager; window.ResponsiveManager = responsiveManager; window.APIManager = apiManager; window.utils = utils; console.log('AuraForge AI loaded successfully');