AI Autocomplete Lyrics Generator
Suggestions:
Enter a line above and click "Get Suggestions".
No more unique suggestions available right now.
'; return; } suggestions.forEach(suggestion => { const button = document.createElement('button'); button.textContent = suggestion; button.classList.add('ai-lyrics-suggestion-btn'); suggestionsListDiv.appendChild(button); }); } // Append accepted suggestion (or current input) to lyrics function acceptSuggestion(textToAdd) { const currentLyrics = generatedLyricsTextarea.value; const lineEnding = "\n"; // Add a newline between lines // If lyrics area is empty, don't add a leading newline const newLyrics = currentLyrics ? (currentLyrics + lineEnding + textToAdd) : textToAdd; generatedLyricsTextarea.value = newLyrics; currentLineInput.value = ''; // Clear input line after adding suggestionsListDiv.innerHTML = 'Suggestion added! Enter next line or get more suggestions.
'; // Clear suggestions // Scroll to the bottom of the textarea generatedLyricsTextarea.scrollTop = generatedLyricsTextarea.scrollHeight; } // Clear all inputs and outputs function clearAll() { currentLineInput.value = ''; generatedLyricsTextarea.value = ''; suggestionsListDiv.innerHTML = 'Enter a line above and click "Get Suggestions".
'; } // Download lyrics as PDF function downloadPdf() { const lyricsText = generatedLyricsTextarea.value; if (!lyricsText.trim()) { alert("There are no lyrics to download!"); return; } try { const doc = new jsPDF(); const title = "Generated Song Lyrics"; // Get PDF text color from CSS variable for consistency const pdfTextColor = getComputedStyle(document.documentElement).getPropertyValue('--ai-lyrics-pdf-text-color').trim(); doc.setTextColor(pdfTextColor); doc.setFontSize(18); doc.text(title, 105, 15, null, null, 'center'); // Centered title doc.setFontSize(12); // Split text into lines that fit the page width (approx A4 width minus margins) const splitLyrics = doc.splitTextToSize(lyricsText, 180); doc.text(splitLyrics, 15, 30); // Add text with margin doc.save('ai-generated-lyrics.pdf'); } catch (error) { console.error("Error generating PDF:", error); alert("An error occurred while generating the PDF. Please check the console for details."); } } // --- Event Listeners --- getSuggestionsBtn.addEventListener('click', () => { // Optional: Could use currentLineInput.value to influence suggestions later const suggestions = generateSuggestions(3); // Get 3 suggestions displaySuggestions(suggestions); }); // Use event delegation for dynamically added suggestion buttons suggestionsListDiv.addEventListener('click', (event) => { if (event.target.classList.contains('ai-lyrics-suggestion-btn')) { // First, add the manually entered line (if any) const currentLine = currentLineInput.value.trim(); if (currentLine) { acceptSuggestion(currentLine); // Add the current typed line first } // Then, add the clicked suggestion acceptSuggestion(event.target.textContent); } }); clearLyricsBtn.addEventListener('click', clearAll); downloadPdfBtn.addEventListener('click', downloadPdf); // --- Initial Setup --- // Optional: You could display initial random suggestions on load // clearAll(); // Start clean }Key features of this implementation:
- Clean, centered design with a modern blue color scheme that works well within WordPress
- Interactive controls including:
- Creativity level slider (conventional to experimental)
- Emotional tone dropdown (melancholic, romantic, hopeful, angry, joyful, reflective)
- Musical style selection (pop, rock, folk, hip hop, country, R&B, electronic)
- Multiple generation options:
- Generate suggestions (provides clickable suggestion pills)
- Complete verse (automatically builds on your initial lyrics)
