creepmoji / templates /index.html
theminji's picture
first commit
cea757d
<!DOCTYPE html>
<html>
<head>
<title>Creepmoji</title>
<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div class="container">
<h1>Creepmoji</h1>
<form id="emoji-form">
<label for="emoji">Enter Emoji:</label>
<input type="text" id="emoji" name="emoji" maxlength="2" placeholder="πŸ˜€" autocomplete="off">
<button type="submit">Generate Creepmoji</button>
</form>
<div id="result-container">
<div id="loading">
<div class="loading-text">Creating your masterpiece...</div>
<div class="loading-bar"></div>
</div>
<div id="emoji-display"></div>
</div>
</div>
<script>
// Client-side emoji validation
document.getElementById('emoji').addEventListener('input', function(e) {
let value = e.target.value;
// Keep only emoji characters
const emojiRegex = /[\p{Emoji}]/gu;
const emojis = value.match(emojiRegex);
if (emojis) {
e.target.value = emojis.join('');
} else {
e.target.value = '';
}
// Limit to a single emoji
if (e.target.value.length > 2) {
e.target.value = e.target.value.slice(0, 2);
}
});
document.getElementById('emoji-form').addEventListener('submit', function(e) {
e.preventDefault();
const emoji = document.getElementById('emoji').value.trim();
if (!emoji) {
document.getElementById('emoji-display').innerHTML = '<div class="error-message">Please enter an emoji.</div>';
return;
}
// Show loading indicator
document.getElementById('loading').style.display = 'block';
document.getElementById('emoji-display').innerHTML = '';
// Get form data
const formData = new FormData(this);
// Send AJAX request
fetch('/generate', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
// Hide loading indicator
document.getElementById('loading').style.display = 'none';
if (data.error) {
document.getElementById('emoji-display').innerHTML = `<div class="error-message">${data.error}</div>`;
} else {
// Display the image with a fade-in effect
const img = document.createElement('img');
img.src = data.image;
img.className = 'emoji-result';
img.alt = 'Creepy Emoji';
img.style.opacity = '0';
document.getElementById('emoji-display').appendChild(img);
// Trigger fade-in effect
setTimeout(() => {
img.style.transition = 'opacity 0.6s ease';
img.style.opacity = '1';
}, 50);
}
})
.catch(error => {
document.getElementById('loading').style.display = 'none';
document.getElementById('emoji-display').innerHTML = `<div class="error-message">Error: ${error}</div>`;
});
});
</script>
</body>
</html>