async function logout() { try { await fetch('/web/api/auth/logout', { method: 'POST' }); } catch (e) {} window.location.href = '/'; } async function refreshBalance() { try { const res = await fetch('/web/api/user/balance'); const data = await res.json(); if (data.success) { document.querySelectorAll('.user-balance').forEach(el => { const old = el.textContent; const val = `${Math.floor(data.balance)} ₽`; if (old !== val) { el.textContent = val; el.classList.remove('animate-scaleIn'); void el.offsetWidth; el.classList.add('animate-scaleIn'); } }); } } catch (e) {} } function getRarityColor(rarity) { const colors = { 'Consumer Grade': '#b0b0b0', 'Industrial Grade': '#5e98d9', 'Mil-Spec': '#4b69ff', 'Mil-Spec Grade': '#4b69ff', 'Restricted': '#8847ff', 'Classified': '#d32ce6', 'Covert': '#eb4b4b', 'Rare Special Item': '#ffd700', 'Extraordinary': '#ffd700', }; return colors[rarity] || '#b0b0b0'; } function formatNumber(n) { return n.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ' '); } function debounce(fn, ms = 300) { let timer; return function (...args) { clearTimeout(timer); timer = setTimeout(() => fn.apply(this, args), ms); }; } function escapeHtml(str) { const div = document.createElement('div'); div.textContent = str; return div.innerHTML; } function showNotification(message, type = 'info', duration = 3000) { let container = document.getElementById('toastContainer'); if (!container) { container = document.createElement('div'); container.id = 'toastContainer'; container.className = 'toast-container'; document.body.appendChild(container); } const icons = { success: '✓', error: '✗', info: 'ℹ', warning: '⚠' }; const toast = document.createElement('div'); toast.className = `toast toast-${type} animate-slideUp`; toast.innerHTML = `${icons[type] || ''}${message}`; container.appendChild(toast); setTimeout(() => { toast.style.opacity = '0'; toast.style.transform = 'translateX(100%)'; toast.style.transition = 'all 0.3s ease'; setTimeout(() => toast.remove(), 300); }, duration); } function showAchievementPopup(title, reward) { let popup = document.getElementById('achievementGlobalPopup'); if (!popup) { popup = document.createElement('div'); popup.id = 'achievementGlobalPopup'; popup.className = 'modal-overlay'; popup.style.background = 'rgba(0,0,0,0.5)'; popup.style.alignItems = 'flex-start'; popup.style.paddingTop = '60px'; popup.innerHTML = `
🏆 Достижение разблокировано!
`; document.body.appendChild(popup); } document.getElementById('globalPopupTitle').textContent = title; document.getElementById('globalPopupReward').textContent = reward ? `+${reward} ₽` : ''; popup.style.display = 'flex'; if (window.SoundManager) SoundManager.achievement(); setTimeout(() => { popup.style.display = 'none'; }, 4000); } document.addEventListener('DOMContentLoaded', () => { const toggle = document.getElementById('mobileToggle'); const nav = document.getElementById('navLinks'); if (toggle && nav) { toggle.addEventListener('click', () => { nav.classList.toggle('open'); }); document.addEventListener('click', (e) => { if (!toggle.contains(e.target) && !nav.contains(e.target)) { nav.classList.remove('open'); } }); } const soundToggle = document.getElementById('soundToggle'); if (soundToggle && window.SoundManager) { soundToggle.addEventListener('click', () => { const enabled = SoundManager.toggle(); soundToggle.textContent = enabled ? '🔊' : '🔇'; }); } });