/* زر واتساب عائم */
(function(){
if(document.getElementById('mlk-wa'))return;
var a=document.createElement('a');
a.id='mlk-wa';
a.href='https://wa.me/966556975546?text='+encodeURIComponent('السلام عليكم، عندي استفسار عن متجر ملك');
a.target='_blank';a.rel='noopener';
a.setAttribute('aria-label','تواصل معنا عبر واتساب');
a.innerHTML='';
a.style.cssText='position:fixed;right:18px;bottom:20px;z-index:9999;width:56px;height:56px;border-radius:50%;background:#25D366;display:flex;align-items:center;justify-content:center;box-shadow:0 4px 14px rgba(0,0,0,.25);transition:bottom .2s,transform .2s';
a.onmouseenter=function(){a.style.transform='scale(1.08)'};
a.onmouseleave=function(){a.style.transform='none'};
document.body.appendChild(a);
/* يرفع الزر فوق أي شريط ثابت أسفل الشاشة (مثل زر الإضافة للسلة بالجوال) */
function place(){
var b=20;
var els=document.elementsFromPoint(innerWidth/2,innerHeight-4);
for(var i=0;iinnerHeight/2)b=Math.max(b,innerHeight-r.top+12);}
break;
}
e=e.parentElement;
}
}
a.style.bottom=b+'px';
}
var t;function q(){clearTimeout(t);t=setTimeout(place,150)}
addEventListener('scroll',q,{passive:true});addEventListener('resize',q);
setTimeout(place,800);setTimeout(place,2500);
})();
/* إخفاء نموذج الطلب المباشر (ليش تنتظر؟) لأنه ينشئ طلب بدون دفع */
(function(){var s=document.createElement('style');s.textContent='salla-quick-order{display:none !important}';document.head.appendChild(s);})();
/* زر الرجوع للصفحة الرئيسية أعلى صفحات المتجر (غير الرئيسية) */
(function(){
function addHome(){
if(location.pathname==='/'||location.pathname==='/ar'||document.getElementById('mlk-home'))return;
var main=document.querySelector('main');
if(!main)return;
var w=document.createElement('div');
w.id='mlk-home';
w.style.cssText='max-width:1280px;margin:10px auto 0;padding:0 16px;direction:rtl';
w.innerHTML=''+
''+
'الرجوع للرئيسية';
main.insertBefore(w,main.firstChild);
}
if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',addHome);else addHome();
})();
/* إبراز التقسيط مع تابي وتمارا في صفحة المنتج والصفحة الرئيسية */
(function(){
function toNum(t){t=String(t||'').replace(/[\u0660-\u0669]/g,function(d){return d.charCodeAt(0)-1632}).replace(/[^0-9.]/g,'');return parseFloat(t)||0}
function fmt(n){return (Math.round(n*100)/100).toLocaleString('ar-SA',{maximumFractionDigits:2})}
function box(per){
var d=document.createElement('div');
d.className='mlk-bnpl';
d.style.cssText='direction:rtl;margin:12px 0;padding:12px 14px;border-radius:14px;background:#FBEBC4;border:1px solid #F1E4C8;color:#2B2B2B;font-size:14px;line-height:1.8;text-align:right';
d.innerHTML='
قسّميها على ٤ دفعات بدون فوائد'+(per?' : '+fmt(per)+' ريال للدفعة':'')+'
'+
'
'+
''+'تمارا'+
'بدون رسوم، والتحميل فوري بعد الطلب
';
return d;
}
function run(){
if(document.querySelector('.mlk-bnpl'))return;
var isProduct=document.body.classList.contains('product-single');
if(isProduct){
/* صندوق تمارا المؤقت بتصميم تمارا */
if(document.querySelector('.mlk-tamara'))return;
var inst=document.querySelector('salla-installment');
var tp=document.querySelector('.total-price');
var pr=tp?toNum(tp.textContent):0;
if(inst&&inst.parentNode&&pr){
var t=document.createElement('div');t.className='mlk-tamara';
t.style.cssText='direction:rtl;display:flex;align-items:center;justify-content:space-between;gap:12px;margin:10px 0 14px;padding:14px 16px;background:#fff;border:1px solid #E5E5E5;border-radius:8px;font-family:inherit;color:#231F1E;font-size:13px;line-height:1.7;text-align:right';
t.innerHTML='
أو قسّمها على ٤ دفعات بقيمة '+fmt(pr/4)+' ر.س بدون فوائد أو رسوم تأخير. متوافقة مع أحكام الشريعة. لمعرفة المزيد
';
inst.parentNode.insertBefore(t,inst.nextSibling);
}
}else if(location.pathname==='/'||location.pathname==='/ar'){
var cta=document.querySelector('.mlk-pitch .cta');
if(cta){var b=box(49/4);b.style.maxWidth='420px';b.style.margin='14px auto 0';cta.parentNode.insertBefore(b,cta.nextSibling)}
}
}
var tries=0;var iv=setInterval(function(){tries++;run();if(tries>30)clearInterval(iv)},700);
})();
/* بطاقات عروض الكتاب بتصميم مرتب */
(function(){
var BOOK=739970236;
var ITEMS=[
{id:1517510314,name:'ملف إنجاز بنات',tag:'للبنات',img:'https://cdn.salla.sa/nooqr/5b11a88d-c81d-49f6-9ad9-8e69f76db282-1000x1000-6TNadb0wVcDCG1wG1GtD64LyBod2lJb3ugaNCs1o.jpg',c:'#F2A7B5'},
{id:305827045,name:'ملف إنجاز أولاد',tag:'للأولاد',img:'https://cdn.salla.sa/nooqr/1ea37b19-ad16-416b-b6f6-ae645268b98e-1000x1000-EADV2re2H0N6ujksU88cJarlZ58Y5WfPSJRmwnMQ.jpg',c:'#7CC0E3'},
{id:570447136,name:'جدول مهام البنات',tag:'للبنات',img:'https://cdn.salla.sa/nooqr/9b3c91fb-db92-42ee-a8ab-3bfb09572164-1000x1000-EUVsjtZRZGii1kUIJJdbGET1bGhkNSJOrynZWQ03.jpg',c:'#F2A7B5'},
{id:1359060200,name:'جدول مهام الأولاد',tag:'للأولاد',img:'https://cdn.salla.sa/nooqr/e8bf49f9-c3b6-466f-bb3f-6b51a3a83d8d-1000x1000-nWisqAJBXMv4MT9kIJGz4m87QcEjhuHp7ngjE4Gs.jpg',c:'#7CC0E3'}
];
var GIFT='';
function css(){
if(document.getElementById('mlk-offers-css'))return;
var s=document.createElement('style');s.id='mlk-offers-css';
s.textContent=
'salla-offer{display:none !important}'+
'.mlk-offers{direction:rtl;margin:28px 0;padding:22px;border-radius:22px;background:#FFF8EC;border:1px solid #F1E4C8;font-family:inherit}'+
'.mlk-offers__head{display:flex;align-items:center;gap:12px;margin-bottom:6px}'+
'.mlk-offers__ic{width:42px;height:42px;border-radius:12px;background:#2F6B3A;display:flex;align-items:center;justify-content:center;flex-shrink:0}'+
'.mlk-offers h2{margin:0;font-size:20px;font-weight:800;color:#2F6B3A}'+
'.mlk-offers__sub{margin:0 0 18px;color:#6B6B6B;font-size:14px}'+
'.mlk-offers__sub b{color:#B8452E}'+
'.mlk-offers__grid{display:grid;grid-template-columns:repeat(4,1fr);gap:14px}'+
'@media(max-width:900px){.mlk-offers__grid{grid-template-columns:repeat(2,1fr)}.mlk-offers{padding:16px}}'+
'.mlk-oc{position:relative;background:#fff;border:1px solid #F1E4C8;border-radius:16px;overflow:hidden;display:flex;flex-direction:column;transition:transform .15s,box-shadow .15s}'+
'.mlk-oc:hover{transform:translateY(-3px);box-shadow:0 8px 20px rgba(47,107,58,.12)}'+
'.mlk-oc__img{display:block;aspect-ratio:1/1;background:#f6f6f6}'+
'.mlk-oc__img img{width:100%;height:100%;object-fit:cover;display:block}'+
'.mlk-oc__pills{display:flex;gap:6px;flex-wrap:wrap}'+
'.mlk-oc__badge{background:#B8452E;color:#fff;font-weight:800;font-size:12px;padding:3px 10px;border-radius:999px}'+
'.mlk-oc__tag{color:#2B2B2B;font-weight:700;font-size:12px;padding:3px 10px;border-radius:999px}'+
'.mlk-oc__body{padding:12px;display:flex;flex-direction:column;gap:8px;flex:1}'+
'.mlk-oc__name{font-weight:800;font-size:15px;color:#2B2B2B;text-decoration:none;line-height:1.4}'+
'.mlk-oc__price{display:flex;align-items:baseline;gap:8px}'+
'.mlk-oc__now{font-size:20px;font-weight:800;color:#2F6B3A}'+
'.mlk-oc__was{font-size:14px;color:#9a9a9a;text-decoration:line-through}'+
'.mlk-oc__btn{margin-top:auto;border:0;border-radius:12px;background:#2F6B3A;color:#fff;font-family:inherit;font-weight:800;font-size:14px;padding:10px;cursor:pointer}'+
'.mlk-oc__btn:hover{background:#245530}'+
'.mlk-oc__btn.done{background:#E7F1E2;color:#2F6B3A}';
document.head.appendChild(s);
}
function build(){
var w=document.createElement('section');w.className='mlk-offers';
var h='
'+GIFT+'
كمّليها مع الكتاب بخصم ٤٠٪
'+
'
أضيفي أي ملف مع الكتاب بـ٩ ريال بدل ١٥، والخصم يتطبّق تلقائيًا في السلة.
';
ITEMS.forEach(function(it){
var url='/p'+it.id;
h+='
';
w.addEventListener('click',function(e){
var b=e.target.closest('.mlk-oc__btn');if(!b||b.classList.contains('done'))return;
b.textContent='جاري الإضافة..';
var p=(window.salla&&salla.cart&&salla.cart.addItem)?salla.cart.addItem({id:+b.dataset.id,quantity:1}):Promise.reject();
Promise.resolve(p).then(function(){b.textContent='تمت الإضافة للسلة';b.classList.add('done')})
.catch(function(){location.href='/p'+b.dataset.id});
});
return w;
}
function run(){
if(!document.body.classList.contains('product-single'))return true;
if(location.pathname.indexOf('p'+BOOK)<0)return true;
css();
if(document.querySelector('.mlk-offers'))return true;
var off=document.querySelector('salla-offer');
if(!off)return false;
off.parentNode.insertBefore(build(),off);
return true;
}
var n=0,iv=setInterval(function(){n++;if(run()&&document.querySelector('.mlk-offers')||n>40)clearInterval(iv)},500);
})();
/* شريط عرض الملفات مع الكتاب في الرئيسية */
(function(){
var p=location.pathname.replace(/\/+$/,'');
if(p!==''&&p!=='/ar') return;
var tries=0;
function add(){
if(document.getElementById('mlk-bundle-note')) return true;
var hs=[].slice.call(document.querySelectorAll('h2,h3'));
var h=hs.filter(function(e){return /مع الكتاب كل ملف/.test(e.textContent);})[0];
if(!h) return false;
var sec=h.closest('section')||h.parentElement.parentElement;
var d=document.createElement('div');
d.id='mlk-bundle-note';
d.style.cssText='max-width:1180px;margin:24px auto 8px;padding:0 16px;direction:rtl';
d.innerHTML='
'
+'🎁'
+'
عرض الباقة: خذي الكتاب، وكل ملف معه يصير بـ٩ ريال بدل ١٥
'
+'
أضيفي الكتاب والملفات للسلة، والخصم ينزل تلقائياً · وفّري ٤٠٪ على كل ملف
'
+'
';
sec.parentNode.insertBefore(d,sec);
return true;
}
var t=setInterval(function(){ if(add()||++tries>40) clearInterval(t); },300);
})();
/* شارة النسخة الصوتية تحت عنوان الكتاب */
(function(){
if(location.pathname.indexOf('p739970236')<0) return;
var n=0;
function add(){
if(document.getElementById('mlk-audio-badge')) return true;
var h=document.querySelector('h1');
if(!h) return false;
var d=document.createElement('div');
d.id='mlk-audio-badge';
d.style.cssText='direction:rtl;display:flex;align-items:center;gap:12px;background:#2F6B3A;color:#fff;border-radius:14px;padding:12px 14px;margin:12px 0;box-shadow:0 3px 10px rgba(47,107,58,.25)';
d.innerHTML=''
+'
مع نسخة صوتية مسموعة 🎧
القصص الخمس بصوت واضح، توصلك مع الكتاب بدون تكلفة إضافية
';
h.parentNode.insertBefore(d,h.nextSibling);
return true;
}
var t=setInterval(function(){ add(); if(++n>60) clearInterval(t); },500);
})();
/* حدث عرض المحتوى لبكسل تيك توك في صفحات المنتجات */
(function(){
var m=location.pathname.match(/\/p(\d+)/); if(!m) return;
var id=m[1], n=0;
var t=setInterval(function(){
if(!window.ttq||typeof window.ttq.track!=='function'){ if(++n>40) clearInterval(t); return; }
clearInterval(t);
var name='', price=0;
try{ [].forEach.call(document.querySelectorAll('script[type="application/ld+json"]'),function(s){ var j=JSON.parse(s.textContent); if(j['@type']==='Product'){ name=j.name||''; var o=j.offers; if(Array.isArray(o)) o=o[0]; price=parseFloat(o&&o.price)||0; } }); }catch(e){}
window.ttq.track('ViewContent',{contents:[{content_id:id,content_type:'product',content_name:name,price:price,quantity:1}],content_type:'product',value:price,currency:'SAR'},{event_id:'vc_'+id+'_'+Date.now()});
},500);
})();