glitchcraft/app/app.js
Ole-Morten Duesund 7b0a3746d5 Enhance mobile experience and add zalgo text variants
Mobile improvements:
- Comprehensive responsive design for 320px-4K screens
- Touch-optimized controls with larger touch targets
- iOS zoom prevention with 16px font sizes on inputs
- Swipe-friendly interface with better spacing
- Portrait and landscape orientation support
- Enhanced accessibility with better contrast and sizes

Zalgo variants implemented:
- Full Chaos: Balanced corruption (default)
- Above Only: Marks above characters only
- Below Only: Marks below characters only
- Middle Only: Overlaying marks
- Mini Glitch: Subtle corruption
- Heavy Corruption: Maximum chaos overload

UI enhancements:
- Added corruption mode selector dropdown
- Reorganized controls into responsive groups
- Improved mobile control layouts
- Better visual hierarchy and spacing

Code quality:
- Fixed ESLint/Prettier indentation conflict
- Enhanced ZalgoGenerator with mode parameter
- Added event handlers for mode selection
- Comprehensive mobile CSS with multiple breakpoints

Documentation:
- Created comprehensive README with zalgo examples
- Documented all corruption modes with examples
- Added development and deployment instructions

The app now provides a perfect mobile experience with
diverse zalgo corruption options for creative text effects.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-18 20:30:05 +02:00

126 lines
3.4 KiB
JavaScript

/**
* Main application logic for GlitchCraft
* Handles UI interactions and PWA registration
*/
/* global ZalgoGenerator */
// Initialize zalgo generator
const zalgo = new ZalgoGenerator();
// DOM elements
const inputText = document.getElementById('inputText');
const outputText = document.getElementById('outputText');
const intensitySlider = document.getElementById('intensity');
const intensityValue = document.getElementById('intensityValue');
const zalgoModeSelect = document.getElementById('zalgoMode');
const clearBtn = document.getElementById('clearBtn');
const copyNotification = document.getElementById('copyNotification');
/**
* Update the corrupted text output
*/
function updateOutput() {
const text = inputText.value;
const intensity = parseInt(intensitySlider.value);
const mode = zalgoModeSelect.value;
if (text) {
outputText.value = zalgo.generate(text, intensity, mode);
} else {
outputText.value = '';
}
}
/**
* Copy text to clipboard and show notification
*/
async function copyToClipboard() {
if (!outputText.value) return;
try {
await navigator.clipboard.writeText(outputText.value);
// Show copy notification
copyNotification.classList.add('show');
setTimeout(() => {
copyNotification.classList.remove('show');
}, 2000);
} catch (err) {
// Fallback for older browsers
outputText.select();
document.execCommand('copy');
// Show copy notification
copyNotification.classList.add('show');
setTimeout(() => {
copyNotification.classList.remove('show');
}, 2000);
}
}
/**
* Clear all text fields
*/
function clearAll() {
inputText.value = '';
outputText.value = '';
inputText.focus();
}
// Event listeners
inputText.addEventListener('input', updateOutput);
intensitySlider.addEventListener('input', () => {
intensityValue.textContent = intensitySlider.value;
updateOutput();
});
zalgoModeSelect.addEventListener('change', updateOutput);
outputText.addEventListener('click', copyToClipboard);
clearBtn.addEventListener('click', clearAll);
// Handle keyboard shortcuts
document.addEventListener('keydown', e => {
// Ctrl/Cmd + K to clear
if ((e.ctrlKey || e.metaKey) && e.key === 'k') {
e.preventDefault();
clearAll();
}
// Ctrl/Cmd + C when output is focused to copy
if ((e.ctrlKey || e.metaKey) && e.key === 'c' && document.activeElement === outputText) {
copyToClipboard();
}
});
// Register service worker for PWA functionality
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker
.register('sw.js')
.then(registration => {
console.log('Service Worker registered successfully:', registration.scope);
})
.catch(error => {
console.log('Service Worker registration failed:', error);
});
});
}
// Handle install prompt for PWA
window.addEventListener('beforeinstallprompt', e => {
// Prevent the mini-infobar from appearing on mobile
e.preventDefault();
// Store the event so it can be triggered later if needed
// Currently not used but kept for potential future install button
window.deferredPrompt = e;
console.log('Install prompt ready');
});
// Focus input on load
window.addEventListener('load', () => {
inputText.focus();
});