<!-- Скрипт, который создает распределяющий попап при входе на Tilda с сайта bulgkate.ru -->
<style>
.welcome-popup-overlay {
position: fixed;
inset: 0;
background: rgba(0,0,0,0.45);
display: none;
align-items: center;
justify-content: center;
z-index: 9999;
}
.welcome-popup {
background: #fff;
border-radius: 16px;
max-width: 420px;
width: 90%;
padding: 40px 30px;
text-align: center;
font-family: 'Golos Text', Arial, sans-serif;
box-shadow: 0 8px 24px rgba(0,0,0,0.15);
animation: fadeIn 0.4s ease;
}
.welcome-popup h2 {
font-size: 22px;
font-weight: 600;
margin-bottom: 24px;
color: #2d2d2d;
}
.welcome-popup .btns {
display: flex;
gap: 16px;
justify-content: center;
flex-wrap: wrap;
}
.welcome-popup button {
flex: 1;
min-width: 140px;
padding: 12px 20px;
border: none;
border-radius: 8px;
font-size: 16px;
font-weight: 500;
cursor: pointer;
transition: background 0.25s;
}
.welcome-popup .btn-choice1 { background: #017E66; color: #fff; }
.welcome-popup .btn-choice1:hover { background: #016954; }
.welcome-popup .btn-choice2 { background: #FECF02; color: #2d2d2d; }
.welcome-popup .btn-choice2:hover { background: #e0b702; }
@keyframes fadeIn {
from { opacity: 0; transform: translateY(-10px); }
to { opacity: 1; transform: translateY(0); }
}
</style>
<div class="welcome-popup-overlay" id="welcomePopup" aria-modal="true" role="dialog" aria-labelledby="welcomePopupTitle">
<div class="welcome-popup">
<h2 id="welcomePopupTitle">Сделайте свой выбор:</h2>
<div class="btns">
<button class="btn-choice1" id="welcomeBtnChoice1">Выбор 1</button>
<button class="btn-choice2" id="welcomeBtnChoice2">Выбор 2</button>
</div>
</div>
</div>
<script>
(function() {
var KEY = 'welcome_choice'; // choice1 | choice2
var EXPIRE_DAYS = 1;
var popup = document.getElementById('welcomePopup');
var btnChoice1 = document.getElementById('welcomeBtnChoice1');
var btnChoice2 = document.getElementById('welcomeBtnChoice2');
function setCookie(name, value, days) {
var d = new Date();
d.setTime(d.getTime() + (days * 24 * 60 * 60 * 1000));
document.cookie = name + "=" + encodeURIComponent(value) + ";expires=" + d.toUTCString() + ";path=/;SameSite=Lax";
}
function getCookie(name) {
var m = document.cookie.match(new RegExp("(^| )" + name + "=([^;]+)"));
return m ? decodeURIComponent(m[2]) : null;
}
function setChoice(val) {
try {
localStorage.setItem(KEY, val);
localStorage.setItem(KEY + '_ts', Date.now().toString());
} catch(e) {}
setCookie(KEY, val, EXPIRE_DAYS);
setCookie(KEY + '_ts', Date.now().toString(), EXPIRE_DAYS);
}
function getChoice() {
var v = null, ts = null;
try { v = localStorage.getItem(KEY); ts = localStorage.getItem(KEY + '_ts'); } catch(e) {}
if (!v) { v = getCookie(KEY); ts = getCookie(KEY + '_ts'); }
if (v && ts) {
var age = Date.now() - parseInt(ts, 10);
if (isFinite(age) && age < EXPIRE_DAYS * 24 * 60 * 60 * 1000) return v;
}
return null;
}
function hidePopup(){ popup.style.display = 'none'; }
function showPopup(){ popup.style.display = 'flex'; }
// Вариант 1: переход по ссылке (текущий рабочий)
function goChoice1() {
setChoice('choice1');
window.location.href = 'https://example.com/choice1';
}
// Вариант 2: остаться на текущей странице
/*
function goChoice1() {
setChoice('choice1');
hidePopup(); // просто скрываем окно, остаёмся на странице
}
*/
function goChoice2() {
setChoice('choice2');
window.location.href = 'https://example.com/choice2';
}
btnChoice1.addEventListener('click', goChoice1);
btnChoice2.addEventListener('click', goChoice2);
document.addEventListener('DOMContentLoaded', function() {
var choice = getChoice();
if (choice) {
hidePopup();
} else {
showPopup();
}
});
popup.addEventListener('click', function(e) {
if (e.target === popup) hidePopup();
});
})();
</script>