|
<!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> |
|
|
|
document.getElementById('emoji').addEventListener('input', function(e) { |
|
let value = e.target.value; |
|
|
|
const emojiRegex = /[\p{Emoji}]/gu; |
|
const emojis = value.match(emojiRegex); |
|
|
|
if (emojis) { |
|
e.target.value = emojis.join(''); |
|
} else { |
|
e.target.value = ''; |
|
} |
|
|
|
|
|
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; |
|
} |
|
|
|
|
|
document.getElementById('loading').style.display = 'block'; |
|
document.getElementById('emoji-display').innerHTML = ''; |
|
|
|
|
|
const formData = new FormData(this); |
|
|
|
|
|
fetch('/generate', { |
|
method: 'POST', |
|
body: formData |
|
}) |
|
.then(response => response.json()) |
|
.then(data => { |
|
|
|
document.getElementById('loading').style.display = 'none'; |
|
|
|
if (data.error) { |
|
document.getElementById('emoji-display').innerHTML = `<div class="error-message">${data.error}</div>`; |
|
} else { |
|
|
|
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); |
|
|
|
|
|
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> |