Script: Font Playlist
// export/import function exportPlaylist() const dataStr = JSON.stringify( fonts: playlist, savedText: userMessageTextarea.value , null, 2); const blob = new Blob([dataStr], type: "application/json"); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = "fontPlaylist.json"; a.click(); URL.revokeObjectURL(url);
// Auto-rotation function startAutoRotate() if (intervalId) clearInterval(intervalId); if (playlist.length === 0) return; isPlaying = true; intervalId = setInterval(() => if (playlist.length > 0) currentIndex = (currentIndex + 1) % playlist.length; updateDisplay(); , 3000);
userMessageTextarea.addEventListener('input', updateTextContent); prevBtn.addEventListener('click', prevFont); nextBtn.addEventListener('click', nextFont); playBtn.addEventListener('click', () => if (playlist.length) startAutoRotate(); else alert("Add fonts to playlist first"); ); pauseBtn.addEventListener('click', stopAutoRotate); addFontBtn.addEventListener('click', addFont); exportBtn.addEventListener('click', exportPlaylist); importBtn.addEventListener('click', () => importFileInput.click()); importFileInput.addEventListener('change', (e) => if (e.target.files.length) importPlaylist(e.target.files[0]); importFileInput.value = ''; ); darkModeBtn.addEventListener('click', toggleDarkMode); // Stop rotation when page visibility or before unload (clean) window.addEventListener('beforeunload', () => if(intervalId) clearInterval(intervalId); ); font playlist script
// Helper: update preview font + text function updateDisplay() if (!playlist.length) displayDiv.style.fontFamily = "sans-serif"; currentFontLabel.innerText = "Font: none"; fontCounterSpan.innerText = `Font 0 of 0`; return; const currentFont = playlist[currentIndex]; displayDiv.style.fontFamily = `'$currentFont', system-ui, sans-serif`; currentFontLabel.innerText = `Font: $currentFont`; fontCounterSpan.innerText = `Font $currentIndex+1 of $playlist.length`;
// Add font function addFont() let newFont = newFontNameInput.value.trim(); if (newFont === "") return alert("Enter a font name"); // simple check: avoid duplicate (case-insensitive) if (playlist.some(f => f.toLowerCase() === newFont.toLowerCase())) alert("Font already in playlist"); return; playlist.push(newFont); renderPlaylistUI(); if (playlist.length === 1) currentIndex = 0; updateDisplay(); newFontNameInput.value = ""; if (isPlaying) stopAutoRotate(); startAutoRotate(); const blob = new Blob([dataStr]
// dark mode toggle function toggleDarkMode() document.body.classList.toggle('dark');
// DOM elements const displayDiv = document.getElementById('displayText'); const currentFontLabel = document.getElementById('currentFontLabel'); const userMessageTextarea = document.getElementById('userMessage'); const prevBtn = document.getElementById('prevBtn'); const nextBtn = document.getElementById('nextBtn'); const playBtn = document.getElementById('playBtn'); const pauseBtn = document.getElementById('pauseBtn'); const addFontBtn = document.getElementById('addFontBtn'); const newFontNameInput = document.getElementById('newFontName'); const fontListContainer = document.getElementById('fontListContainer'); const fontCounterSpan = document.getElementById('fontCounter'); const exportBtn = document.getElementById('exportBtn'); const importBtn = document.getElementById('importBtn'); const importFileInput = document.getElementById('importFile'); const darkModeBtn = document.getElementById('darkModeBtn'); const url = URL.createObjectURL(blob)
// refresh font list UI (with remove & reorder stub) function renderPlaylistUI() fontListContainer.innerHTML = ''; playlist.forEach((font, idx) => const itemDiv = document.createElement('div'); itemDiv.className = 'font-item'; const nameSpan = document.createElement('span'); nameSpan.className = 'font-name'; nameSpan.innerText = font; nameSpan.style.fontFamily = `'$font', monospace`; // click on font name => jump to that font & pause nameSpan.addEventListener('click', () => if (playlist.length) currentIndex = idx; updateDisplay(); stopAutoRotate(); ); const removeBtn = document.createElement('button'); removeBtn.innerText = '✖️'; removeBtn.className = 'remove-font'; removeBtn.addEventListener('click', (e) => e.stopPropagation(); if (playlist.length <= 1) alert("Cannot remove last font – add another first."); return; playlist.splice(idx, 1); if (currentIndex >= playlist.length) currentIndex = playlist.length - 1; if (currentIndex < 0) currentIndex = 0; renderPlaylistUI(); updateDisplay(); stopAutoRotate(); ); itemDiv.appendChild(nameSpan); itemDiv.appendChild(removeBtn); fontListContainer.appendChild(itemDiv); );