/* Add custom Js styles below */
// بوب أب مستك الذكي - يظهر كل ساعة بعد الإغلاق أو النسخ
(function() {
var DISCOUNT_CODE = 'S10';
var PRODUCT_URL = 'https://mistqsa.com/t/p1650322540';
var STORAGE_KEY = 'mistqsa_popup_timer';
var ONE_HOUR = 60 * 60 * 1000; // 1 ساعة
function shouldShowPopup() {
var last = localStorage.getItem(STORAGE_KEY);
if (!last) return true;
var diff = Date.now() - parseInt(last, 10);
return diff >= ONE_HOUR;
}
function saveNow() {
localStorage.setItem(STORAGE_KEY, String(Date.now()));
}
document.addEventListener('DOMContentLoaded', function() {
if (!shouldShowPopup()) return;
var html =
'
';
document.body.insertAdjacentHTML('beforeend', html);
setTimeout(function() {
var overlay = document.getElementById('mistqsa-discount-popup');
if (overlay) overlay.classList.add('show');
}, 1500);
// إغلاق بزر X
document.getElementById('mistqsaCloseBtn').addEventListener('click', function(e) {
e.preventDefault(); e.stopPropagation(); closePopup();
});
// إغلاق عند الضغط خارج المحتوى
var overlay = document.getElementById('mistqsa-discount-popup');
overlay.addEventListener('click', function(e) {
if (e.target === overlay) closePopup();
});
// منع الإغلاق عند النقر داخل المحتوى
document.getElementById('mistqsa-popup-content').addEventListener('click', function(e) {
e.stopPropagation();
});
// إغلاق بـ ESC
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape' || e.key === 'Esc') closePopup();
});
// نسخ الكود
document.getElementById('mistqsaCopyBtn').addEventListener('click', function(e) {
e.preventDefault(); e.stopPropagation();
var btn = this;
var code = DISCOUNT_CODE;
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(code).then(function() {
onCopied(btn);
}).catch(function() { fallbackCopy(code, btn); });
} else {
fallbackCopy(code, btn);
}
});
function onCopied(btn) {
var original = btn.innerHTML;
btn.innerHTML = '✅ تم النسخ!';
btn.classList.add('copied');
saveNow();
setTimeout(function() {
btn.innerHTML = original;
btn.classList.remove('copied');
}, 2000);
}
function fallbackCopy(text, btn) {
var ta = document.createElement('textarea');
ta.value = text;
ta.style.position = 'fixed';
ta.style.opacity = '0';
document.body.appendChild(ta);
ta.focus(); ta.select();
try {
var ok = document.execCommand('copy');
if (ok) onCopied(btn); else alert('الكود: ' + text);
} catch (err) {
alert('الكود: ' + text);
}
document.body.removeChild(ta);
}
function closePopup() {
var overlay = document.getElementById('mistqsa-discount-popup');
if (!overlay) return;
overlay.classList.remove('show');
saveNow();
setTimeout(function() {
if (overlay.parentNode) overlay.parentNode.removeChild(overlay);
}, 350);
}
});
})();