auditautomagica / script.js
CairoSSN's picture
Now make it functional by adding the backend part of the site, I want the buttons to be actionable. Remove testimonials and the trusted by section as we are a new SaaS company
0233a8a verified
Raw History Blame Contribute Delete
3.77 kB
// Form handlers and API integration
const handleSignup = async (email, plan = 'free') => {
try {
const response = await fetch('/api/signup', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ email, plan }),
});
if (response.ok) {
window.location.href = '/dashboard';
} else {
const errorData = await response.json();
throw new Error(errorData.message || 'Signup failed');
}
} catch (error) {
alert(error.message);
}
};
const handleDemoRequest = async (email) => {
try {
const response = await fetch('/api/request-demo', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ email }),
});
if (response.ok) {
alert('Demo scheduled! We\'ll contact you shortly.');
} else {
const errorData = await response.json();
throw new Error(errorData.message || 'Request failed');
}
} catch (error) {
alert(error.message);
}
};
// Dark mode toggle functionality
document.addEventListener('DOMContentLoaded', function() {
const darkModeToggle = document.getElementById('darkModeToggle');
// Setup form handlers
document.querySelectorAll('.signup-form').forEach(form => {
form.addEventListener('submit', async (e) => {
e.preventDefault();
const email = form.querySelector('input[type="email"]').value;
const plan = form.dataset.plan || 'free';
await handleSignup(email, plan);
});
});
document.querySelectorAll('.demo-form').forEach(form => {
form.addEventListener('submit', async (e) => {
e.preventDefault();
const email = form.querySelector('input[type="email"]').value;
await handleDemoRequest(email);
});
});
// Check for saved user preference
if (localStorage.getItem('darkMode') === 'enabled') {
document.documentElement.classList.add('dark');
if (darkModeToggle) darkModeToggle.checked = true;
}
// Toggle dark mode
if (darkModeToggle) {
darkModeToggle.addEventListener('change', function() {
if (this.checked) {
document.documentElement.classList.add('dark');
localStorage.setItem('darkMode', 'enabled');
} else {
document.documentElement.classList.remove('dark');
localStorage.setItem('darkMode', 'disabled');
}
});
}
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href');
if (targetId === '#') return;
const targetElement = document.querySelector(targetId);
if (targetElement) {
targetElement.scrollIntoView({
behavior: 'smooth'
});
}
});
});
// Animation for pricing cards
const pricingCards = document.querySelectorAll('.pricing-card');
pricingCards.forEach(card => {
card.addEventListener('mouseenter', () => {
card.classList.add('shadow-lg');
card.classList.remove('shadow-md');
});
card.addEventListener('mouseleave', () => {
card.classList.remove('shadow-lg');
card.classList.add('shadow-md');
});
});
});