replit-clone / script.js
creative888's picture
add a chat with ai option in this, so the user can use the ai to write codes
0f0f876 verified
// DOM Content Loaded Event
document.addEventListener('DOMContentLoaded', function() {
// Initialize feather icons
feather.replace();
// Add animation to cards on page load
const cards = document.querySelectorAll('.border');
cards.forEach((card, index) => {
setTimeout(() => {
card.classList.add('opacity-100');
}, 100 * index);
});
// Button click effects
const buttons = document.querySelectorAll('button');
buttons.forEach(button => {
button.addEventListener('click', function() {
this.classList.add('scale-95');
setTimeout(() => {
this.classList.remove('scale-95');
}, 100);
});
});
});
// AI Chat toggle functionality
document.addEventListener('toggleAIChat', function() {
const aiAgent = document.querySelector('ai-agent');
if (aiAgent) {
aiAgent.shadowRoot.querySelector('#agentButton').click();
}
});
// Theme toggle functionality
function toggleTheme() {
const html = document.documentElement;
const currentTheme = html.classList.contains('dark') ? 'dark' : 'light';
if (currentTheme === 'light') {
html.classList.add('dark');
localStorage.setItem('theme', 'dark');
} else {
html.classList.remove('dark');
localStorage.setItem('theme', 'light');
}
}
// Check for saved theme preference
document.addEventListener('DOMContentLoaded', function() {
const savedTheme = localStorage.getItem('theme');
if (savedTheme === 'dark') {
document.documentElement.classList.add('dark');
}
});