![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/.cursor-server/data/User/History/-9bf69ba/ |
(function() {
function notify(message, type) {
if (typeof window.showNotification === 'function') {
window.showNotification(message, type || 'info');
} else if (message) {
alert(message);
}
}
function updateButtonState(button, added) {
if (!button) return;
button.classList.toggle('active', added);
button.setAttribute('aria-pressed', added ? 'true' : 'false');
const icon = button.querySelector('i');
if (icon) {
icon.classList.remove(added ? 'far' : 'fas');
icon.classList.add(added ? 'fas' : 'far');
}
// Update title attribute if translations are available
if (typeof window.wishlistTranslations !== 'undefined' && window.wishlistTranslations) {
const title = added
? (window.wishlistTranslations.remove_from_wishlist || 'Remove from wishlist')
: (window.wishlistTranslations.add_to_wishlist || 'Add to wishlist');
button.setAttribute('title', title);
}
}
function resolveButton(trackId, button) {
if (button) return button;
const card = document.querySelector(`[data-track-id="${trackId}"]`);
return card ? card.querySelector('.wishlist-btn') : null;
}
window.toggleWishlist = function(trackId, button = null) {
if (!trackId) return;
const targetBtn = resolveButton(trackId, button);
if (targetBtn) {
targetBtn.classList.add('loading');
targetBtn.disabled = true;
}
fetch('/api/add_to_wishlist.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
credentials: 'include',
body: JSON.stringify({ track_id: trackId })
})
.then(response => response.json().then(data => ({ ok: response.ok, status: response.status, data })))
.then(({ ok, status, data }) => {
if (!ok || !data.success) {
const message = data.message || (status === 401 ? 'Please log in to use your wishlist.' : 'Unable to update wishlist.');
notify(message, status === 401 ? 'warning' : 'error');
return;
}
const added = data.action === 'added';
updateButtonState(targetBtn, added);
notify(added ? 'Added to wishlist!' : 'Removed from wishlist', 'success');
window.dispatchEvent(new CustomEvent('wishlist:toggled', {
detail: { trackId, added }
}));
})
.catch(error => {
console.error('Wishlist error:', error);
notify('Unable to update wishlist. Please check your connection.', 'error');
})
.finally(() => {
if (targetBtn) {
targetBtn.classList.remove('loading');
targetBtn.disabled = false;
}
});
};
})();