<!-- Как вставить таймер обратного отсчета в ZeroBlock Tilda tbmsc.ru-->
<script>
document.addEventListener('DOMContentLoaded', () => {
const SETTINGS = {
showDays: true,
showHours: true,
showMinutes: true,
showSeconds: true,
separator: ' • '
};
const SOURCE_BLOCK_CLASS = '.uc-timer-block';
const OUTPUT_SELECTOR = '.zero-timer .tn-atom';
const getValue = (container, selector) => {
const el = container.querySelector(selector);
return el ? el.textContent.trim() : '00';
};
const buildTimeString = (data) => {
const parts = [];
if (SETTINGS.showDays) parts.push(data.days);
if (SETTINGS.showHours) parts.push(data.hours);
if (SETTINGS.showMinutes) parts.push(data.minutes);
if (SETTINGS.showSeconds) parts.push(data.seconds);
return parts.join(SETTINGS.separator);
};
const updateZeroBlockTimer = () => {
const source = document.querySelector(SOURCE_BLOCK_CLASS);
if (!source) return;
const timeData = {
days: getValue(source, '.t415__days'),
hours: getValue(source, '.t415__hours'),
minutes: getValue(source, '.t415__minutes'),
seconds: getValue(source, '.t415__seconds')
};
const formattedTime = buildTimeString(timeData);
const targets = document.querySelectorAll(OUTPUT_SELECTOR);
targets.forEach(node => {
node.textContent = formattedTime;
});
const isFinished = Object.values(timeData).every(v => v === '00' || v === '0');
if (isFinished) {
clearInterval(timerInterval);
}
};
updateZeroBlockTimer();
const timerInterval = setInterval(updateZeroBlockTimer, 1000);
});
</script>
<style>
/* Скрываем стандартный блок таймера Tilda */
[data-record-type="415"] {
visibility: hidden;
height: 0;
overflow: hidden;
}
</style>