<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>