<script>
    document.addEventListener("DOMContentLoaded", function () {
    const telegramButton = document.querySelector(".sigmaweb-telegram-button");
    const telegramChat = document.querySelector(".sigmaweb-telegram-chat");
    const closeButton = document.querySelector(".sigmaweb-telegram-close-button div");
    const textOnline = document.querySelector(".sigmaweb-telegram-textonline");
    const textOffline = document.querySelector(".sigmaweb-telegram-textoffline");

    // تابعی برای دریافت ساعت به فرمت 08:00
    function getCurrentTime() {
        const now = new Date();
        let hours = now.getHours();
        let minutes = now.getMinutes();

        hours = hours < 10 ? "0" + hours : hours;
        minutes = minutes < 10 ? "0" + minutes : minutes;

        return `${hours}:${minutes}`;
    }

    // تابع بررسی ساعت و نمایش متن مناسب
    function checkTime() {
        const now = new Date();
        const currentTime = getCurrentTime();
        const startTime = "08:00"; // ساعت شروع نمایش آنلاین
        const endTime = "20:00"; // ساعت پایان نمایش آنلاین

		// اگر ساعت بین 08:00 و 20:00 باشد، متن "online" نمایش داده شود و متن "offline" مخفی شود
        if (currentTime >= startTime && currentTime < endTime) {
            textOnline.style.display = "block";
            textOffline.style.display = "none";
        } else {
		// در غیر این صورت، متن "offline" نمایش داده شود و متن "online" مخفی شود
            textOnline.style.display = "none";
            textOffline.style.display = "block";
        }
    }

    checkTime();

    // افزودن رویداد کلیک برای باز و بسته کردن چت واتساپ
    if (telegramButton && telegramChat) {
        telegramButton.addEventListener("click", function () {
            telegramButton.classList.toggle("active");
            telegramChat.classList.toggle("active");
        });
    }

    // افزودن رویداد کلیک به دکمه بستن چت واتساپ
    if (closeButton) {
        closeButton.addEventListener("click", function () {
            telegramButton.classList.remove("active");
            telegramChat.classList.remove("active");
        });
    }

    // بررسی ساعت هر 60 ثانیه یک‌بار برای به‌روزرسانی خودکار وضعیت
    setInterval(checkTime, 60000);
});
</script>