MusicMemory
1990s Hits • Mood Filters • Memory Prompts
How are you feeling?
♥ 0 Favorites
Loading classic songs from YouTube...
💫 Memory Prompt:
Play a song to receive a warm memory prompt...
`).join("");
}
// Toggle favorite
function toggleFavorite(title) {
const idx = favorites.indexOf(title);
if (idx > -1) {
favorites.splice(idx, 1);
} else {
favorites.push(title);
}
localStorage.setItem("musicMemoryFavorites", JSON.stringify(favorites));
updateFavorites();
renderCurrentTab();
}
// Update favorites count
function updateFavorites() {
document.getElementById("favCount").textContent = `♥ ${favorites.length} Favorite${favorites.length !== 1 ? 's' : ''}`;
}
// Update memory prompt
function updateMemoryPrompt(mood) {
const prompts = memoryPrompts[mood] || memoryPrompts.calm;
const prompt = prompts[Math.floor(Math.random() * prompts.length)];
document.getElementById("memoryPrompt").textContent = prompt;
}
// Filter and render
function renderCurrentTab() {
const songList = document.getElementById("songList");
const currentTab = document.querySelector(".tab-btn.active").dataset.tab;
let toRender = classicSongs;
if (selectedMood !== "all") {
toRender = toRender.filter(s => s.mood === selectedMood);
}
if (currentTab === "favorites") {
toRender = toRender.filter(s => favorites.includes(s.title));
if (toRender.length === 0) {
songList.innerHTML = `No favorites yet. Heart a song to save it! ❤
`;
return;
}
}
renderSongs(toRender);
}
// Event listeners
document.querySelectorAll(".mood-btn").forEach(btn => {
btn.addEventListener("click", (e) => {
document.querySelectorAll(".mood-btn").forEach(b => b.classList.remove("active"));
e.target.classList.add("active");
selectedMood = e.target.dataset.mood;
renderCurrentTab();
});
});
document.querySelectorAll(".tab-btn").forEach(btn => {
btn.addEventListener("click", (e) => {
document.querySelectorAll(".tab-btn").forEach(b => b.classList.remove("active"));
e.target.classList.add("active");
renderCurrentTab();
});
});
// Initialize
window.onload = () => {
document.getElementById("loading").style.display = "none";
document.getElementById("content").style.display = "block";
updateFavorites();
renderCurrentTab();
};
// Make functions global
window.toggleFavorite = toggleFavorite;
window.updateMemoryPrompt = updateMemoryPrompt;