CoolFace
Apppublic

TotalWarModder/beloozero-banner-forge

sourceHugging Faceupdated 8mo agoView on Hugging Face
0likes
script.js111 linesDownload Raw Back to root
1 2document.addEventListener('DOMContentLoaded', () => {3    // Animation for banner cards4    const bannerCards = document.querySelectorAll('banner-card');5    6    bannerCards.forEach((card, index) => {7        card.style.opacity = '0';8        card.style.transform = 'translateY(20px)';9        card.style.transition = `all 0.5s ease ${index * 0.1}s`;10        11        setTimeout(() => {12            card.style.opacity = '1';13            card.style.transform = 'translateY(0)';14        }, 100);15    });16 17    // AI Assistant functionality18    if (document.getElementById('ai-form')) {19        const form = document.getElementById('ai-form');20        const userInput = document.getElementById('user-input');21        const chatContainer = document.getElementById('chat-container');22 23        form.addEventListener('submit', async (e) => {24            e.preventDefault();25            const question = userInput.value.trim();26            if (!question) return;27 28            // Add user message to chat29            addMessage(question, 'user');30            userInput.value = '';31 32            // Show loading indicator33            const loadingId = addMessage('Thinking...', 'ai', true);34 35            try {36                // In a real implementation, you would call your AI API here37                // This is a mock implementation for demonstration38                const response = await mockAIResponse(question);39                40                // Replace loading with actual response41                updateMessage(loadingId, response, 'ai');42            } catch (error) {43                updateMessage(loadingId, "Sorry, I encountered an error. Please try again later.", 'ai');44                console.error(error);45            }46        });47 48        function addMessage(content, sender, isTemp = false) {49            const messageDiv = document.createElement('div');50            const messageClass = sender === 'user' 51                ? 'bg-indigo-600 text-white ml-auto' 52                : 'bg-indigo-50 text-indigo-800';53            54            messageDiv.className = `p-4 rounded-lg max-w-3xl ${messageClass}`;55            messageDiv.innerHTML = marked.parse(content);56            57            if (isTemp) {58                messageDiv.id = 'temp-' + Date.now();59            }60            61            chatContainer.appendChild(messageDiv);62            chatContainer.scrollTop = chatContainer.scrollHeight;63            64            return messageDiv.id;65        }66 67        function updateMessage(id, content, sender) {68            const messageDiv = document.getElementById(id);69            if (messageDiv) {70                const messageClass = sender === 'user' 71                    ? 'bg-indigo-600 text-white ml-auto' 72                    : 'bg-indigo-50 text-indigo-800';73                74                messageDiv.className = `p-4 rounded-lg max-w-3xl ${messageClass}`;75                messageDiv.innerHTML = marked.parse(content);76                chatContainer.scrollTop = chatContainer.scrollHeight;77            }78        }79 80        async function mockAIResponse(question) {81            // Simulate API delay82            await new Promise(resolve => setTimeout(resolve, 1500));83            84            // This is where you would normally call a real AI API85            // For demo purposes, we'll return mock responses86            const responses = {87                'game': "For Medieval 2 Total War mods, I recommend starting with the Assembly Kit tools. You'll need to...",88                'fix': "To troubleshoot performance issues, first check your system resources. Press Ctrl+Shift+Esc to open Task Manager...",89                'create': "When creating new content, begin by outlining your requirements. For game assets, consider using...",90                'default': `I can help with that! Here's a comprehensive guide to ${question.toLowerCase()}:91                921. First step would be to...932. Then you should consider...943. Finally, make sure to...95 96Would you like more specific details about any of these steps?`97            };98 99            if (question.toLowerCase().includes('game') || question.toLowerCase().includes('mod')) {100                return responses['game'];101            } else if (question.toLowerCase().includes('fix') || question.toLowerCase().includes('error')) {102                return responses['fix'];103            } else if (question.toLowerCase().includes('create') || question.toLowerCase().includes('make')) {104                return responses['create'];105            } else {106                return responses['default'];107            }108        }109    }110});111