Spaces:
Running
Running
File size: 40,563 Bytes
426ffb5 |
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 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Anime Recommendation System</title>
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@300;400;500;700&family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="{{ url_for('static', filename='greentheme.css') }}" id="theme-green" disabled>
<link rel="stylesheet" href="{{ url_for('static', filename='orangetheme.css') }}" id="theme-orange" disabled>
<link rel="stylesheet" href="{{ url_for('static', filename='purpletheme.css') }}" id="theme-purple">
<link rel="preconnect" href="https://www.googletagmanager.com">
<link rel="preconnect" href="https://www.google-analytics.com">
<style>
/* Critical CSS - Sayfa yükleme sırasında görünümü engellemek için */
html {
visibility: hidden;
opacity: 0;
transition: opacity 0.3s ease-in-out;
}
html.loaded {
visibility: visible;
opacity: 1;
}
/* Loading screen */
.page-loader {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
display: flex;
justify-content: center;
align-items: center;
z-index: 9999;
opacity: 1;
transition: opacity 0.5s ease-out;
}
.page-loader.hidden {
opacity: 0;
pointer-events: none;
}
.loader-spinner {
width: 50px;
height: 50px;
border: 3px solid rgba(255, 255, 255, 0.3);
border-top: 3px solid white;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
/* Preload critical animations */
.preload-animations {
position: absolute;
top: -9999px;
left: -9999px;
opacity: 0;
pointer-events: none;
}
/* Theme Switcher Styles */
.theme-switcher {
position: fixed;
top: 20px;
right: 20px;
z-index: 1000;
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
border-radius: 15px;
padding: 8px;
border: 1px solid rgba(255, 255, 255, 0.2);
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}
.theme-switcher-toggle {
background: none;
border: none;
font-size: 20px;
cursor: pointer;
padding: 8px;
border-radius: 10px;
transition: all 0.3s ease;
color: inherit;
}
.theme-switcher-toggle:hover {
background: rgba(255, 255, 255, 0.1);
transform: scale(1.1);
}
.theme-options {
position: absolute;
top: 100%;
right: 0;
margin-top: 10px;
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(15px);
border-radius: 15px;
padding: 10px;
border: 1px solid rgba(255, 255, 255, 0.2);
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
opacity: 0;
transform: translateY(-10px);
pointer-events: none;
transition: all 0.3s ease;
min-width: 150px;
}
.theme-options.show {
opacity: 1;
transform: translateY(0);
pointer-events: all;
}
.theme-option {
display: flex;
align-items: center;
gap: 10px;
padding: 8px 12px;
border-radius: 10px;
cursor: pointer;
transition: all 0.3s ease;
margin: 2px 0;
font-size: 14px;
font-weight: 500;
}
.theme-option:hover {
background: rgba(255, 255, 255, 0.1);
transform: translateX(3px);
}
.theme-option.active {
background: rgba(255, 255, 255, 0.2);
border: 1px solid rgba(255, 255, 255, 0.3);
}
.theme-color {
width: 16px;
height: 16px;
border-radius: 50%;
border: 2px solid rgba(255, 255, 255, 0.3);
transition: all 0.3s ease;
}
.theme-option.active .theme-color {
border-color: rgba(255, 255, 255, 0.8);
box-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}
.theme-purple .theme-color {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.theme-green .theme-color {
background: linear-gradient(45deg, #4caf50, #2e7d32);
}
.theme-orange .theme-color {
background: linear-gradient(45deg, #ffa500, #ff4500);
}
.product-hunt {
position: fixed;
top: 17px;
right: 235px;
z-index: 1000;
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
border-radius: 15px;
padding: 8px;
border: 1px solid rgba(255, 255, 255, 0.2);
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}
/* Mobile responsive */
@media (max-width: 768px) {
.theme-switcher {
top: 15px;
right: 15px;
padding: 6px;
}
.theme-switcher-toggle {
font-size: 18px;
padding: 6px;
}
.theme-options {
right: -20px;
min-width: 130px;
}
.theme-option {
font-size: 13px;
padding: 6px 10px;
}
}
</style>
</head>
<body>
<!-- Page Loader -->
<div class="page-loader" id="pageLoader">
<div class="loader-spinner"></div>
</div>
<!-- Preload animations -->
<div class="preload-animations">
<div class="theme-switcher-toggle"></div>
<div class="theme-option"></div>
<div class="anime-card"></div>
</div>
<div class="theme-switcher">
<button class="theme-switcher-toggle" onclick="toggleThemeOptions()">🎨</button>
<div class="theme-options" id="themeOptions">
<div class="theme-option theme-purple active" onclick="changeTheme('purple')">
<div class="theme-color"></div>
<span>Purple</span>
</div>
<div class="theme-option theme-green" onclick="changeTheme('green')">
<div class="theme-color"></div>
<span>Green</span>
</div>
<div class="theme-option theme-orange" onclick="changeTheme('orange')">
<div class="theme-color"></div>
<span>Orange</span>
</div>
</div>
</div>
<div class="social-button">
<a href="/chat" class="social-btn">
<span class="social-icon">💬</span>
<span class="social-text">Social</span>
</a>
</div>
<button class="back-button" onclick="showFavorites()">← Back to Favorites</button>
<div class="container">
<div class="header">
<h1>Just one episode...</h1>
<p>Discover your next favorite anime</p>
</div>
<!-- Favorites Section -->
<div class="favorites-section" id="favoritesSection">
<h2 class="section-title">Select Your Favorite Animes</h2>
<div class="search-container" style="position: relative;">
<input type="text" class="search-input" id="animeSearch" placeholder="Search for an anime..." autocomplete="off">
<button class="blacklist-button" id="blacklistButton" onclick="openBlacklistModal()" title="Manage Blacklist">
🗑️
<span class="blacklist-counter" id="blacklistCounter">0</span>
</button>
<div class="blacklist-modal" id="blacklistModal">
<div class="blacklist-content">
<div class="blacklist-header">
<h2 class="blacklist-title">Blacklisted Animes</h2>
<button class="blacklist-close" onclick="closeBlacklistModal()">×</button>
</div>
<div class="blacklist-list" id="blacklistList"></div>
<div class="blacklist-actions">
<button class="clear-blacklist-btn" onclick="clearBlacklist()">Clear All Blacklist</button>
</div>
</div>
</div>
<!-- Modern SVG ikonu -->
<svg class="search-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
style="width: 20px; height: 20px; position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: #888;">
<circle cx="11" cy="11" r="8" />
<line x1="21" y1="21" x2="16.65" y2="16.65" />
</svg>
<div class="anime-dropdown" id="animeDropdown"></div>
</div>
<div class="favorites-list" id="favoritesList">
<div class="empty-state">No favorites selected yet. Search and add some animes!</div>
</div>
<div class="action-buttons">
<button class="btn btn-primary" onclick="getRecommendations()">Get Recommendations</button>
<button class="btn btn-secondary" onclick="clearFavorites()">Clear All</button>
</div>
</div>
<!-- Recommendations Section -->
<div class="recommendations-section" id="recommendationsSection">
<div class="favorites-section">
<h2 class="section-title">Recommended for You</h2>
<div class="filter-container">
<div class="filter-buttons">
<button class="filter-btn" data-filter="show_sequels" onclick="toggleFilter(this)">Sequels</button>
<button class="filter-btn active" data-filter="show_movies" onclick="toggleFilter(this)">Movies</button>
<button class="filter-btn active" data-filter="show_tv" onclick="toggleFilter(this)">TV Series</button>
<button class="filter-btn" data-filter="show_ova" onclick="toggleFilter(this)">OVA/ONA/SPECIAL</button>
</div>
<button class="apply-filters-btn" onclick="applyFilters()">Apply Filters</button>
</div>
<div class="recommendations-grid" id="recommendationsGrid"></div>
</div>
</div>
<div class="about-section" id="aboutSection">
<div class="about-content">
<div class="about-item">
<h3>About the Model</h3>
<p>Despite its strong performance, I couldn't find any anime recommendation websites using a BERT-based recommender system. This recommendation system uses a BERT transformer specifically for anime recommendations. Unlike other systems, it takes only users' favorite anime titles as input, rather than ratings. I believe the BERT model handled the recommendation task very well, including effectively addressing the cold start problem by generating meaningful recommendations even with limited user data.</p>
</div>
<div class="about-item">
<h3>Purpose</h3>
<p>AnimeRecbert was built with the mission of making anime discovery smarter, more personal, and more enjoyable. Instead of relying on generic ratings or tags, it uses the power of modern NLP — specifically BERT — to understand your favorite titles and suggest anime that match your unique preferences. Our goal is to reimagine recommendation systems by combining deep language understanding with intuitive user interaction. Whether you're a seasoned anime fan or just getting started, AnimeRecbert helps you find your next favorite show effortlessly.</p>
</div>
<div class="about-item">
<h3>Contact & Feedback</h3>
<p><a href="mailto:[email protected]">[email protected]</a></p>
</div>
<div class="about-item">
<h3>GitHub Repo</h3>
<p><a href="https://github.com/MRamazan/AnimeRecBertWeb">https://github.com/MRamazan/AnimeRecBertWeb</a></p>
</div>
</div>
</div>
</div>
<script>
let allAnimes = [];
let malLogoUrl = '';
let currentTheme = 'purple';
// Page loading optimization
function initializePage() {
// Hide loader after everything is loaded
const pageLoader = document.getElementById('pageLoader');
const html = document.documentElement;
// Add loaded class to html
html.classList.add('loaded');
// Hide loader with animation
setTimeout(() => {
pageLoader.classList.add('hidden');
setTimeout(() => {
pageLoader.style.display = 'none';
}, 500);
}, 300);
}
// Critical resource preloading
function preloadCriticalResources() {
// Preload theme CSS files
const themes = ['green', 'orange', 'purple'];
themes.forEach(theme => {
const link = document.createElement('link');
link.rel = 'preload';
link.as = 'style';
link.href = `{{ url_for('static', filename='${theme}theme.css') }}`;
document.head.appendChild(link);
});
// Preload commonly used images
const commonImages = ['/static/mal-logo.png', '/static/placeholder.jpg'];
commonImages.forEach(src => {
const img = new Image();
img.src = src;
});
}
// Theme Switcher Functions
function toggleThemeOptions() {
const themeOptions = document.getElementById('themeOptions');
themeOptions.classList.toggle('show');
}
function changeTheme(theme) {
// Use requestAnimationFrame for smooth transitions
requestAnimationFrame(() => {
// Disable all theme stylesheets
document.getElementById('theme-purple').disabled = true;
document.getElementById('theme-green').disabled = true;
document.getElementById('theme-orange').disabled = true;
// Enable selected theme
document.getElementById(`theme-${theme}`).disabled = false;
// Update active theme option
document.querySelectorAll('.theme-option').forEach(option => {
option.classList.remove('active');
});
document.querySelector(`.theme-${theme}`).classList.add('active');
// Save theme preference
localStorage.setItem('selectedTheme', theme);
currentTheme = theme;
// Hide theme options
document.getElementById('themeOptions').classList.remove('show');
});
}
function loadSavedTheme() {
const savedTheme = localStorage.getItem('selectedTheme') || 'purple';
changeTheme(savedTheme);
}
// Close theme options when clicking outside
document.addEventListener('click', function(e) {
if (!e.target.closest('.theme-switcher')) {
document.getElementById('themeOptions').classList.remove('show');
}
});
// Initialize the application
document.addEventListener('DOMContentLoaded', function() {
// Initialize page loading
initializePage();
preloadCriticalResources();
loadBlacklist();
loadSavedTheme();
loadFavorites();
loadMalLogo();
const searchInput = document.getElementById('animeSearch');
const dropdown = document.getElementById('animeDropdown');
// Use debouncing for search
let searchTimeout;
searchInput.addEventListener('input', function() {
clearTimeout(searchTimeout);
const query = this.value.trim();
searchTimeout = setTimeout(() => {
if (query.length > 0) {
searchAnimes(query);
} else {
hideDropdown();
}
}, 300); // 300ms debounce
});
// Hide dropdown when clicking outside
document.addEventListener('click', function(e) {
if (!e.target.closest('.search-container')) {
hideDropdown();
}
});
});
// Load MAL logo from backend with caching
async function loadMalLogo() {
try {
// Check cache first
const cachedLogo = localStorage.getItem('malLogoUrl');
if (cachedLogo) {
malLogoUrl = cachedLogo;
return;
}
const response = await fetch('/api/mal_logo');
const data = await response.json();
if (data.success) {
malLogoUrl = data.logo_url;
localStorage.setItem('malLogoUrl', malLogoUrl);
}
} catch (error) {
console.error('Error loading MAL logo:', error);
}
}
// Search animes with caching
let searchCache = new Map();
async function searchAnimes(query) {
try {
// Check cache first
if (searchCache.has(query)) {
showDropdown(searchCache.get(query));
return;
}
const response = await fetch(`/api/search_animes?q=${encodeURIComponent(query)}`);
const animes = await response.json();
// Cache the result
searchCache.set(query, animes);
// Limit cache size
if (searchCache.size > 50) {
const firstKey = searchCache.keys().next().value;
searchCache.delete(firstKey);
}
showDropdown(animes);
} catch (error) {
console.error('Error searching animes:', error);
}
}
// Show dropdown with optimized rendering
function showDropdown(animes) {
const dropdown = document.getElementById('animeDropdown');
// Use requestAnimationFrame for smooth rendering
requestAnimationFrame(() => {
dropdown.innerHTML = '';
dropdown.style.display = 'block';
// Use DocumentFragment for better performance
const fragment = document.createDocumentFragment();
if (animes.length === 0) {
const option = document.createElement('div');
option.className = 'anime-option';
option.textContent = 'No animes found';
fragment.appendChild(option);
} else {
animes.slice(0, 30).forEach(anime => {
const option = document.createElement('div');
option.className = 'anime-option';
option.textContent = anime[1];
option.onclick = () => addToFavorites(anime[0], anime[1]);
fragment.appendChild(option);
});
}
dropdown.appendChild(fragment);
// Show with animation
setTimeout(() => {
dropdown.classList.add('show');
}, 50);
});
}
// Hide dropdown - optimized version
function hideDropdown() {
const dropdown = document.getElementById('animeDropdown');
dropdown.classList.remove('show');
setTimeout(() => {
dropdown.style.display = 'none';
dropdown.innerHTML = '';
}, 300);
}
// Add anime to favorites
async function addToFavorites(animeId, animeName) {
try {
const response = await fetch('/api/add_favorite', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
anime_id: animeId,
anime_name: animeName
})
});
const result = await response.json();
if (result.success) {
loadFavorites();
document.getElementById('animeSearch').value = '';
hideDropdown();
} else {
showMessage("Error", 'error');
}
} catch (error) {
console.error('Error adding favorite:', error);
showMessage('Error adding favorite', 'error');
}
}
// Remove from favorites
async function removeFromFavorites(animeId) {
try {
const response = await fetch('/api/remove_favorite', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
anime_id: animeId,
})
});
const result = await response.json();
if (result.success) {
loadFavorites();
} else {
showMessage("Error", 'error');
}
} catch (error) {
console.error('Error removing favorite:', error);
}
}
// Remove from favorites
async function removeFromFavorites(animeId) {
try {
const response = await fetch('/api/remove_favorite', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
anime_id: animeId,
})
});
const result = await response.json();
if (result.success) {
loadFavorites();
} else {
showMessage("Error", 'error');
}
} catch (error) {
console.error('Error removing favorite:', error);
}
}
// Load favorites from server
async function loadFavorites() {
try {
const response = await fetch('/api/get_favorites');
const favorites = await response.json();
displayFavorites(favorites);
} catch (error) {
console.error('Error loading favorites:', error);
}
}
// Display favorites with optimized rendering
function displayFavorites(favorites) {
const favoritesList = document.getElementById('favoritesList');
requestAnimationFrame(() => {
if (favorites.length === 0) {
favoritesList.innerHTML = '<div class="empty-state">No favorites selected yet. Search and add some animes!</div>';
} else {
const fragment = document.createDocumentFragment();
favorites.forEach(anime => {
const div = document.createElement('div');
div.className = 'favorite-tag';
div.innerHTML = `
<span>${anime.name}</span>
<button class="remove-btn" onclick="removeFromFavorites(${anime.id})">×</button>
`;
fragment.appendChild(div);
});
favoritesList.innerHTML = '';
favoritesList.appendChild(fragment);
}
});
}
// Clear all favorites
async function clearFavorites() {
try {
const response = await fetch('/api/clear_favorites', {
method: 'POST'
});
const result = await response.json();
if (result.success) {
loadFavorites();
}
} catch (error) {
console.error('Error clearing favorites:', error);
}
}
// Get recommendations
async function getRecommendations() {
const recommendationsSection = document.getElementById('recommendationsSection');
const favoritesSection = document.getElementById('favoritesSection');
const backButton = document.querySelector('.back-button');
const recommendationsGrid = document.getElementById('recommendationsGrid');
// Show loading
recommendationsGrid.innerHTML = `
<div class="loading">
<div class="spinner"></div>
<div>Getting your recommendations...</div>
</div>
`;
// Hide favorites section and show recommendations
favoritesSection.style.display = 'none';
recommendationsSection.style.display = 'block';
backButton.style.display = 'block';
try {
const response = await fetch('/api/get_recommendations', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
filters: currentFilters,
blacklisted_animes: blacklistedAnimes.map(anime => anime.id) // Her zaman blacklist gönder
})
});
const result = await response.json();
if (result.success) {
displayRecommendations(result.recommendations);
} else {
recommendationsGrid.innerHTML = `
<div class="loading">
<div style="color: #ff6b6b;">${result.message}</div>
</div>
`;
}
} catch (error) {
console.error('Error getting recommendations:', error);
recommendationsGrid.innerHTML = `
<div class="loading">
<div style="color: #ff6b6b;">Error getting recommendations</div>
</div>
`;
}
}
// Display recommendations with optimized rendering
function displayRecommendations(recommendations) {
const recommendationsGrid = document.getElementById('recommendationsGrid');
if (recommendations.length === 0) {
recommendationsGrid.innerHTML = '<div class="loading">No recommendations found</div>';
return;
}
requestAnimationFrame(() => {
const fragment = document.createDocumentFragment();
recommendations.forEach((anime, index) => {
const imageElement = anime.image_url
? `<img src="${anime.image_url}" alt="${anime.name}" class="anime-image" loading="lazy" onerror="this.style.display='none'; this.nextElementSibling.style.display='flex';">`
: '';
const placeholderElement = anime.image_url
? `<div class="no-image-placeholder" style="display: none;">🎌</div>`
: `<div class="no-image-placeholder">🎌</div>`;
const malButton = anime.mal_url
? `<a href="${anime.mal_url}" target="_blank" class="mal-button">
${malLogoUrl ? `<img src="${malLogoUrl}" alt="MAL" class="mal-logo">` : '🔗'}
View on MyAnimeList
</a>`
: `<div class="mal-message">MyAnimeList link not available</div>`;
const genresElementFront = anime.genres && anime.genres.length > 0
? `<div class="genres-container-front">
${anime.genres.slice(0, 4).map(genre => `<span class="genre-tag-front">${genre}</span>`).join('')}
</div>`
: '';
const div = document.createElement('div');
div.className = 'anime-card-wrapper';
div.style.animationDelay = `${index * 0.1}s`;
div.setAttribute('data-anime-id', anime.id);
div.innerHTML = `
<button class="delete-button" onclick="deleteAnimeCard(event, ${anime.id})" title="Remove from recommendations">
🗑️
</button>
<div class="anime-rank"></div>
<div class="anime-card" onclick="flipCard(this)">
<div class="card-inner">
<div class="card-front">
<div class="anime-image-container">
${imageElement}
${placeholderElement}
</div>
<div class="anime-info">
<div class="anime-name">${anime.name}</div>
<div class="anime-bottom-section">
${genresElementFront}
<button class="already-watched-btn" onclick="addToFavoritesFromRecommendations(event, ${anime.id}, '${anime.name.replace(/'/g, "\\'")}')">
Already Watched & Liked
</button>
</div>
<div class="flip-hint">Click card to see MyAnimeList link →</div>
</div>
</div>
<div class="card-back">
<div class="mal-button-container">
${malButton}
</div>
</div>
</div>
</div>
`;
fragment.appendChild(div);
});
recommendationsGrid.innerHTML = '';
recommendationsGrid.appendChild(fragment);
});
}
function flipCard(card) {
const cardInner = card.querySelector('.card-inner');
const scoreElement = card.querySelector('.anime-score');
const buttonElement = card.querySelector('.already-watched-btn');
if (cardInner.classList.contains('flipped')) {
cardInner.classList.remove('flipped');
if (scoreElement) scoreElement.classList.add('hidden');
if (buttonElement) buttonElement.classList.add('hidden');
setTimeout(() => {
if (scoreElement) scoreElement.classList.remove('hidden');
if (buttonElement) buttonElement.classList.remove('hidden');
}, 300);
} else {
cardInner.classList.add('flipped');
}
const malButton = card.querySelector('.mal-button');
if (malButton) {
malButton.addEventListener('click', function(e) {
e.stopPropagation();
});
}
}
// Show favorites section
function showFavorites() {
document.getElementById('favoritesSection').style.display = 'block';
document.getElementById('recommendationsSection').style.display = 'none';
document.querySelector('.back-button').style.display = 'none';
window.scrollTo(0, 0);
}
// Show messages
function showMessage(message, type) {
alert(message);
}
// Add anime to favorites from recommendations
async function addToFavoritesFromRecommendations(event, animeId, animeName) {
event.stopPropagation();
try {
const response = await fetch('/api/add_favorite', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
anime_id: animeId,
anime_name: animeName
})
});
const result = await response.json();
if (result.success) {
showFavorites();
loadFavorites();
getRecommendations();
} else {
showMessage("This anime is already in your favorites!", 'info');
}
} catch (error) {
console.error('Error adding favorite:', error);
showMessage('Error adding to favorites', 'error');
}
}
let currentFilters = {
show_sequels: false,
show_movies: true,
show_tv: true,
show_ova: false,
};
function toggleFilter(button) {
const filterName = button.getAttribute('data-filter');
const isActive = button.classList.contains('active');
if (isActive) {
button.classList.remove('active');
currentFilters[filterName] = false;
} else {
button.classList.add('active');
currentFilters[filterName] = true;
}
}
function applyFilters() {
getRecommendations(); // Artık blacklist otomatik olarak dahil edilecek
}
// Page visibility optimization
document.addEventListener('visibilitychange', function() {
if (document.hidden) {
// Page is hidden, pause animations
document.body.style.animationPlayState = 'paused';
} else {
// Page is visible, resume animations
document.body.style.animationPlayState = 'running';
}
});
function deleteAnimeCard(event, animeId) {
event.stopPropagation();
const cardWrapper = event.target.closest('.anime-card-wrapper');
const animeName = cardWrapper.querySelector('.anime-name').textContent;
// Blacklist'e ekle
addToBlacklist(animeId, animeName);
// Smooth animation ile kartı kaldır
cardWrapper.style.transform = 'scale(0.8)';
cardWrapper.style.opacity = '0';
cardWrapper.style.transition = 'all 0.3s ease';
setTimeout(() => {
cardWrapper.remove();
// Kalan kartları yeniden düzenle
const remainingCards = document.querySelectorAll('.anime-card-wrapper');
remainingCards.forEach((card, index) => {
card.style.animationDelay = `${index * 0.1}s`;
});
// Önerileri yeniden al (blacklist ile birlikte)
getRecommendations();
}, 300);
}
let blacklistedAnimes = [];
// Blacklist yönetimi
function loadBlacklist() {
const saved = localStorage.getItem('blacklistedAnimes');
if (saved) {
blacklistedAnimes = JSON.parse(saved);
}
updateBlacklistCounter();
}
function saveBlacklist() {
localStorage.setItem('blacklistedAnimes', JSON.stringify(blacklistedAnimes));
updateBlacklistCounter();
}
function updateBlacklistCounter() {
const counter = document.getElementById('blacklistCounter');
const button = document.getElementById('blacklistButton');
if (blacklistedAnimes.length > 0) {
counter.textContent = blacklistedAnimes.length;
button.classList.add('show');
} else {
counter.textContent = '0';
button.classList.remove('show');
}
}
function addToBlacklist(animeId, animeName) {
const existingIndex = blacklistedAnimes.findIndex(anime => anime.id === animeId);
if (existingIndex === -1) {
blacklistedAnimes.push({ id: animeId, name: animeName });
saveBlacklist();
}
}
function displayBlacklistItems() {
const blacklistList = document.getElementById('blacklistList');
if (blacklistedAnimes.length === 0) {
blacklistList.innerHTML = '<div class="empty-blacklist">No animes in blacklist</div>';
return;
}
const fragment = document.createDocumentFragment();
blacklistedAnimes.forEach(anime => {
const div = document.createElement('div');
div.className = 'blacklist-item';
div.innerHTML = `
<span class="blacklist-name">${anime.name}</span>
<button class="remove-blacklist-btn" onclick="removeFromBlacklist(${anime.id})">Remove</button>
`;
fragment.appendChild(div);
});
blacklistList.innerHTML = '';
blacklistList.appendChild(fragment);
}
function removeFromBlacklist(animeId) {
blacklistedAnimes = blacklistedAnimes.filter(anime => anime.id !== animeId);
saveBlacklist();
displayBlacklistItems();
}
function showCustomConfirm(title, message, onConfirm) {
// Modal HTML'ini oluştur
const modal = document.createElement('div');
modal.className = 'custom-confirm-modal';
modal.innerHTML = `
<div class="custom-confirm-content">
<div class="confirm-header">
<h3>${title}</h3>
</div>
<div class="confirm-message">
<p>${message}</p>
</div>
<div class="confirm-actions">
<button class="confirm-btn cancel" onclick="closeCustomConfirm()">Cancel</button>
<button class="confirm-btn confirm" onclick="confirmAction()">Yes, Clear All</button>
</div>
</div>
`;
document.body.appendChild(modal);
// Fonksiyonları global olarak erişilebilir yap
window.confirmAction = () => {
onConfirm();
closeCustomConfirm();
};
window.closeCustomConfirm = () => {
modal.remove();
delete window.confirmAction;
delete window.closeCustomConfirm;
};
// Modal'ı göster
setTimeout(() => modal.classList.add('show'), 50);
}
function clearBlacklist() {
showCustomConfirm(
'Clear All Blacklist',
'Are you sure you want to clear all blacklisted animes?',
() => {
blacklistedAnimes = [];
saveBlacklist();
displayBlacklistItems();
}
);
}
function openBlacklistModal() {
displayBlacklistItems();
document.getElementById('blacklistModal').classList.add('show');
}
function closeBlacklistModal() {
document.getElementById('blacklistModal').classList.remove('show');
}
</script>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-THGPD4P709"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
// Ek konfigürasyonlar eklenebilir
gtag('config', 'G-THGPD4P709', {
// Cookie consent için (isteğe bağlı)
'anonymize_ip': true,
// Sayfa yükleme performansı ölçümü
'send_page_view': true,
// Custom events tanımlanabilir
'custom_map': {
'custom_parameter': 'dimension1'
}
});
// Özel event'ler için örnek fonksiyonlar
function trackAnimeRecommendation(animeName) {
gtag('event', 'anime_recommendation', {
'anime_name': animeName,
'event_category': 'recommendation',
'event_label': animeName
});
}
function trackFavoriteAdd(animeName) {
gtag('event', 'favorite_added', {
'anime_name': animeName,
'event_category': 'user_interaction',
'event_label': animeName
});
}
function trackThemeChange(themeName) {
gtag('event', 'theme_changed', {
'theme_name': themeName,
'event_category': 'ui_customization',
'event_label': themeName
});
}
</script>
</body>
</html>
|