(() => {
"use strict";
// يعمل فقط على صفحة المنتج المحددة
if (!location.pathname.includes("/p1883361925")) return;
function init() {
if (document.getElementById("viber-open-calculator"))
return true;
const tabs = document.querySelector(".tabs.tabs__product");
if (!tabs)
return false;
// زر فتح الحاسبة
const btn = document.createElement("button");
btn.type = "button";
btn.id = "viber-open-calculator";
btn.textContent = " لحساب كم راح نحولك (اضغظ هنا)";
btn.style.cssText = `
width:100%;
padding:14px;
margin:15px 0;
background:#6d28d9;
color:#fff;
border:none;
border-radius:10px;
font-size:16px;
font-weight:bold;
cursor:pointer;
`;
tabs.insertAdjacentElement("afterend", btn);
// إنشاء النافذة
const wrapper = document.createElement("div");
wrapper.innerHTML = `
`;
document.body.appendChild(wrapper);
const popup = document.getElementById("viber-modal");
btn.addEventListener("click",function(e){
e.preventDefault();
e.stopPropagation();
popup.style.display="flex";
});
document.getElementById("viber-close").addEventListener("click",function(e){
e.preventDefault();
e.stopPropagation();
popup.style.display="none";
});
popup.addEventListener("click",function(e){
if(e.target===popup){
popup.style.display="none";
}
});
document.getElementById("viber-calc").addEventListener("click",function(e){
e.preventDefault();
e.stopPropagation();
const value = parseFloat(
document.getElementById("viber-balance").value
);
if(isNaN(value) || value <= 0){
alert("أدخل قيمة صحيحة");
return;
}
const total = (value * 0.90) - 1.5;
const result = document.getElementById("viber-price");
result.style.display = "block";
result.innerHTML = `
سعر الشراء
${total.toFixed(2)} ريال
`;
});
return true;
}const timer = setInterval(function(){
if(init()){
clearInterval(timer);
}
},300);
})();