Spaces:
Running
Running
File size: 18,898 Bytes
a555746 |
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 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TMKOC Quotes API Demo</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 20px;
}
.container {
max-width: 1200px;
margin: 0 auto;
}
.header {
text-align: center;
margin-bottom: 40px;
animation: fadeInDown 1s ease-out;
}
.header h1 {
color: white;
font-size: 3rem;
margin-bottom: 10px;
text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}
.header p {
color: rgba(255,255,255,0.9);
font-size: 1.2rem;
margin-bottom: 20px;
}
.api-info {
background: rgba(255,255,255,0.1);
backdrop-filter: blur(10px);
border-radius: 15px;
padding: 15px 25px;
border: 1px solid rgba(255,255,255,0.2);
display: inline-block;
}
.api-info code {
color: #FFD700;
font-weight: bold;
}
.demo-section {
background: rgba(255,255,255,0.95);
border-radius: 20px;
padding: 30px;
margin-bottom: 30px;
box-shadow: 0 20px 40px rgba(0,0,0,0.1);
animation: fadeInUp 1s ease-out;
}
.section-title {
font-size: 1.8rem;
color: #333;
margin-bottom: 20px;
display: flex;
align-items: center;
gap: 10px;
}
.controls {
display: flex;
flex-wrap: wrap;
gap: 15px;
margin-bottom: 25px;
}
.btn {
padding: 12px 24px;
border: none;
border-radius: 25px;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
display: flex;
align-items: center;
gap: 8px;
box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}
.btn-primary {
background: linear-gradient(45deg, #FF6B6B, #FF8E53);
color: white;
}
.btn-secondary {
background: linear-gradient(45deg, #4ECDC4, #44A08D);
color: white;
}
.btn-accent {
background: linear-gradient(45deg, #A8E6CF, #88D8A3);
color: #333;
}
.btn:hover {
transform: translateY(-2px);
box-shadow: 0 8px 25px rgba(0,0,0,0.2);
}
.input-group {
display: flex;
gap: 10px;
margin-bottom: 15px;
flex-wrap: wrap;
}
.form-input {
flex: 1;
min-width: 200px;
padding: 12px 16px;
border: 2px solid #e0e0e0;
border-radius: 25px;
font-size: 1rem;
transition: all 0.3s ease;
}
.form-input:focus {
outline: none;
border-color: #667eea;
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}
.quote-display {
background: linear-gradient(135deg, #667eea, #764ba2);
color: white;
padding: 30px;
border-radius: 15px;
margin: 20px 0;
text-align: center;
min-height: 150px;
display: flex;
flex-direction: column;
justify-content: center;
position: relative;
overflow: hidden;
}
.quote-display::before {
content: '"';
font-size: 8rem;
position: absolute;
top: -20px;
left: 20px;
opacity: 0.1;
font-family: serif;
}
.quote-text {
font-size: 1.4rem;
line-height: 1.6;
margin-bottom: 15px;
font-style: italic;
}
.quote-author {
font-size: 1.1rem;
font-weight: 600;
opacity: 0.9;
}
.quote-tags {
margin-top: 10px;
}
.tag {
display: inline-block;
background: rgba(255,255,255,0.2);
padding: 4px 12px;
border-radius: 15px;
font-size: 0.8rem;
margin: 2px;
}
.results-container {
max-height: 400px;
overflow-y: auto;
border: 1px solid #e0e0e0;
border-radius: 10px;
padding: 15px;
}
.quote-item {
background: #f8f9fa;
padding: 15px;
border-radius: 8px;
margin-bottom: 10px;
border-left: 4px solid #667eea;
}
.loading {
text-align: center;
padding: 40px;
color: #666;
}
.spinner {
display: inline-block;
width: 30px;
height: 30px;
border: 3px solid #f3f3f3;
border-top: 3px solid #667eea;
border-radius: 50%;
animation: spin 1s linear infinite;
margin-bottom: 10px;
}
.error {
background: #ffebee;
color: #c62828;
padding: 15px;
border-radius: 8px;
border-left: 4px solid #c62828;
}
.endpoints {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 20px;
margin-top: 20px;
}
.endpoint-card {
background: #f8f9fa;
padding: 20px;
border-radius: 12px;
border: 1px solid #e0e0e0;
}
.endpoint-method {
background: #28a745;
color: white;
padding: 4px 8px;
border-radius: 4px;
font-size: 0.8rem;
font-weight: bold;
margin-bottom: 8px;
display: inline-block;
}
.endpoint-url {
font-family: 'Courier New', monospace;
background: #e9ecef;
padding: 8px 12px;
border-radius: 6px;
font-size: 0.9rem;
word-break: break-all;
}
@keyframes fadeInDown {
from {
opacity: 0;
transform: translateY(-30px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes fadeInUp {
from {
opacity: 0;
transform: translateY(30px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
@media (max-width: 768px) {
.header h1 {
font-size: 2rem;
}
.controls {
flex-direction: column;
}
.input-group {
flex-direction: column;
}
.form-input {
min-width: unset;
}
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1><i class="fas fa-quote-left"></i> TMKOC Quotes API</h1>
<p>Explore quotes from the beloved Indian sitcom Taarak Mehta Ka Ooltah Chashmah</p>
<div class="api-info">
<i class="fas fa-link"></i> Base URL: <code>https://tmkoc-quotes-api.onrender.com</code>
</div>
</div>
<!-- Random Quote Section -->
<div class="demo-section">
<h2 class="section-title">
<i class="fas fa-random"></i>
Random Quotes
</h2>
<div class="controls">
<button class="btn btn-primary" onclick="getRandomQuote()">
<i class="fas fa-dice"></i> Get Random Quote
</button>
<button class="btn btn-secondary" onclick="getMultipleQuotes()">
<i class="fas fa-layer-group"></i> Get 3 Random Quotes
</button>
</div>
<div id="randomQuoteDisplay" class="quote-display" style="display: none;">
<div class="quote-text" id="randomQuoteText"></div>
<div class="quote-author" id="randomQuoteAuthor"></div>
<div class="quote-tags" id="randomQuoteTags"></div>
</div>
<div id="multipleQuotesDisplay" class="results-container" style="display: none;"></div>
</div>
<!-- Character Filter Section -->
<div class="demo-section">
<h2 class="section-title">
<i class="fas fa-user"></i>
Filter by Character
</h2>
<div class="controls">
<button class="btn btn-accent" onclick="getQuotesByCharacter('Jethalal')">Jethalal</button>
<button class="btn btn-accent" onclick="getQuotesByCharacter('Daya')">Daya</button>
<button class="btn btn-accent" onclick="getQuotesByCharacter('Tapu')">Tapu</button>
<button class="btn btn-accent" onclick="getQuotesByCharacter('Popatlal')">Popatlal</button>
</div>
<div class="input-group">
<input type="text" class="form-input" id="characterInput" placeholder="Enter character name...">
<button class="btn btn-primary" onclick="getQuotesByCharacterInput()">
<i class="fas fa-search"></i> Search
</button>
</div>
<div id="characterQuotesDisplay" class="results-container" style="display: none;"></div>
</div>
<!-- Search Section -->
<div class="demo-section">
<h2 class="section-title">
<i class="fas fa-search"></i>
Search Quotes
</h2>
<div class="input-group">
<input type="text" class="form-input" id="searchAuthor" placeholder="Author name (optional)">
<input type="text" class="form-input" id="searchText" placeholder="Search text in quotes">
<button class="btn btn-primary" onclick="searchQuotes()">
<i class="fas fa-search"></i> Search
</button>
</div>
<div id="searchResults" class="results-container" style="display: none;"></div>
</div>
<!-- API Endpoints Reference -->
<div class="demo-section">
<h2 class="section-title">
<i class="fas fa-code"></i>
API Endpoints Reference
</h2>
<div class="endpoints">
<div class="endpoint-card">
<div class="endpoint-method">GET</div>
<div class="endpoint-url">/v1/quotes</div>
<p>Get a random quote</p>
</div>
<div class="endpoint-card">
<div class="endpoint-method">GET</div>
<div class="endpoint-url">/v1/quotes/{number}</div>
<p>Get multiple random quotes</p>
</div>
<div class="endpoint-card">
<div class="endpoint-method">GET</div>
<div class="endpoint-url">/v1/quotes/character/{author}</div>
<p>Get quotes by character</p>
</div>
<div class="endpoint-card">
<div class="endpoint-method">GET</div>
<div class="endpoint-url">/v1/quotes/tag/{tag}</div>
<p>Get quotes by tag/category</p>
</div>
<div class="endpoint-card">
<div class="endpoint-method">GET</div>
<div class="endpoint-url">/v1/quotes/search?author=X&text=Y</div>
<p>Search quotes by author and/or text</p>
</div>
</div>
</div>
</div>
<script>
const API_BASE = 'https://tmkoc-quotes-api.onrender.com/v1';
function showLoading(containerId) {
const container = document.getElementById(containerId);
container.style.display = 'block';
container.innerHTML = `
<div class="loading">
<div class="spinner"></div>
<p>Loading quotes...</p>
</div>
`;
}
function showError(containerId, message) {
const container = document.getElementById(containerId);
container.style.display = 'block';
container.innerHTML = `
<div class="error">
<i class="fas fa-exclamation-triangle"></i>
Error: ${message}
</div>
`;
}
function displaySingleQuote(quote) {
document.getElementById('randomQuoteText').textContent = quote.quote;
document.getElementById('randomQuoteAuthor').textContent = `— ${quote.author}`;
const tagsContainer = document.getElementById('randomQuoteTags');
if (quote.tags && quote.tags.length > 0) {
tagsContainer.innerHTML = quote.tags.map(tag =>
`<span class="tag">#${tag}</span>`
).join('');
} else {
tagsContainer.innerHTML = '';
}
document.getElementById('randomQuoteDisplay').style.display = 'flex';
}
function displayMultipleQuotes(quotes, containerId) {
const container = document.getElementById(containerId);
container.style.display = 'block';
container.innerHTML = quotes.map(quote => `
<div class="quote-item">
<div style="font-size: 1.1rem; margin-bottom: 8px; font-style: italic;">
"${quote.quote}"
</div>
<div style="font-weight: 600; color: #667eea;">
— ${quote.author}
</div>
${quote.tags ? `
<div style="margin-top: 8px;">
${quote.tags.map(tag => `<span class="tag" style="background: #e3f2fd; color: #1976d2;">#${tag}</span>`).join('')}
</div>
` : ''}
</div>
`).join('');
}
async function makeAPICall(endpoint) {
const response = await fetch(`${API_BASE}${endpoint}`);
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
return await response.json();
}
async function getRandomQuote() {
try {
document.getElementById('multipleQuotesDisplay').style.display = 'none';
showLoading('randomQuoteDisplay');
const quotes = await makeAPICall('/quotes');
document.getElementById('randomQuoteDisplay').style.display = 'none';
displaySingleQuote(quotes[0]);
} catch (error) {
showError('randomQuoteDisplay', error.message);
}
}
async function getMultipleQuotes() {
try {
document.getElementById('randomQuoteDisplay').style.display = 'none';
showLoading('multipleQuotesDisplay');
const quotes = await makeAPICall('/quotes/3');
displayMultipleQuotes(quotes, 'multipleQuotesDisplay');
} catch (error) {
showError('multipleQuotesDisplay', error.message);
}
}
async function getQuotesByCharacter(character) {
try {
showLoading('characterQuotesDisplay');
const quotes = await makeAPICall(`/quotes/character/${encodeURIComponent(character)}`);
displayMultipleQuotes(quotes, 'characterQuotesDisplay');
} catch (error) {
showError('characterQuotesDisplay', error.message);
}
}
async function getQuotesByCharacterInput() {
const character = document.getElementById('characterInput').value.trim();
if (!character) {
alert('Please enter a character name');
return;
}
await getQuotesByCharacter(character);
}
async function searchQuotes() {
const author = document.getElementById('searchAuthor').value.trim();
const text = document.getElementById('searchText').value.trim();
if (!author && !text) {
alert('Please enter either author name or search text');
return;
}
try {
showLoading('searchResults');
const params = new URLSearchParams();
if (author) params.append('author', author);
if (text) params.append('text', text);
const quotes = await makeAPICall(`/quotes/search?${params.toString()}`);
displayMultipleQuotes(quotes, 'searchResults');
} catch (error) {
showError('searchResults', error.message);
}
}
// Add enter key support for inputs
document.getElementById('characterInput').addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
getQuotesByCharacterInput();
}
});
document.getElementById('searchAuthor').addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
searchQuotes();
}
});
document.getElementById('searchText').addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
searchQuotes();
}
});
// Load a random quote on page load
window.addEventListener('load', getRandomQuote);
</script>
</body>
</html> |