<!-- Ограничиваем заказы по времени | https://mixadev.ru -->
<script id="disable-order-by-time">
(() => {
"use strict";
const config = {
blockId: "#rec000000000",
startTime: "12",
endTime: "21.59",
timeZone: "+1",
monday: true,
tuesday: true,
wednesday: true,
thursday: true,
friday: true,
saturday: true,
sunday: true,
};
const { blockId, endTime, startTime, timeZone } = config;
const daysOfWeek = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];
const activeDays = [config.sunday, config.monday, config.tuesday, config.wednesday, config.thursday, config.friday, config.saturday];
const enabledDays = daysOfWeek.map((day, index) => (activeDays[index] ? day : undefined));
const getBlockTooltip = (selector) => {
const block = $(selector);
return $("[data-tooltip-hook]", block).attr("data-tooltip-hook");
};
const simulateClick = (url) => {
const link = $("<a>", {
href: url,
click: function (event) {
event.preventDefault();
$(this).remove();
},
});
link.appendTo(".t706");
link[0].click();
};
const isOrderAllowed = ({ blockId, startHour, endHour, timeZone, days }) => {
if ($(blockId).length) {
const now = new Date();
const currentTime = now.getTime();
const timezoneOffset = 6e4 * now.getTimezoneOffset();
const adjustedTime = currentTime + 60 * timeZone * 60 * 1e3;
const localTime = new Date(adjustedTime + timezoneOffset);
const currentHour = localTime.getHours();
let isAllowed = true;
let isActiveDay = false;
days.forEach((day, index) => {
if (daysOfWeek.includes(day) && index === localTime.getDay()) {
isActiveDay = true;
}
});
if (isActiveDay) {
if (startHour < endHour) {
isAllowed = !(currentHour >= startHour && currentHour <= endHour);
} else {
isAllowed = !(currentHour >= startHour || currentHour <= endHour);
}
}
return isAllowed;
}
};
t_onFuncLoad("tcart__openCartSidebar", () => {
const originalOpenCartSidebar = window.tcart__openCartSidebar;
window.tcart__openCartSidebar = function () {
if (isOrderAllowed({
blockId,
startHour: startTime,
endHour: endTime,
timeZone: Number(timeZone),
days: enabledDays,
})) {
simulateClick(getBlockTooltip(blockId));
} else {
originalOpenCartSidebar(...arguments);
}
};
});
t_onFuncLoad("tcart__openCart", () => {
const originalOpenCart = window.tcart__openCart;
window.tcart__openCart = function () {
if (isOrderAllowed({
blockId,
startHour: startTime,
endHour: endTime,
timeZone: Number(timeZone),
days: enabledDays,
})) {
simulateClick(getBlockTooltip(blockId));
} else {
originalOpenCart(...arguments);
}
};
});
})();
</script>