Spaces:
Running
Running
File size: 10,820 Bytes
7b1266a |
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 |
const animeData = {
"Naruto": { "genres": ["Action", "Adventure", "Fantasy"] },
"Death Note": { "genres": ["Mystery", "Psychological", "Supernatural", "Thriller"] },
"Attack on Titan": { "genres": ["Action", "Dark Fantasy", "Post-apocalyptic"] },
"One Punch Man": { "genres": ["Action", "Comedy", "Superhero"] },
"My Hero Academia": { "genres": ["Superhero", "Action", "Comedy"] },
"Fullmetal Alchemist: Brotherhood": { "genres": ["Adventure", "Dark Fantasy", "Steampunk"] },
"Demon Slayer": { "genres": ["Adventure", "Dark Fantasy", "Martial Arts"] },
"Steins;Gate": { "genres": ["Sci-Fi", "Thriller", "Time Travel"] },
"Hunter x Hunter": { "genres": ["Adventure", "Fantasy", "Martial Arts"] },
"Code Geass": { "genres": ["Mecha", "Alternate History", "Military"] },
"Neon Genesis Evangelion": { "genres": ["Psychological", "Science Fiction", "Mecha"] },
"Cowboy Bebop": { "genres": ["Space Western", "Science Fiction", "Neo-noir"] },
"Gintama": { "genres": ["Action", "Comedy", "Science Fiction"] },
"One Piece": { "genres": ["Adventure", "Fantasy", "Comedy"] },
"Sword Art Online": { "genres": ["Science Fiction", "Adventure", "Romance"] }
};
const animeQuotes = [
{ quote: "I'll take a potato chip... and eat it!", author: "Light Yagami", anime: "Death Note" },
{ quote: "The only ones who should kill are those who are prepared to be killed.", author: "Lelouch Lamperouge", anime: "Code Geass" },
{ quote: "People die if they are killed.", author: "Shirou Emiya", anime: "Fate/stay night" },
{ quote: "I don't want to conquer anything. I just think the guy with the most freedom in this whole ocean... that's the Pirate King!", author: "Monkey D. Luffy", anime: "One Piece" },
{ quote: "The world isn't perfect. But it's there for us, doing the best it can... that's what makes it so damn beautiful.", author: "Roy Mustang", anime: "Fullmetal Alchemist" },
{ quote: "If you don't take risks, you can't create a future!", author: "Monkey D. Luffy", anime: "One Piece" },
{ quote: "Whatever you lose, you'll find it again. But what you throw away you'll never get back.", author: "Himura Kenshin", anime: "Rurouni Kenshin" },
{ quote: "Fear is not evil. It tells you what your weakness is. And once you know your weakness, you can become stronger as well as kinder.", author: "Gildarts Clive", anime: "Fairy Tail" },
{ quote: "It's not the face that makes someone a monster; it's the choices they make with their lives.", author: "Naruto Uzumaki", anime: "Naruto" },
{ quote: "If you don't like your destiny, don't accept it. Instead, have the courage to change it the way you want it to be.", author: "Naruto Uzumaki", anime: "Naruto" }
];
const quizQuestions = [
{
question: "How would you describe your personality?",
options: ["Energetic and optimistic", "Calm and analytical", "Determined and passionate", "Mysterious and aloof"]
},
{
question: "What's your ideal way to spend a weekend?",
options: ["Training and improving my skills", "Solving complex puzzles or mysteries", "Hanging out with friends", "Exploring new places"]
},
{
question: "If you had a superpower, what would it be?",
options: ["Super strength", "Mind reading", "Elemental control", "Time manipulation"]
},
{
question: "How do you handle conflicts?",
options: ["Face them head-on", "Analyze and strategize", "Try to understand all perspectives", "Avoid them if possible"]
},
{
question: "What's your biggest motivation in life?",
options: ["Protecting loved ones", "Seeking knowledge", "Achieving personal goals", "Making the world a better place"]
},
{
question: "Which animal best represents you?",
options: ["Fox", "Owl", "Lion", "Wolf"]
},
{
question: "What's your preferred fighting style?",
options: ["Hand-to-hand combat", "Strategic planning", "Weapons mastery", "Special abilities or magic"]
}
];
const characters = [
{ name: "Naruto Uzumaki", anime: "Naruto" },
{ name: "L Lawliet", anime: "Death Note" },
{ name: "Mikasa Ackerman", anime: "Attack on Titan" },
{ name: "Spike Spiegel", anime: "Cowboy Bebop" },
{ name: "Gon Freecss", anime: "Hunter x Hunter" },
{ name: "Lelouch Lamperouge", anime: "Code Geass" },
{ name: "Monkey D. Luffy", anime: "One Piece" },
{ name: "Saitama", anime: "One Punch Man" }
];
// DOM Elements
const animeListElement = document.getElementById('animeList');
const genreListElement = document.getElementById('genreList');
const recommendBtn = document.getElementById('recommendBtn');
const randomBtn = document.getElementById('randomBtn');
const recommendationsElement = document.getElementById('recommendations');
const quoteText = document.getElementById('quoteText');
const quoteAuthor = document.getElementById('quoteAuthor');
const newQuoteBtn = document.getElementById('newQuoteBtn');
const quizQuestion = document.getElementById('quizQuestion');
const quizOptions = document.getElementById('quizOptions');
const quizResult = document.getElementById('quizResult');
const restartQuizBtn = document.getElementById('restartQuizBtn');
const quizContainer = document.getElementById('quizContainer');
// State management
let selectedAnime = new Set();
let selectedGenres = new Set();
let currentQuestion = 0;
let userAnswers = [];
// Utility Functions
function createItem(text, listType) {
const item = document.createElement('div');
item.classList.add(`${listType}-item`);
item.textContent = text;
item.addEventListener('click', () => toggleItem(item, text, listType));
return item;
}
function toggleItem(item, text, listType) {
const selectedSet = listType === 'anime' ? selectedAnime : selectedGenres;
if (selectedSet.has(text)) {
selectedSet.delete(text);
item.classList.remove('selected');
} else {
selectedSet.add(text);
item.classList.add('selected');
}
}
// Recommendation System
function calculateRecommendations() {
if (selectedAnime.size === 0 && selectedGenres.size === 0) {
alert('Please select at least one anime or genre!');
return [];
}
const genreWeights = new Map();
// Weight genres from selected anime
selectedAnime.forEach(anime => {
const animeGenres = animeData[anime].genres;
animeGenres.forEach(genre => {
genreWeights.set(genre, (genreWeights.get(genre) || 0) + 1);
});
});
// Add weights from explicitly selected genres
selectedGenres.forEach(genre => {
genreWeights.set(genre, (genreWeights.get(genre) || 0) + 2);
});
// Calculate scores for each anime
const recommendations = [];
for (const [anime, data] of Object.entries(animeData)) {
if (selectedAnime.has(anime)) continue;
const score = data.genres.reduce((sum, genre) =>
sum + (genreWeights.get(genre) || 0), 0);
if (score > 0) {
recommendations.push({ title: anime, genres: data.genres, score });
}
}
return recommendations
.sort((a, b) => b.score - a.score)
.slice(0, 5)
.map(({ title, genres }) => ({ title, genres }));
}
function displayRecommendations(recommendations) {
recommendationsElement.innerHTML = '<h3>Recommendations:</h3>';
if (recommendations.length === 0) {
recommendationsElement.innerHTML += '<p>No recommendations found.</p>';
return;
}
const list = document.createElement('ul');
recommendations.forEach(anime => {
const item = document.createElement('li');
item.textContent = `${anime.title} - ${anime.genres.join(', ')}`;
list.appendChild(item);
});
recommendationsElement.appendChild(list);
}
// Quote System
function displayRandomQuote() {
const randomQuote = animeQuotes[Math.floor(Math.random() * animeQuotes.length)];
quoteText.textContent = `"${randomQuote.quote}"`;
quoteAuthor.textContent = `- ${randomQuote.author} (${randomQuote.anime})`;
}
// Quiz System
function displayQuestion() {
const question = quizQuestions[currentQuestion];
quizQuestion.textContent = question.question;
quizOptions.innerHTML = '';
question.options.forEach((option, index) => {
const button = document.createElement('button');
button.textContent = option;
button.addEventListener('click', () => selectAnswer(index));
quizOptions.appendChild(button);
});
}
function selectAnswer(index) {
userAnswers.push(index);
if (currentQuestion < quizQuestions.length - 1) {
currentQuestion++;
displayQuestion();
} else {
showResult();
}
}
function showResult() {
const characterIndex = Math.floor(Math.random() * characters.length);
const character = characters[characterIndex];
quizContainer.style.display = 'none';
quizResult.style.display = 'block';
quizResult.innerHTML = `
<h3>Quiz Result</h3>
<p>Based on your answers, you're most like <strong>${character.name}</strong> from ${character.anime}!</p>
<p>Remember, this is just for fun. Every person is unique, just like every anime character!</p>
`;
restartQuizBtn.style.display = 'block';
}
function restartQuiz() {
currentQuestion = 0;
userAnswers = [];
quizContainer.style.display = 'block';
quizResult.style.display = 'none';
restartQuizBtn.style.display = 'none';
displayQuestion();
}
// Initialize UI
function initializeUI() {
// Initialize anime list
Object.keys(animeData).forEach(anime => {
animeListElement.appendChild(createItem(anime, 'anime'));
});
// Initialize genre list
const allGenres = new Set();
Object.values(animeData).forEach(data => {
data.genres.forEach(genre => allGenres.add(genre));
});
Array.from(allGenres).forEach(genre => {
genreListElement.appendChild(createItem(genre, 'genre'));
});
// Initialize quote
displayRandomQuote();
// Initialize quiz
displayQuestion();
}
// Event Listeners
recommendBtn.addEventListener('click', () => {
const recommendations = calculateRecommendations();
displayRecommendations(recommendations);
});
randomBtn.addEventListener('click', () => {
const allAnime = Object.keys(animeData);
const randomAnime = allAnime[Math.floor(Math.random() * allAnime.length)];
displayRecommendations([{ title: randomAnime, genres: animeData[randomAnime].genres }]);
});
newQuoteBtn.addEventListener('click', displayRandomQuote);
restartQuizBtn.addEventListener('click', restartQuiz);
// Initialize the application
document.addEventListener('DOMContentLoaded', initializeUI);
|