Skip to content
Skip to content
document.addEventListener('DOMContentLoaded', function () {
const submitBtn = document.getElementById('submit-ai-question');
const questionInput = document.getElementById('ai-question');
const postIdField = document.getElementById('hidden-post-id');
const postId = postIdField ? postIdField.value : 'unknown';
if (submitBtn && questionInput) {
submitBtn.addEventListener('click', function () {
const question = questionInput.value.trim();
if (!question) return;
const loading = document.getElementById('ai-loading');
const responseBox = document.getElementById('ai-response');
const responseText = document.getElementById('ai-response-text');
loading.style.display = 'block';
responseBox.style.display = 'none';
responseBox.style.opacity = 0;
fetch('https://hooks.zapier.com/hooks/catch/21429105/2nkr6c1/', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
question: question,
postId: postId
})
}).then(function (response) {
loading.style.display = 'none';
responseBox.style.display = 'block';
setTimeout(function () {
responseBox.style.opacity = 1;
}, 50);
responseText.innerText = "✅ Question submitted. AI response will appear soon.";
}).catch(function (error) {
loading.style.display = 'none';
responseBox.style.display = 'block';
responseText.innerText = "❌ Error sending question.";
console.error(error);
});
});
// Button hover styling
submitBtn.addEventListener('mouseover', function () {
submitBtn.style.backgroundColor = '#4f8a61';
});
submitBtn.addEventListener('mouseout', function () {
submitBtn.style.backgroundColor = '#6daa75';
});
}
});