Zirnavis21 / static /js /utils.js
Elias207's picture
Create static/js/utils.js
679329e verified
// توابع کمکی فرمت‌دهی زمان و تاریخ
function getPersianDate() {
const d = new Date();
const option = { month: 'long', day: 'numeric', year: 'numeric' };
return d.toLocaleDateString('fa-IR', option);
}
function fmt(s) {
let sec = Math.floor(s);
let ms = Math.round((s - sec) * 100);
return `${sec < 10 ? '0'+sec : sec}.${ms < 10 ? '0'+ms : ms}`;
}
function formatTimeSimple(sec) {
let m = Math.floor(sec / 60);
let s = Math.floor(sec % 60);
return `${m}:${s < 10 ? '0'+s : s}`;
}
// انیمیشن ساده
function startAnim(selector) {
const container = document.querySelector(selector);
if(!container) return;
const words = container.querySelectorAll('.anim-word');
let i = 0;
setInterval(() => {
words.forEach(w => w.classList.remove('active'));
words[i].classList.add('active');
i = (i + 1) % words.length;
}, 600);
}
// همگام‌سازی دکمه‌های استایل
function syncModeButtons() {
document.querySelectorAll('.mode-btn').forEach(b => {
b.classList.remove('active');
if(b.getAttribute('onclick').includes(`'${state.st.type}'`)) b.classList.add('active');
});
}