Vytvořil Shoptet | Design Shoptak.cz.
(function(){
const code="DNES10",
delay=2e4,
flag1="hpmShowed1",
flag2="hpmShowedCart";
// CSS včetně mobilních úprav
const css=`
.hpmOverlay{
position:fixed;inset:0;
background:rgba(0,0,0,.4);
display:flex;align-items:center;justify-content:center;
opacity:0;visibility:hidden;
transition:.3s;
z-index:99999;
}
.hpmOverlay.show{opacity:1;visibility:visible}
.hpmBox{
background:#fff;
border-radius:1rem;
max-width:340px;width:90%;
box-shadow:0 10px 30px rgba(0,0,0,.25);
text-align:center;
font-family:inherit;
overflow:hidden;
}
.hpmHead{
background:linear-gradient(135deg,#f083a3,#ed93c3);
color:#fff;
padding:1rem 2.5rem 1rem 1rem;
font-weight:600;
position:relative;
font-size:1rem;
line-height:1.4;
}
.hpmClose{
position:absolute;
right:.75rem;top:.5rem;
cursor:pointer;
font-size:22px;
color:#fff;
border:none;
background:transparent;
line-height:1;
}
.hpmBody{
padding:1rem;
font-size:.95rem;
color:#333;
line-height:1.5;
}
.hpmBody p{
margin:0 0 .75rem 0;
}
.hpmCode{
display:flex;
flex-wrap:wrap;
gap:.5rem;
justify-content:center;
margin:.5rem 0;
}
.hpmCodeBox{
border:2px dashed #f083a3;
border-radius:.5rem;
padding:.5rem 1rem;
color:#f083a3;
font-weight:700;
user-select:all;
font-size:1rem;
line-height:1.2;
min-width:100px;
text-align:center;
}
.hpmBtn{
background:linear-gradient(135deg,#f083a3,#ed93c3);
color:#fff;
border:none;
border-radius:.5rem;
padding:.5rem 1rem;
cursor:pointer;
font-size:.9rem;
line-height:1.2;
font-weight:600;
display:flex;
align-items:center;
gap:.4rem;
box-shadow:0 8px 20px rgba(240,131,163,.45);
}
.hpmNote{
font-size:.8rem;
color:#666;
margin-top:.5rem;
line-height:1.4;
}
@media(max-width:360px){
.hpmHead{font-size:.9rem;padding:.8rem 2.5rem .8rem .8rem}
.hpmBody{font-size:.9rem}
.hpmCodeBox{font-size:.9rem;padding:.4rem .8rem}
.hpmBtn{font-size:.8rem;padding:.4rem .8rem}
}
`;
// vložení stylu (jen jednou)
const style=document.createElement("style");
style.textContent=css;
document.head.appendChild(style);
// vytvoření popupu jen jednou
function makePopup(){
if(document.getElementById("hpmOverlay")) {
return document.getElementById("hpmOverlay");
}
const o=document.createElement("div");
o.id="hpmOverlay";
o.className="hpmOverlay";
o.setAttribute("role","dialog");
o.setAttribute("aria-modal","true");
o.innerHTML=`
Pouze dnes -10 % na celý nákup 💗
Použij kód při objednávce a sleva se ti načte.
Sleva platí jen dnes 💕
`;
document.body.appendChild(o);
const btn=o.querySelector(".hpmBtn");
const cls=o.querySelector(".hpmClose");
// kopírování kódu
btn.onclick=()=>{
navigator.clipboard.writeText(code).then(()=>{
btn.textContent="✓ Zkopírováno";
},()=>{
// fallback kdyby clipboard writeText nepustil
const tmp=document.createElement("input");
tmp.value=code;
document.body.appendChild(tmp);
tmp.select();
document.execCommand("copy");
document.body.removeChild(tmp);
btn.textContent="✓ Zkopírováno";
});
};
// zavření
const close=()=>o.classList.remove("show");
cls.onclick=close;
o.onclick=e=>{ if(e.target===o) close(); };
return o;
}
// zobraz okno
const show=()=>{ makePopup().classList.add("show"); };
// detekce košíku
function onCart(){
return location.pathname.includes("/kosik");
}
// řízení zobrazení
document.addEventListener("DOMContentLoaded",()=>{
if(onCart()){
if(!localStorage.getItem(flag2)){
show();
localStorage.setItem(flag2,"1");
}
}else{
if(!localStorage.getItem(flag1)){
setTimeout(()=>{
show();
localStorage.setItem(flag1,"1");
},delay);
}
}
});
})();