`;
showNotification("Error generating content.");
} finally {
generateBtn.disabled = false;
generateBtn.textContent = 'Generate Intros';
}
}
function renderIntros() {
resultsContainer.innerHTML = generatedIntros.map((intro, index) => `
`).join('');
}
// --- UTILITY FUNCTIONS ---
function showNotification(message, duration = 2000) {
notification.textContent = message;
notification.classList.remove('opacity-0');
setTimeout(() => notification.classList.add('opacity-0'), duration);
}
function copyToClipboard(text, message) {
navigator.clipboard.writeText(text).then(() => {
showNotification(message);
});
}
// --- PDF GENERATION ---
async function generatePdfReport() {
if (generatedIntros.length === 0) {
showNotification("No intros to generate a report for.");
return;
}
downloadPdfBtn.disabled = true;
downloadPdfBtn.textContent = '...';
const introCards = generatedIntros.map((intro, index) => `
`).join('');
const reportHtml = `
`;
const pdfTemplate = document.getElementById('pdf-template');
pdfTemplate.innerHTML = reportHtml;
pdfTemplate.classList.remove('invisible');
try {
const { jsPDF } = window.jspdf;
const canvas = await html2canvas(pdfTemplate.querySelector('.pdf-page'), { scale: 2 });
const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF({ orientation: 'p', unit: 'pt', format: 'a4' });
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = (canvas.height * pdfWidth) / canvas.width;
pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight);
pdf.save(`Blog_Intros_${inputsData.title.replace(/\s+/g, '_')}.pdf`);
} catch (e) { console.error('PDF Generation Error:', e); } finally {
downloadPdfBtn.disabled = false;
downloadPdfBtn.textContent = 'Download PDF';
pdfTemplate.classList.add('invisible');
pdfTemplate.innerHTML = '';
}
}
// --- EVENT LISTENERS ---
generateBtn.addEventListener('click', generateIntros);
copyAllBtn.addEventListener('click', () => {
if (generatedIntros.length === 0) {
showNotification("Nothing to copy.");
return;
}
copyToClipboard(generatedIntros.join('\n\n'), 'All intros copied!');
});
resultsContainer.addEventListener('click', (e) => {
if (e.target.classList.contains('copy-intro-btn')) {
const introText = generatedIntros[e.target.dataset.index];
copyToClipboard(introText, 'Intro copied!');
}
});
downloadPdfBtn.addEventListener('click', generatePdfReport);
});
${intro}
Option ${index + 1}
${intro}
Blog Introduction Hooks
For Blog Post: ${inputsData.title}
Generated Ideas
${introCards}
