(()=>{const RATE=.025,ALLOW=['745398474','203752814'],$=s=>document.querySelector(s),$$=s=>[...document.querySelectorAll(s)],toNum=s=>Number(((s??"")+"").replace(/[٬, ]/g,"").replace(/٫/g,".").replace(/[٠-٩]/g,d=>"٠١٢٣٤٥٦٧٨٩".indexOf(d))),fmt=n=>new Intl.NumberFormat(undefined,{minimumFractionDigits:2,maximumFractionDigits:2}).format(n),getPid=()=>{const m=decodeURIComponent(location.pathname||"").match(/\/p([0-9]{6,})(\/|$)/);return m?m[1]:""},getBtnId=b=>{const id=b.getAttribute("product-id")||b.dataset?.productId||b.dataset?.productid;return id?String(id):""},ok=b=>{if(!ALLOW.length)return!0;const id=getBtnId(b);if(id)return ALLOW.includes(id);const p=getPid();return!!p&&ALLOW.includes(p)},isPDP=()=>{const og=document.querySelector('meta[property="og:type"]')?.content;if(og==="product")return!0;return/\/p[0-9]{6,}(\/|$)/.test(decodeURIComponent(location.pathname||""))},allowedPage=()=>!ALLOW.length||ALLOW.includes(getPid()),setDonate=(vStr,vNum)=>{$$('salla-add-product-button[product-type="donating"]').filter(ok).forEach(b=>{b.setAttribute("donating-amount",vStr);try{b.donatingAmount=vNum}catch(_){}const d=b.data;if(d?.base_currency_price){try{d.base_currency_price.amount=vNum}catch(_){}try{b.data={...d,base_currency_price:{...d.base_currency_price,amount:vNum}}}catch(_){}}});const f=$('input[name="donating_amount"],#donation-amount,input[placeholder*="مبلغ التبرع"],input[placeholder*="التبرع"]');if(f){f.value=vStr;f.setAttribute("value",vStr)}};const mount=()=>{if(!isPDP()||!allowedPage())return;const btn=$$('salla-add-product-button[product-type="donating"]').find(ok);if(!btn||$(".zh-box"))return;btn.insertAdjacentHTML("beforebegin",'
احسب زكاتك (٢٫٥٪)
الزكاة: 0.00
');const inp=$(".zh-wealth"),out=$(".zh-out");const calc=()=>{const w=toNum(inp.value),z=w*RATE,zn=Math.round(z*100)/100,good=zn>0&&isFinite(zn);if(!good){out.textContent="0.00";return}const vStr=zn.toFixed(2);out.textContent=fmt(zn);setDonate(vStr,zn)};inp.addEventListener("input",calc);calc()};mount();new MutationObserver(()=>{$(".zh-box")||mount()}).observe(document.documentElement,{childList:!0,subtree:!0});})();