Zero Block с баннером
для показа по расписанию
Листинг с основной процедурой
<script>

class BigBanner {
    constructor(selector, options = {}) {
        this.el = document.querySelector(selector);

        this.days = options.days || [];                // ['mon','tue','wed']
        this.dateFrom = options.dateFrom || null;      // '2025-02-01'
        this.dateTo = options.dateTo || null;          // '2025-02-20'
    }

    isAvailable() {
       if (!this.el) return false;

        const now = new Date();

        // Получаем день недели: mon, tue, wed, thu, fri, sat, sun
        const daysMap = ['sun','mon','tue','wed','thu','fri','sat'];
        const today = daysMap[now.getDay()];

        // --- Проверка по дням недели ---
        if (this.days.length > 0 && !this.days.includes(today)) {
            return false;
        }

        // --- Проверка по дате "с" ---
        if (this.dateFrom) {
            const from = new Date(this.dateFrom);
            if (now < from) return false;
        }

        // --- Проверка по дате "до" ---
        if (this.dateTo) {
            const to = new Date(this.dateTo);
            if (now > to) return false;
        }

        return true;
    }

    show() {
        if (this.el) this.el.style.display = 'block';
    }

    hide() {
        if (this.el) this.el.style.display = 'none';
    }

    run() {
        this.isAvailable() ? this.show() : this.hide();
    }
}

</script>
Показ по дням недели
<script>
const banner = new BigBanner('#rec1613183261', {
    days: ['mon','tue', 'thu','fri']
});

banner.run();
</script>
Показ с даты до даты
<script>
const banner = new BigBanner('#rec1613183261', {
    dateFrom: '2025-10-15',
    dateTo: '2026-01-10'
});

banner.run();
</script>
Показ по понедельникам до даты
<script>
const banner = new BigBanner('#rec1625262591', {
    days: ['mon'],
    dateTo: '2025-11-30'
});

banner.run();
</script>
Made on
Tilda