87 lines
2.7 KiB
JavaScript
87 lines
2.7 KiB
JavaScript
// Общие функции для всех страниц
|
||
|
||
// Инициализация табов
|
||
function initTabs() {
|
||
const tabs = document.querySelectorAll('.tab');
|
||
if (tabs.length > 0) {
|
||
tabs.forEach(tab => {
|
||
tab.addEventListener('click', function() {
|
||
const tabId = this.getAttribute('data-tab');
|
||
if (tabId) {
|
||
switchTab(tabId);
|
||
}
|
||
});
|
||
});
|
||
}
|
||
}
|
||
|
||
function switchTab(tabId) {
|
||
// Удаляем активный класс у всех вкладок
|
||
document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
|
||
document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active'));
|
||
|
||
// Добавляем активный класс выбранной вкладке
|
||
const activeTab = document.querySelector(`.tab[data-tab="${tabId}"]`);
|
||
const activeContent = document.getElementById(`${tabId}-tab`);
|
||
|
||
if (activeTab) activeTab.classList.add('active');
|
||
if (activeContent) activeContent.classList.add('active');
|
||
}
|
||
|
||
// Таймер обратного отсчета
|
||
class GameTimer {
|
||
constructor(elementId, duration) {
|
||
this.element = document.getElementById(elementId);
|
||
this.duration = duration;
|
||
this.timeLeft = duration;
|
||
this.interval = null;
|
||
}
|
||
|
||
start() {
|
||
this.updateDisplay();
|
||
this.interval = setInterval(() => {
|
||
this.timeLeft--;
|
||
this.updateDisplay();
|
||
|
||
if (this.timeLeft <= 0) {
|
||
this.stop();
|
||
if (this.onComplete) this.onComplete();
|
||
}
|
||
}, 1000);
|
||
}
|
||
|
||
stop() {
|
||
if (this.interval) {
|
||
clearInterval(this.interval);
|
||
this.interval = null;
|
||
}
|
||
}
|
||
|
||
updateDisplay() {
|
||
if (this.element) {
|
||
const minutes = Math.floor(this.timeLeft / 60);
|
||
const seconds = this.timeLeft % 60;
|
||
this.element.textContent = `${minutes}:${seconds < 10 ? '0' : ''}${seconds}`;
|
||
}
|
||
}
|
||
}
|
||
|
||
// Форматирование чисел (валюты)
|
||
function formatCurrency(amount) {
|
||
return new Intl.NumberFormat('ru-RU', {
|
||
style: 'currency',
|
||
currency: 'RUB',
|
||
minimumFractionDigits: 0
|
||
}).format(amount);
|
||
}
|
||
|
||
// Инициализация при загрузке страницы
|
||
document.addEventListener('DOMContentLoaded', function() {
|
||
initTabs();
|
||
|
||
// Инициализация текущего пользователя
|
||
const currentUser = localStorage.getItem('currentUser');
|
||
if (currentUser && document.getElementById('current-user')) {
|
||
document.getElementById('current-user').textContent = currentUser;
|
||
}
|
||
}); |