Lead Magnet Content Generator
Create compelling content for your lead magnets instantly.
Generated Lead Magnet Content
Your generated content will appear here.
Go to 'Data Configuration' to enter your details.
Describe Your Lead Magnet
${intro}
`; } else if (conclusionMatch) { const conclusion = conclusionMatch[1].trim(); currentSection = { heading: 'Conclusion', items: [conclusion] }; parsedContent.sections.push(currentSection); html += `Conclusion
${conclusion}
`; } else if (chapterMatch || dayMatch || checklistMatch) { const heading = (chapterMatch || dayMatch)?.[1]?.trim() || 'Checklist'; currentSection = { heading: heading, items: [] }; parsedContent.sections.push(currentSection); html += `${heading}
`; if(type === 'checklist') html += ''; else html += '
';
return { parsedContent, html };
}
function renderContent(text, type) {
const { parsedContent, html } = parseAndRenderContent(text, type);
if (parsedContent.title) {
lastGeneratedContent = parsedContent;
previewPlaceholder.classList.add('hidden');
resultsPreview.innerHTML = html;
} else {
resultsPreview.innerHTML = `- ';
} else if (itemMatch && currentSection) {
const item = itemMatch[1].trim();
currentSection.items.push(item);
if(type === 'checklist') {
html += `
- ${item} `; } } }); if (html.endsWith('
${item}
`;
} else {
html += `- ') || html.endsWith('
')) {
html += type === 'checklist' ? '
' : 'The AI could not generate content in the expected format. Please try again.
';
generateBtn.disabled = true;
generateBtn.textContent = 'Generating...';
showFeedback('AI is crafting your content...', false, 0);
} else {
generateBtn.disabled = false;
generateBtn.textContent = 'Generate Content';
}
}
downloadPdfBtn.addEventListener('click', () => {
if (!lastGeneratedContent) {
showFeedback('Please generate content before downloading.', true, 3000);
return;
}
showFeedback('Generating PDF...', false, 2000);
try {
const { jsPDF } = window.jspdf;
const pdf = new jsPDF({ unit: 'pt', format: 'letter' });
const pageMargin = 72;
const pageWidth = pdf.internal.pageSize.getWidth();
const textWidth = pageWidth - (pageMargin * 2);
let cursorY = pageMargin;
function addText(text, size, style, spaceAfter) {
if (cursorY > pdf.internal.pageSize.getHeight() - pageMargin) {
pdf.addPage();
cursorY = pageMargin;
}
pdf.setFont('Helvetica', style);
pdf.setFontSize(size);
const lines = pdf.splitTextToSize(text, textWidth);
pdf.text(lines, pageMargin, cursorY);
cursorY += (lines.length * size * 1.2) + spaceAfter;
}
addText(lastGeneratedContent.title, 22, 'bold', 30);
lastGeneratedContent.sections.forEach(section => {
addText(section.heading, 16, 'bold', 10);
section.items.forEach(item => {
addText( (section.heading === 'Checklist' || item.startsWith('•') ? '' : '• ') + item, 11, 'normal', 8);
});
cursorY += 15;
});
pdf.save('lead-magnet-content.pdf');
} catch(err) {
console.error("PDF Generation Error: ", err);
showFeedback("Error generating PDF.", true, 3000);
}
});
let feedbackTimeout;
function showFeedback(message, isError = false, duration = 3000) {
clearTimeout(feedbackTimeout);
feedbackMessage.innerHTML = message;
feedbackMessage.style.color = isError ? '#ef4444' : '#4a5568';
if (duration !== 0) {
feedbackTimeout = setTimeout(() => { feedbackMessage.innerHTML = ''; }, duration);
}
}
});
