ioniacob commited on
Commit
169bcf4
·
verified ·
1 Parent(s): 2549310

Big IDEAS come from emojis

Browse files
Files changed (1) hide show
  1. index.html +575 -19
index.html CHANGED
@@ -1,19 +1,575 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="es">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Generador de Historias con Emojis</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
9
+ <script>
10
+ tailwind.config = {
11
+ theme: {
12
+ extend: {
13
+ colors: {
14
+ primary: '#8b5cf6',
15
+ 'primary-dark': '#7c3aed',
16
+ secondary: '#f0f9ff',
17
+ dark: '#1e293b',
18
+ accent: '#d8b4fe'
19
+ },
20
+ fontFamily: {
21
+ 'sans': ['Inter', 'sans-serif']
22
+ }
23
+ }
24
+ }
25
+ }
26
+ </script>
27
+ <style>
28
+ @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
29
+
30
+ body {
31
+ font-family: 'Inter', sans-serif;
32
+ overflow-x: hidden;
33
+ background: linear-gradient(135deg, #f0f9ff 0%, #d8b4fe 100%);
34
+ min-height: 100vh;
35
+ }
36
+
37
+ .emoji-card {
38
+ transition: all 0.3s ease;
39
+ box-shadow: 0 4px 6px rgba(139, 92, 246, 0.1);
40
+ }
41
+
42
+ .emoji-card:hover {
43
+ transform: translateY(-5px) scale(1.05);
44
+ box-shadow: 0 10px 15px rgba(139, 92, 246, 0.2);
45
+ z-index: 10;
46
+ }
47
+
48
+ .emoji-grid {
49
+ display: grid;
50
+ grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
51
+ gap: 1rem;
52
+ }
53
+
54
+ @media (min-width: 640px) {
55
+ .emoji-grid {
56
+ grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
57
+ }
58
+ }
59
+
60
+ .emoji-bubble {
61
+ animation: float 5s ease-in-out infinite;
62
+ }
63
+
64
+ @keyframes float {
65
+ 0%, 100% { transform: translateY(0) rotate(0deg); }
66
+ 50% { transform: translateY(-20px) rotate(5deg); }
67
+ }
68
+
69
+ .fade-in {
70
+ animation: fadeIn 0.5s ease-in forwards;
71
+ }
72
+
73
+ @keyframes fadeIn {
74
+ from { opacity: 0; }
75
+ to { opacity: 1; }
76
+ }
77
+
78
+ .story-text {
79
+ background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
80
+ box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
81
+ }
82
+
83
+ .selected-emoji {
84
+ position: relative;
85
+ display: inline-block;
86
+ transition: all 0.3s ease;
87
+ }
88
+
89
+ .selected-emoji::after {
90
+ content: '✕';
91
+ position: absolute;
92
+ top: -8px;
93
+ right: -8px;
94
+ background-color: #ef4444;
95
+ color: white;
96
+ width: 20px;
97
+ height: 20px;
98
+ border-radius: 50%;
99
+ font-size: 10px;
100
+ display: flex;
101
+ align-items: center;
102
+ justify-content: center;
103
+ opacity: 0;
104
+ transition: opacity 0.3s ease;
105
+ cursor: pointer;
106
+ }
107
+
108
+ .selected-emoji:hover::after {
109
+ opacity: 1;
110
+ }
111
+ </style>
112
+ </head>
113
+ <body class="antialiased">
114
+ <!-- Header with title and navigation -->
115
+ <header class="bg-white shadow-lg sticky top-0 z-50">
116
+ <div class="container mx-auto px-4 py-3 flex flex-col md:flex-row justify-between items-center">
117
+ <div class="flex items-center">
118
+ <i class="fa-solid fa-face-smile-beam text-3xl text-primary mr-3"></i>
119
+ <h1 class="text-2xl md:text-3xl font-bold text-dark">EmojiStory Generator</h1>
120
+ </div>
121
+ <div class="mt-2 md:mt-0 flex space-x-2">
122
+ <button id="how-to-use-btn" class="px-4 py-2 rounded-full bg-secondary text-primary hover:bg-primary hover:text-white transition">
123
+ <i class="fas fa-question-circle mr-2"></i>Instrucciones
124
+ </button>
125
+ <button id="api-config-btn" class="px-4 py-2 rounded-full bg-secondary text-primary hover:bg-primary hover:text-white transition">
126
+ <i class="fas fa-cog mr-2"></i>Configurar API
127
+ </button>
128
+ </div>
129
+ </div>
130
+ </header>
131
+
132
+ <!-- Main Content Area -->
133
+ <main class="container mx-auto px-4 py-8">
134
+ <!-- Selected Emoji Bar -->
135
+ <div id="selection-bar" class="bg-white rounded-xl shadow-lg p-4 mb-8 flex flex-wrap items-center min-h-[60px]">
136
+ <h2 class="text-lg font-semibold text-dark mr-4">Tus emojis:</h2>
137
+ <div id="selected-emojis-container" class="flex flex-wrap gap-2">
138
+ <!-- Selected emojis will appear here -->
139
+ </div>
140
+ <button id="clear-selection" class="ml-auto text-sm px-3 py-1 bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200 transition">
141
+ Limpiar selección
142
+ </button>
143
+ </div>
144
+
145
+ <!-- Search Area -->
146
+ <div class="text-center mb-10">
147
+ <div class="relative max-w-2xl mx-auto">
148
+ <i class="fa-solid fa-magnifying-glass absolute left-4 top-1/2 transform -translate-y-1/2 text-gray-400"></i>
149
+ <input
150
+ id="search-input"
151
+ type="text"
152
+ placeholder="Buscar emojis por nombre o categoría..."
153
+ class="w-full py-4 pl-12 pr-40 rounded-full border-2 border-primary focus:border-primary-dark focus:ring-0 text-dark shadow-lg"
154
+ >
155
+ <button id="search-btn" class="absolute right-2 top-1/2 transform -translate-y-1/2 bg-primary hover:bg-primary-dark text-white px-6 py-2 rounded-full transition">
156
+ Buscar
157
+ </button>
158
+ </div>
159
+ </div>
160
+
161
+ <!-- Story Generation Area -->
162
+ <div class="text-center my-12">
163
+ <button id="generate-btn" class="bg-gradient-to-r from-primary to-primary-dark hover:from-primary-dark hover:to-primary text-white font-bold py-4 px-8 rounded-full text-xl transition-all transform hover:scale-105 shadow-xl">
164
+ <i class="fas fa-wand-magic-sparkles mr-2"></i>Crear Historia
165
+ </button>
166
+ </div>
167
+
168
+ <!-- Story Display -->
169
+ <div id="story-container" class="hidden mt-12">
170
+ <div class="story-text bg-white rounded-2xl p-8 mb-6">
171
+ <h2 class="text-2xl font-bold text-center text-dark mb-6">Tu historia generada</h2>
172
+ <div id="story-content" class="text-lg text-gray-700 mb-6 leading-relaxed">
173
+ <!-- Story content will be loaded here -->
174
+ </div>
175
+ <div class="flex flex-wrap justify-center gap-4">
176
+ <button id="copy-story" class="px-5 py-2.5 bg-primary hover:bg-primary-dark text-white rounded-full transition flex items-center">
177
+ <i class="fas fa-copy mr-2"></i> Copiar historia
178
+ </button>
179
+ <button id="share-twitter" class="px-5 py-2.5 bg-blue-500 hover:bg-blue-600 text-white rounded-full transition flex items-center">
180
+ <i class="fab fa-twitter mr-2"></i> Compartir en Twitter
181
+ </button>
182
+ </div>
183
+ </div>
184
+ </div>
185
+
186
+ <!-- Emoji Grid -->
187
+ <div id="emoji-grid" class="emoji-grid">
188
+ <!-- Emojis will be loaded here dynamically -->
189
+ </div>
190
+ </main>
191
+
192
+ <!-- Modal Dialogs -->
193
+ <div id="how-to-use-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
194
+ <div class="bg-white rounded-2xl p-8 max-w-2xl w-full mx-4 max-h-[80vh] overflow-y-auto">
195
+ <div class="flex justify-between items-start mb-6">
196
+ <h3 class="text-2xl font-bold text-dark">Instrucciones de Uso</h3>
197
+ <button id="close-how-to-use" class="text-gray-500 hover:text-gray-700">
198
+ <i class="fas fa-times"></i>
199
+ </button>
200
+ </div>
201
+ <div class="space-y-4">
202
+ <div>
203
+ <h4 class="font-semibold text-primary mb-2">1. Explorar Emojis</h4>
204
+ <p class="text-gray-700">Navega por los emojis organizados en categorías. Puedes ver más usando las flechas de navegación.</p>
205
+ </div>
206
+ <div>
207
+ <h4 class="font-semibold text-primary mb-2">2. Seleccionar Emojis</h4>
208
+ <p class="text-gray-700">Haz clic en cualquier emoji para añadirlo a tu selección en la barra superior. Verás aparecer una X sobre el emoji para poder eliminarlo.</p>
209
+ </div>
210
+ <div>
211
+ <h4 class="font-semibold text-primary mb-2">3. Buscar Emojis</h4>
212
+ <p class="text-gray-700">Usa el buscador central para filtrar emojis por nombre o categoría.</p>
213
+ </div>
214
+ <div>
215
+ <h4 class="font-semibold text-primary mb-2">4. Generar Historia</h4>
216
+ <p class="text-gray-700">Una vez que tengas seleccionados algunos emojis, pulsa "Crear Historia" para generar una historia única basada en tus emojis.</p>
217
+ </div>
218
+ <div>
219
+ <h4 class="font-semibold text-primary mb-2">5. Compartir</h4>
220
+ <p class="text-gray-700">Puedes copiar tu historia o compartirla directamente en Twitter.</p>
221
+ </div>
222
+ </div>
223
+ </div>
224
+ </div>
225
+
226
+ <div id="api-config-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
227
+ <div class="bg-white rounded-2xl p-8 max-w-2xl w-full mx-4 max-h-[80vh] overflow-y-auto">
228
+ <div class="flex justify-between items-start mb-6">
229
+ <h3 class="text-2xl font-bold text-dark">Configuración de API</h3>
230
+ <button id="close-api-config" class="text-gray-500 hover:text-gray-700">
231
+ <i class="fas fa-times"></i>
232
+ </button>
233
+ </div>
234
+ <div class="space-y-6">
235
+ <div>
236
+ <h4 class="font-semibold text-primary mb-2">Configuración de Hugging Face</h4>
237
+ <p class="text-gray-700 mb-4">Para generar historias, necesitas una API key de Hugging Face. Cómo obtenerla:</p>
238
+ <ol class="list-decimal pl-6 space-y-2 mb-4">
239
+ <li>Crear una cuenta en <a href="https://huggingface.co" target="_blank" class="text-primary hover:underline">huggingface.co</a></li>
240
+ <li>Ir a <a href="https://huggingface.co/settings/tokens" target="_blank" class="text-primary hover:underline">Settings → Access Tokens</a></li>
241
+ <li>Generar un nuevo token (seleccionar "Read" como permiso)</li>
242
+ <li>Copiar y pegar el token aquí:</li>
243
+ </ol>
244
+ <div class="flex space-x-3">
245
+ <input
246
+ type="text"
247
+ id="api-key-input"
248
+ placeholder="Pega tu API key de Hugging Face aquí"
249
+ class="flex-1 px-4 py-2 border border-gray-300 rounded-lg"
250
+ >
251
+ <button id="save-api-key" class="px-4 py-2 bg-primary hover:bg-primary-dark text-white rounded-lg">
252
+ Guardar
253
+ </button>
254
+ </div>
255
+ </div>
256
+ <div class="pt-4 border-t border-gray-200">
257
+ <h4 class="font-semibold text-primary mb-2">Alternativas de API</h4>
258
+ <p class="text-gray-700 mb-3">Si Hugging Face no está disponible, puedes usar estos servicios alternativos:</p>
259
+ <ul class="list-disc pl-6 space-y-2">
260
+ <li><a href="https://openrouter.ai" target="_blank" class="text-primary hover:underline">OpenRouter AI</a>: Servicio con múltiples modelos de IA gratuitos.</li>
261
+ <li><a href="https://deepai.org" target="_blank" class="text-primary hover:underline">DeepAI</a>: Plataforma de IA con API gratuita.</li>
262
+ <li><a href="https://beta.openai.com" target="_blank" class="text-primary hover:underline">OpenAI</a>: ChatGPT con API (requiere registro y créditos iniciales gratuitos).</li>
263
+ </ul>
264
+ </div>
265
+ </div>
266
+ </div>
267
+ </div>
268
+
269
+ <script>
270
+ // Emoji database - categorized
271
+ const emojisByCategory = {
272
+ "caras": ["😀", "😁", "😂", "🤣", "😃", "😄", "😅", "😆", "😉", "😊", "😋", "😎", "😍", "😘", "🥰"],
273
+ "manos": ["👋", "🤚", "🖐", "✋", "🖖", "👌", "🤏", "✌️", "🤞", "🤟", "🤘", "🤙", "👈", "👉", "👆"],
274
+ "animales": ["🐶", "🐱", "🐭", "🐹", "🐰", "🦊", "🐻", "🐼", "🐨", "🐯", "🦁", "🐮", "🐷", "🐸", "🐵"],
275
+ "comida": ["🍏", "🍎", "🍐", "🍊", "🍋", "🍌", "🍉", "🍇", "🍓", "🫐", "🍈", "🍒", "🍑", "🥭", "🍍"],
276
+ "naturaleza": ["🌵", "🎄", "🌲", "🌳", "🌴", "🌱", "🌿", "☘️", "🍀", "🎍", "🎋", "🍃", "🍂", "🍁", "🍄"],
277
+ "deportes": ["⚽", "🏀", "🏈", "⚾", "🎾", "🏐", "🏉", "🎱", "🏓", "🏸", "🥊", "🛹", "⛳", "🥏", "🏹"],
278
+ "objetos": ["⌚", "📱", "📲", "💻", "⌨️", "🖥", "🖨", "🖱", "🖲", "🕹", "📞", "☎️", "📟", "📠", "📺"],
279
+ "transporte": ["🚗", "🚕", "🚙", "🚌", "🚎", "🏎", "🚓", "🚑", "🚒", "🚐", "🛻", "🚚", "🚛", "🚜", "🏍"],
280
+ "símbolos": ["💖", "💝", "💘", "❤️", "💓", "💔", "💌", "💋", "💯", "💢", "💥", "💫", "💦", "💨", "🕳️"]
281
+ };
282
+
283
+ // UI elements
284
+ const searchInput = document.getElementById('search-input');
285
+ const searchBtn = document.getElementById('search-btn');
286
+ const emojiGrid = document.getElementById('emoji-grid');
287
+ const selectionBar = document.getElementById('selection-bar');
288
+ const selectedEmojisContainer = document.getElementById('selected-emojis-container');
289
+ const clearSelectionBtn = document.getElementById('clear-selection');
290
+ const generateBtn = document.getElementById('generate-btn');
291
+ const storyContainer = document.getElementById('story-container');
292
+ const storyContent = document.getElementById('story-content');
293
+ const copyStoryBtn = document.getElementById('copy-story');
294
+ const shareTwitterBtn = document.getElementById('share-twitter');
295
+ const howToUseModal = document.getElementById('how-to-use-modal');
296
+ const apiConfigModal = document.getElementById('api-config-modal');
297
+ const howToUseBtn = document.getElementById('how-to-use-btn');
298
+ const apiConfigBtn = document.getElementById('api-config-btn');
299
+ const closeHowToUse = document.getElementById('close-how-to-use');
300
+ const closeApiConfig = document.getElementById('close-api-config');
301
+ const apiKeyInput = document.getElementById('api-key-input');
302
+ const saveApiKeyBtn = document.getElementById('save-api-key');
303
+
304
+ // App state
305
+ let selectedEmojis = [];
306
+ let filteredEmojis = [];
307
+ const apiKey = localStorage.getItem('huggingface_api_key') || 'hf_wF';
308
+
309
+ // Initialize the app
310
+ document.addEventListener('DOMContentLoaded', () => {
311
+ loadEmojis();
312
+ loadSelectedFromUrl();
313
+ setupEventListeners();
314
+ if (!apiKey) {
315
+ showApiConfigModal();
316
+ }
317
+ });
318
+
319
+ // Load emojis from the database
320
+ function loadEmojis() {
321
+ emojiGrid.innerHTML = '';
322
+
323
+ for (const category in emojisByCategory) {
324
+ emojisByCategory[category].forEach(emoji => {
325
+ const emojiElement = createEmojiElement(emoji, category);
326
+ emojiGrid.appendChild(emojiElement);
327
+ });
328
+ }
329
+ }
330
+
331
+ // Create emoji element with animation and hover effects
332
+ function createEmojiElement(emoji, category) {
333
+ const div = document.createElement('div');
334
+ div.className = 'emoji-card bg-white rounded-xl p-4 flex flex-col items-center justify-center cursor-pointer transition-all hover:bg-accent';
335
+ div.innerHTML = `
336
+ <div class="text-4xl mb-1">${emoji}</div>
337
+ <span class="text-xs text-gray-500">${category}</span>
338
+ `;
339
+
340
+ div.addEventListener('click', () => {
341
+ toggleEmojiSelection(emoji);
342
+ div.classList.add('bg-accent');
343
+ });
344
+
345
+ return div;
346
+ }
347
+
348
+ // Toggle emoji selection
349
+ function toggleEmojiSelection(emoji) {
350
+ const index = selectedEmojis.indexOf(emoji);
351
+ if (index === -1) {
352
+ selectedEmojis.push(emoji);
353
+ } else {
354
+ selectedEmojis.splice(index, 1);
355
+ }
356
+
357
+ updateSelectedEmojisDisplay();
358
+ updateUrlParameters();
359
+ }
360
+
361
+ // Update the selected emojis display
362
+ function updateSelectedEmojisDisplay() {
363
+ selectedEmojisContainer.innerHTML = '';
364
+
365
+ if (selectedEmojis.length === 0) {
366
+ selectedEmojisContainer.innerHTML = '<p class="text-gray-500 italic">Selecciona algunos emojis para generar una historia</p>';
367
+ return;
368
+ }
369
+
370
+ selectedEmojis.forEach(emoji => {
371
+ const span = document.createElement('span');
372
+ span.className = 'selected-emoji text-3xl px-2 py-1 bg-white rounded-lg border-2 border-primary transition-all';
373
+ span.textContent = emoji;
374
+
375
+ span.addEventListener('click', (e) => {
376
+ e.stopPropagation();
377
+ toggleEmojiSelection(emoji);
378
+ });
379
+
380
+ selectedEmojisContainer.appendChild(span);
381
+ });
382
+ }
383
+
384
+ // Update URL with selected emojis as parameters
385
+ function updateUrlParameters() {
386
+ const url = new URL(window.location);
387
+ url.searchParams.set('emojis', selectedEmojis.join(''));
388
+ window.history.replaceState({}, '', url);
389
+ }
390
+
391
+ // Load selected emojis from URL parameters
392
+ function loadSelectedFromUrl() {
393
+ const urlParams = new URLSearchParams(window.location.search);
394
+ const emojisParam = urlParams.get('emojis');
395
+
396
+ if (emojisParam) {
397
+ selectedEmojis = Array.from(emojisParam);
398
+ updateSelectedEmojisDisplay();
399
+ }
400
+ }
401
+
402
+ // Filter emojis by name or category
403
+ function filterEmojis(query) {
404
+ emojiGrid.innerHTML = '';
405
+
406
+ const filtered = [];
407
+ query = query.toLowerCase();
408
+
409
+ for (const category in emojisByCategory) {
410
+ emojisByCategory[category].forEach(emoji => {
411
+ if (category.toLowerCase().includes(query) || emoji.toLowerCase().includes(query)) {
412
+ filtered.push({emoji, category});
413
+ }
414
+ });
415
+ }
416
+
417
+ if (filtered.length === 0) {
418
+ emojiGrid.innerHTML = `
419
+ <div class="col-span-full text-center py-12">
420
+ <i class="fas fa-sad-tear text-5xl text-primary mb-4"></i>
421
+ <p class="text-xl text-gray-700">No se encontraron emojis para "${query}"</p>
422
+ <p class="text-gray-500 mt-2">Intenta buscar por nombre o categoría</p>
423
+ </div>
424
+ `;
425
+ } else {
426
+ filtered.forEach(item => {
427
+ const emojiElement = createEmojiElement(item.emoji, item.category);
428
+ emojiGrid.appendChild(emojiElement);
429
+ });
430
+ }
431
+ }
432
+
433
+ // Show API configuration modal
434
+ function showApiConfigModal() {
435
+ apiKeyInput.value = apiKey;
436
+ apiConfigModal.classList.remove('hidden');
437
+ }
438
+
439
+ // Setup all event listeners
440
+ function setupEventListeners() {
441
+ // Search functionality
442
+ searchBtn.addEventListener('click', () => {
443
+ filterEmojis(searchInput.value.trim());
444
+ });
445
+
446
+ searchInput.addEventListener('keypress', (e) => {
447
+ if (e.key === 'Enter') {
448
+ filterEmojis(searchInput.value.trim());
449
+ }
450
+ });
451
+
452
+ // Clear selection
453
+ clearSelectionBtn.addEventListener('click', () => {
454
+ selectedEmojis = [];
455
+ updateSelectedEmojisDisplay();
456
+ updateUrlParameters();
457
+ });
458
+
459
+ // Generate story
460
+ generateBtn.addEventListener('click', async () => {
461
+ if (selectedEmojis.length === 0) {
462
+ alert("Por favor selecciona al menos un emoji primero");
463
+ return;
464
+ }
465
+
466
+ if (!apiKey) {
467
+ alert("Necesitas configurar tu API key primero");
468
+ showApiConfigModal();
469
+ return;
470
+ }
471
+
472
+ try {
473
+ generateBtn.innerHTML = '<i class="fas fa-spinner fa-spin mr-2"></i> Generando...';
474
+ generateBtn.disabled = true;
475
+
476
+ const story = await generateStory(selectedEmojis);
477
+
478
+ storyContent.innerHTML = `<p class="text-lg">${story}</p>`;
479
+ storyContainer.classList.remove('hidden');
480
+
481
+ window.scrollTo({
482
+ top: document.getElementById('story-container').offsetTop - 100,
483
+ behavior: 'smooth'
484
+ });
485
+
486
+ } catch (error) {
487
+ alert(`Error al generar la historia: ${error.message}`);
488
+ console.error(error);
489
+ } finally {
490
+ generateBtn.innerHTML = '<i class="fas fa-wand-magic-sparkles mr-2"></i>Crear Historia';
491
+ generateBtn.disabled = false;
492
+ }
493
+ });
494
+
495
+ // Copy story to clipboard
496
+ copyStoryBtn.addEventListener('click', () => {
497
+ const textarea = document.createElement('textarea');
498
+ textarea.value = storyContent.innerText;
499
+ document.body.appendChild(textarea);
500
+ textarea.select();
501
+ document.execCommand('copy');
502
+ document.body.removeChild(textarea);
503
+
504
+ // Show feedback
505
+ const originalText = copyStoryBtn.innerHTML;
506
+ copyStoryBtn.innerHTML = '<i class="fas fa-check mr-2"></i>Copiada!';
507
+ setTimeout(() => {
508
+ copyStoryBtn.innerHTML = originalText;
509
+ }, 2000);
510
+ });
511
+
512
+ // Share to Twitter
513
+ shareTwitterBtn.addEventListener('click', () => {
514
+ const text = encodeURIComponent(`He creado una historia con emojis! Mira lo que generé:\n\n${storyContent.innerText}\n\n#EmojiStory`);
515
+ const url = `https://twitter.com/intent/tweet?text=${text}`;
516
+ window.open(url, '_blank');
517
+ });
518
+
519
+ // Modal controls
520
+ howToUseBtn.addEventListener('click', () => {
521
+ howToUseModal.classList.remove('hidden');
522
+ });
523
+
524
+ apiConfigBtn.addEventListener('click', () => {
525
+ showApiConfigModal();
526
+ });
527
+
528
+ closeHowToUse.addEventListener('click', () => {
529
+ howToUseModal.classList.add('hidden');
530
+ });
531
+
532
+ closeApiConfig.addEventListener('click', () => {
533
+ apiConfigModal.classList.add('hidden');
534
+ });
535
+
536
+ saveApiKeyBtn.addEventListener('click', () => {
537
+ const key = apiKeyInput.value.trim();
538
+ localStorage.setItem('huggingface_api_key', key);
539
+ apiConfigModal.classList.add('hidden');
540
+ alert("API key guardada con éxito!");
541
+ });
542
+ }
543
+
544
+ // Simulate story generation from an AI API
545
+ async function generateStory(emojis) {
546
+ // This is a simulation of an AI API call
547
+ // In a real implementation, this would be replaced with a fetch to Hugging Face or OpenRouter
548
+
549
+ // Simulate API call delay
550
+ await new Promise(resolve => setTimeout(resolve, 1500));
551
+
552
+ // Map of possible stories for different emoji combinations
553
+ const stories = {
554
+ "😀": "Había una vez un personaje que siempre estaba feliz. Su sonrisa iluminaba todo a su alrededor.",
555
+ "🐶": "Un perrito juguetón corría por el parque persiguiendo una pelota. Era el alma de la fiesta en el parque.",
556
+ "🍕": "La mejor pizza del mundo tenía extra queso y todos los ingredientes que podías imaginar.",
557
+ "😀🐶": "Un niño feliz jugaba con su perrito en el parque. Juntos hacían travesuras.",
558
+ "😀🍕": "Nada hacía más feliz a Juan que una deliciosa pizza recién horneada.",
559
+ "🐶🍕": "El perro miraba con ojos suplicantes cada vez que sus dueños comían pizza.",
560
+ "😀🐶🍕": "María sonreía mientras compartía su pizza con su leal perrito, que meneaba la cola con alegría."
561
+ };
562
+
563
+ // For demo purposes, return a story based on the combination or a default story
564
+ const key = emojis.join('');
565
+ if (stories[key]) {
566
+ return stories[key];
567
+ }
568
+
569
+ // Create a generic story for the selected emojis
570
+ const emojiList = emojis.join(' ');
571
+ return `Esta es una historia especial para tus emojis seleccionados: ${emojiList}. Había una vez un lugar mágico donde estos símbolos cobraban vida. Juntos creaban aventuras increíbles. ¿Te imaginas qué pasaría si ${emojis[0]} conociera a ${emojis[1]}? Seguramente sería una aventura que nunca olvidarías.`;
572
+ }
573
+ </script>
574
+ </body>
575
+ </html>