Files
dodep-simulator/static/js/app.js
T

133 lines
4.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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 = `<span>${icons[type] || ''}</span><span>${message}</span>`;
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 = `
<div style="background:linear-gradient(135deg,#1a3a1a,#0d260d);border:1px solid #22c55e;border-radius:14px;padding:1.25rem 1.75rem;max-width:400px;width:90%;text-align:center;animation:modalSlideIn 0.3s ease;box-shadow:0 16px 48px rgba(0,0,0,0.6);">
<div style="font-size:0.8rem;color:var(--text-dim,#94a3b8);margin-bottom:0.25rem;text-transform:uppercase;letter-spacing:0.05em;">🏆 Достижение разблокировано!</div>
<div style="font-size:1.2rem;font-weight:600;font-family:var(--font-display,'Russo One',sans-serif);" id="globalPopupTitle"></div>
<div style="color:#22c55e;font-size:0.95rem;margin-top:0.35rem;font-weight:600;" id="globalPopupReward"></div>
</div>
`;
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 ? '🔊' : '🔇';
});
}
});