Random Magic Spell Creator

Generate a fictional magic spell with effects, incantations, and requirements!

Your random magic spell will appear here!

Casting Requirements: ${magicSpell.requirements}

Duration/Limitations: ${magicSpell.duration}

`; downloadPdfBtn.style.display = 'block'; // Show download button only on success } }); document.getElementById('clearBtn').addEventListener('click', () => { document.getElementById('magicSchool').value = 'any'; document.getElementById('effectType').value = 'any'; document.getElementById('complexityLevel').value = 'cantrip'; document.getElementById('spellTarget').value = 'any'; document.getElementById('spellKeyword').value = ''; document.getElementById('spellResults').innerHTML = '

Your random magic spell will appear here!

'; document.getElementById('downloadPdfBtn').style.display = 'none'; // Hide PDF button }); // Download PDF Button document.getElementById('downloadPdfBtn').addEventListener('click', () => { const resultsDiv = document.getElementById('spellResults'); // Check if results are error message before attempting to get text if (resultsDiv.textContent.includes("Error:") || resultsDiv.textContent.includes('Your random magic spell will appear here!')) { alert("No spell to download."); return; } const nameText = resultsDiv.querySelector('p:nth-child(1)') ? resultsDiv.querySelector('p:nth-child(1)').textContent.replace('Spell Name: ', '').trim() : ''; const incantationText = resultsDiv.querySelector('p:nth-child(2)') ? resultsDiv.querySelector('p:nth-child(2)').textContent.replace('Incantation: ', '').trim() : ''; const effectText = resultsDiv.querySelector('p:nth-child(3)') ? resultsDiv.querySelector('p:nth-child(3)').textContent.replace('Effect: ', '').trim() : ''; const requirementsText = resultsDiv.querySelector('p:nth-child(4)') ? resultsDiv.querySelector('p:nth-child(4)').textContent.replace('Casting Requirements: ', '').trim() : ''; const durationText = resultsDiv.querySelector('p:nth-child(5)') ? resultsDiv.querySelector('p:nth-child(5)').textContent.replace('Duration/Limitations: ', '').trim() : ''; if (!nameText) { // Should not happen if check passed, but for safety alert("No spell to download."); return; } // --- PDF Generation --- const doc = new jsPDF(); const margin = 15; let y = margin; const pageHeight = doc.internal.pageSize.height; const pageWidth = doc.internal.pageSize.width; const maxLineWidth = pageWidth - 2 * margin; // Max width for text line doc.setFontSize(18); doc.setTextColor(52, 58, 64); // Match text-color variable #343a0 doc.text("Random Magic Spell", margin, y); y += 15; // Space after title doc.setFontSize(12); doc.setTextColor(52, 58, 64); // Match text-color variable #343a0 // Add sections const addSection = (title, text) => { if (!text || text.trim() === "") return; doc.setFontSize(14); doc.setFont(undefined, 'bold'); doc.text(title, margin, y); doc.setFont(undefined, 'normal'); y += 8; doc.setFontSize(12); const textLines = doc.splitTextToSize(text, maxLineWidth); textLines.forEach(line => { if (y + 7 > pageHeight - margin) { doc.addPage(); y = margin; } doc.text(line, margin, y); y += 7; }); y += 10; // Space after section }; addSection("Spell Name:", nameText); addSection("Incantation:", incantationText); addSection("Effect:", effectText); addSection("Casting Requirements:", requirementsText); addSection("Duration/Limitations:", durationText); doc.save('random_magic_spell.pdf'); });

Key Features

  1. Random Magic Spells: Generates unique and creative magic spells with names, descriptions, and effects.

  2. Header with Instructions: Includes a header with a title and brief instructions for ease of use.

  3. PDF Download: Allows users to download the generated spell as a PDF with a consistent color scheme.

  4. Centered Layout: The tool is perfectly centered on the page for a clean and professional look.

  5. Lightweight and Fast: Optimized for performance and works seamlessly in WordPress Elementor HTML blocks.

    Benefits for End Users

    1. Creative Fun: Provides a fun and engaging way to explore unique magic spells.

    2. User-Friendly: Simple and intuitive interface ensures ease of use for all users.

    3. Portable Results: The PDF download feature allows users to save and share their spells effortlessly.

    4. Engaging Design: The tool’s modern design and consistent color scheme enhance the user experience.

    5. Privacy: No personal data is collected, ensuring complete privacy for users.

Scroll to Top