-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStoryGenerator.html
More file actions
418 lines (361 loc) · 15.3 KB
/
StoryGenerator.html
File metadata and controls
418 lines (361 loc) · 15.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Interactive Story Generator</title>
<!-- Bootstrap 5 CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Font Awesome -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<style>
:root {
--primary-color: #6c5ce7;
--secondary-color: #a29bfe;
--dark-bg: #1a1a1a;
--darker-bg: #141414;
--light-text: #ffffff;
--gray-text: #888888;
--success-color: #00b894;
--warning-color: #fdcb6e;
--danger-color: #d63031;
}
body {
background-color: var(--dark-bg);
color: var(--light-text);
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
min-height: 100vh;
padding: 2rem 0;
}
.container {
max-width: 800px;
}
.story-generator {
background-color: var(--darker-bg);
border-radius: 20px;
padding: 2rem;
box-shadow: 0 0 30px rgba(0,0,0,0.3);
}
.title-section {
text-align: center;
margin-bottom: 2rem;
}
.title-section h1 {
color: var(--primary-color);
font-size: 2.5rem;
font-weight: 700;
margin-bottom: 1rem;
}
.title-section p {
color: var(--gray-text);
font-size: 1.1rem;
}
.form-control, .form-select {
background-color: var(--dark-bg);
border: 2px solid var(--secondary-color);
color: var(--light-text);
padding: 0.8rem;
border-radius: 10px;
transition: all 0.3s ease;
}
.form-control:focus, .form-select:focus {
background-color: var(--dark-bg);
border-color: var(--primary-color);
color: var(--light-text);
box-shadow: 0 0 0 0.25rem rgba(108, 92, 231, 0.25);
}
.input-group-text {
background-color: var(--primary-color);
border: none;
color: var(--light-text);
}
.btn-generate {
background-color: var(--primary-color);
color: var(--light-text);
padding: 1rem 2rem;
border-radius: 10px;
border: none;
font-weight: 600;
transition: all 0.3s ease;
}
.btn-generate:hover {
background-color: var(--secondary-color);
transform: translateY(-2px);
}
.btn-save {
background-color: var(--success-color);
color: var(--light-text);
}
.btn-random {
background-color: var(--warning-color);
color: var(--darker-bg);
}
.story-output {
background-color: var(--dark-bg);
border-radius: 15px;
padding: 2rem;
margin-top: 2rem;
position: relative;
display: none;
}
.story-text {
font-size: 1.2rem;
line-height: 1.8;
margin-bottom: 1.5rem;
}
.story-actions {
display: flex;
gap: 1rem;
margin-top: 1.5rem;
}
.saved-stories {
margin-top: 2rem;
display: none;
}
.story-card {
background-color: var(--dark-bg);
border-radius: 15px;
padding: 1.5rem;
margin-bottom: 1rem;
border: 1px solid var(--secondary-color);
transition: all 0.3s ease;
}
.story-card:hover {
transform: translateY(-5px);
box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}
.loading {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(26, 26, 26, 0.9);
display: none;
justify-content: center;
align-items: center;
z-index: 1000;
}
.loading-spinner {
width: 50px;
height: 50px;
border: 5px solid var(--secondary-color);
border-top: 5px solid var(--primary-color);
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.animate-text {
animation: fadeIn 1s ease-in;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
.tooltip-inner {
background-color: var(--primary-color);
}
.form-floating label {
color: var(--gray-text);
}
.character-count {
position: absolute;
right: 10px;
bottom: 5px;
font-size: 0.8rem;
color: var(--gray-text);
}
</style>
</head>
<body>
<div class="container">
<div class="story-generator">
<div class="title-section">
<h1><i class="fas fa-book-open me-2"></i>Story Generator</h1>
<p>Create your unique story by filling in the details below!</p>
</div>
<form id="storyForm" class="mb-4">
<div class="row g-3">
<div class="col-md-6">
<div class="form-floating">
<input type="text" class="form-control" id="characterName" placeholder="Character Name" required>
<label for="characterName">Character Name</label>
</div>
</div>
<div class="col-md-6">
<div class="form-floating">
<input type="text" class="form-control" id="place" placeholder="Place" required>
<label for="place">Place</label>
</div>
</div>
<div class="col-md-6">
<div class="form-floating">
<input type="text" class="form-control" id="object" placeholder="Object" required>
<label for="object">Object</label>
</div>
</div>
<div class="col-md-6">
<div class="form-floating">
<input type="text" class="form-control" id="action" placeholder="Action" required>
<label for="action">Action</label>
</div>
</div>
</div>
<div class="d-flex justify-content-center gap-3 mt-4">
<button type="button" class="btn btn-random" id="randomizeBtn">
<i class="fas fa-random me-2"></i>Randomize
</button>
<button type="submit" class="btn btn-generate">
<i class="fas fa-magic me-2"></i>Generate Story
</button>
</div>
</form>
<div class="story-output" id="storyOutput">
<h3 class="mb-4">Your Story</h3>
<div class="story-text" id="storyText"></div>
<div class="story-actions">
<button class="btn btn-save" id="saveStoryBtn">
<i class="fas fa-save me-2"></i>Save Story
</button>
<button class="btn btn-warning" id="shareStoryBtn">
<i class="fas fa-share-alt me-2"></i>Share
</button>
</div>
</div>
<div class="saved-stories" id="savedStories">
<h3 class="mb-4">Saved Stories</h3>
<div id="storiesList"></div>
</div>
</div>
</div>
<div class="loading" id="loading">
<div class="loading-spinner"></div>
</div>
<!-- Bootstrap 5 JS and Popper.js -->
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.10.2/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.min.js"></script>
<script>
class StoryGenerator {
constructor() {
this.storyTemplates = [
"Once upon a time, {name} ventured into {place} carrying a mysterious {object}. Suddenly, they decided to {action}, which led to an unexpected adventure!",
"In the heart of {place}, {name} discovered a magical {object}. Without hesitation, they began to {action}, changing their destiny forever.",
"The legend speaks of {name}, who journeyed to {place} with nothing but a {object}. There, they would {action}, becoming a hero of ancient tales.",
"Deep within {place}, {name} found themselves face to face with a legendary {object}. In that moment, they chose to {action}, making history.",
"When {name} arrived at {place}, no one expected them to bring a {object}. Yet, as they began to {action}, everything changed in an instant."
];
this.randomWords = {
names: ["Luna", "Atlas", "Nova", "Orion", "Aurora", "Phoenix", "Sage", "Storm"],
places: ["Mystic Forest", "Crystal Cave", "Cloud City", "Ancient Temple", "Starlit Valley"],
objects: ["Golden Compass", "Magic Mirror", "Ancient Scroll", "Enchanted Sword", "Time Crystal"],
actions: ["dance with shadows", "whisper to stars", "unlock ancient secrets", "challenge destiny", "weave spells"]
};
this.savedStories = JSON.parse(localStorage.getItem('savedStories')) || [];
this.setupEventListeners();
this.initializeTooltips();
this.showSavedStories();
}
setupEventListeners() {
document.getElementById('storyForm').addEventListener('submit', (e) => {
e.preventDefault();
this.generateStory();
});
document.getElementById('randomizeBtn').addEventListener('click', () => this.randomizeInputs());
document.getElementById('saveStoryBtn').addEventListener('click', () => this.saveStory());
document.getElementById('shareStoryBtn').addEventListener('click', () => this.shareStory());
}
initializeTooltips() {
const tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
tooltipTriggerList.map(function (tooltipTriggerEl) {
return new bootstrap.Tooltip(tooltipTriggerEl);
});
}
showLoading(show = true) {
document.getElementById('loading').style.display = show ? 'flex' : 'none';
}
getRandomElement(array) {
return array[Math.floor(Math.random() * array.length)];
}
randomizeInputs() {
document.getElementById('characterName').value = this.getRandomElement(this.randomWords.names);
document.getElementById('place').value = this.getRandomElement(this.randomWords.places);
document.getElementById('object').value = this.getRandomElement(this.randomWords.objects);
document.getElementById('action').value = this.getRandomElement(this.randomWords.actions);
}
async generateStory() {
this.showLoading();
const name = document.getElementById('characterName').value;
const place = document.getElementById('place').value;
const object = document.getElementById('object').value;
const action = document.getElementById('action').value;
// Simulate API call delay
await new Promise(resolve => setTimeout(resolve, 1000));
const template = this.getRandomElement(this.storyTemplates);
const story = template
.replace('{name}', name)
.replace('{place}', place)
.replace('{object}', object)
.replace('{action}', action);
const storyOutput = document.getElementById('storyOutput');
const storyText = document.getElementById('storyText');
storyOutput.style.display = 'block';
storyText.textContent = story;
storyText.classList.add('animate-text');
this.showLoading(false);
}
saveStory() {
const storyText = document.getElementById('storyText').textContent;
const timestamp = new Date().toLocaleString();
this.savedStories.unshift({
text: storyText,
timestamp: timestamp
});
localStorage.setItem('savedStories', JSON.stringify(this.savedStories));
this.showSavedStories();
}
showSavedStories() {
const savedStoriesContainer = document.getElementById('savedStories');
const storiesList = document.getElementById('storiesList');
if (this.savedStories.length > 0) {
savedStoriesContainer.style.display = 'block';
storiesList.innerHTML = this.savedStories.map((story, index) => `
<div class="story-card">
<p class="mb-2">${story.text}</p>
<small class="text-muted">Created: ${story.timestamp}</small>
<button class="btn btn-danger btn-sm float-end" onclick="storyGenerator.deleteStory(${index})">
<i class="fas fa-trash"></i>
</button>
</div>
`).join('');
} else {
savedStoriesContainer.style.display = 'none';
}
}
deleteStory(index) {
this.savedStories.splice(index, 1);
localStorage.setItem('savedStories', JSON.stringify(this.savedStories));
this.showSavedStories();
}
shareStory() {
const story = document.getElementById('storyText').textContent;
if (navigator.share) {
navigator.share({
title: 'My Generated Story',
text: story
}).catch(console.error);
} else {
// Fallback copy to clipboard
navigator.clipboard.writeText(story).then(() => {
alert('Story copied to clipboard!');
});
}
}
}
// Initialize the Story Generator
const storyGenerator = new StoryGenerator();
</script>
</body>
</html>