window['bazdid-fair'] = (function () { // ------------------------------------------------------------- // Cookie Helpers // ------------------------------------------------------------- function setCookie(name, value, expires) { document.cookie = `${name}=${value};expires=${expires};path=/`; } function getCookie(name, expireHours) { const expires = new Date(Date.now() + (1000 * 60 * 15 * expireHours)).toGMTString(); const all = document.cookie.split(';').map(c => c.trim()); for (const c of all) { const [key, val] = c.split('='); if (key === name) { if (!val) return [0, expires]; const parts = decodeURIComponent(val).split('|'); if (parts.length === 1) parts[1] = expires; return parts; } } return [0, expires]; } // ------------------------------------------------------------- // JSONP without jQuery // ------------------------------------------------------------- function jsonp(url) { return new Promise(resolve => { const cb = `jsonp_${Date.now()}_${Math.floor(Math.random() * 99999)}`; window[cb] = function (data) { resolve(data); delete window[cb]; script.remove(); }; const script = document.createElement("script"); script.src = url + cb; document.body.appendChild(script); }); } // ------------------------------------------------------------- // Helpers // ------------------------------------------------------------- function inIframe() { try { return window.self !== window.top; } catch { return true; } } function removeElement(id) { const el = document.getElementById(id); if (el && el.parentNode) el.parentNode.removeChild(el); } // ------------------------------------------------------------- // Modal Logic // ------------------------------------------------------------- function openModal() { const cookieName = "kfvd7138e"; const cookieData = getCookie(cookieName, 24); let pops = Number(cookieData[0]); const expireDate = cookieData[1]; if (isNaN(pops)) pops = 0; if (pops >= 3) return; if (inIframe()) return; setCookie(cookieName, ++pops, expireDate); // ---------------- CSS Loader ---------------- const css = document.createElement("link"); css.rel = "stylesheet"; css.href = "https://bazdid-fa.ir/smartpop/css?" + Math.floor(Math.random() * 1000000); document.head.appendChild(css); // ---------------- Black Screen ---------------- const black = document.createElement("div"); black.id = "bazdid-fair_blackScreen"; black.style.opacity = "0"; // ---------------- Wrapper ---------------- const wrapper = document.createElement("div"); wrapper.id = "bazdid-fair_wrapper"; wrapper.className = "fall_init"; wrapper.style = ` display:none; width:600px; height:334px; margin-top: -170px; margin-left: -300px; `; // ---------------- Iframe ---------------- const iframe = document.createElement("iframe"); iframe.frameBorder = "0"; iframe.scrolling = "no"; iframe.src = "https://bazdid-fa.ir/smartpop/process/52/01fc6d3e5eb6305a6488b1673f76807f?domain=" + window.location.hostname; iframe.style = ` width:600px; height:300px; `; // ---------------- Close Button ---------------- const closeBtn = document.createElement("a"); closeBtn.className = "closeBtn"; let countdown = 5; const timer = setInterval(() => { countdown--; if (countdown <= 0) { clearInterval(timer); closeBtn.textContent = "بستن پنجره"; closeBtn.onclick = closeModal; } else { closeBtn.textContent = `لطفا ${countdown} ثانیه منتظر بمانید.`; } }, 1000); // ---------------- Network Link ---------------- const network = document.createElement("div"); network.className = "network_link"; network.innerHTML = `تبلیغات پاپ باکس`; // ---------------- Layout ---------------- const top = document.createElement("div"); top.className = "top"; top.appendChild(closeBtn); top.appendChild(network); const iframeBox = document.createElement("div"); iframeBox.className = "iframe"; iframeBox.style = ` width:600px; height:300px; `; iframeBox.appendChild(iframe); const container = document.createElement("div"); container.appendChild(top); container.appendChild(iframeBox); wrapper.appendChild(container); document.body.appendChild(black); document.body.appendChild(wrapper); showModal(); } function showModal() { const black = document.getElementById("bazdid-fair_blackScreen"); const wrap = document.getElementById("bazdid-fair_wrapper"); black.style.opacity = "0.7"; wrap.style.display = "block"; setTimeout(() => { wrap.classList.add("fall_active"); }, 300); } function closeModal() { const black = document.getElementById("bazdid-fair_blackScreen"); const wrap = document.getElementById("bazdid-fair_wrapper"); black.style.opacity = "0"; wrap.className = "fall_init"; setTimeout(() => { removeElement("bazdid-fair_blackScreen"); removeElement("bazdid-fair_wrapper"); }, 800); save(); } // ------------------------------------------------------------- // Save (JSONP, replaces jQuery AJAX) // ------------------------------------------------------------- function save() { const url = "https://bazdid-fa.ir/smartpop/save/52/01fc6d3e5eb6305a6488b1673f76807f?callback=%3F" + "&domain=" + window.location.hostname + "&callback="; jsonp(url); } // ------------------------------------------------------------- // Public API (namespace) // ------------------------------------------------------------- return { open: openModal, close: closeModal, save, cookie: { get: getCookie, set: setCookie }, }; })(); // Init window.addEventListener("load", function () { window['bazdid-fair'].open(); });