}; /* 2) IDs سننشئها تلقائيًا */ const ID_250 = 'gpt-article-250'; const ID_300 = 'gpt-article-300'; const ID_336 = 'gpt-article-336'; /* 3) A/B Controller (Line Item IDs) */ const ADPLUS_LI = '7110307884'; const NEWORMEDIA_LI = '7110320154'; const MAP = { [ADPLUS_LI]:'ADPLUS', [NEWORMEDIA_LI]:'NEWORMEDIA' }; const CTRL_PATH = '/23284614899/ab_controller'; const CTRL_DIV = 'gpt-ab-controller'; /* 4) مسارات Ad.Plus (حسب سنبتك) */ const ADPLUS_300x250_PATH = '/21849154601,23284614899/Ad.Plus-300x250'; // يُستخدم للـ300×250 والـ250×250 const ADPLUS_336x280_PATH = '/21849154601,23284614899/Ad.Plus-336x280'; /* 5) خرائط Waldo IDs (NeworMedia) */ const NEWOR_ID_300 = 'waldo-tag-42241'; // 300×250 const NEWOR_ID_250 = 'waldo-tag-42245'; // 250×250 const NEWOR_ID_336 = 'waldo-tag-42247'; // 336×280 /* Helpers */ const $ = (sel,root=document)=>root.querySelector(sel); const byId = id => document.getElementById(id); const onReady = fn => (document.readyState==='loading'?document.addEventListener('DOMContentLoaded',fn):fn()); function mountBox(id){ if (byId(id)) return byId(id); const el = document.createElement('div'); el.id = id; el.style.cssText='margin:16px 0;text-align:center;min-height:50px'; return el; } function tryInsertBox(root, cfg, boxEl){ if (!root) return false; const target = $(cfg.selector, root); if (!target) return false; if (cfg.at==='after') target.insertAdjacentElement('afterend', boxEl); else if (cfg.at==='before')target.insertAdjacentElement('beforebegin', boxEl); else target.appendChild(boxEl); return true; } function autoMountAll(){ const root = $(CONFIG.articleRoot) || document.body; tryInsertBox(root, CONFIG.pickers.box250, mountBox(ID_250)); tryInsertBox(root, CONFIG.pickers.box300, mountBox(ID_300)); tryInsertBox(root, CONFIG.pickers.box336, mountBox(ID_336)); } /* (اختياري) OOP للهيدر */ function injectAdPlusOOP(){ googletag.cmd.push(function(){ const inter = googletag.defineOutOfPageSlot('/21849154601,23284614899/Ad.Plus-Interstitial', googletag.enums.OutOfPageFormat.INTERSTITIAL); if (inter){ inter.addService(googletag.pubads()); googletag.display(inter); } const anchor = googletag.defineOutOfPageSlot('/21849154601,23284614899/Ad.Plus-Anchor', googletag.enums.OutOfPageFormat.BOTTOM_ANCHOR); if (anchor){ anchor.addService(googletag.pubads()); googletag.display(anchor); } }); } function injectNeworOOP(){ const s=document.createElement('script'); s.src='https://cdn.thisiswaldo.com/static/js/41784.js'; s.async=true; document.head.appendChild(s); onReady(function(){ if (!byId('waldo-tag-42249')) { const d=document.createElement('div'); d.id='waldo-tag-42249'; document.body.appendChild(d); } }); } /* حقن Ad.Plus: defineSlot/display على نفس العنصر (بدون div داخلي وبدون iframe) */ function serveAdPlus(){ googletag.cmd.push(function(){ // ملاحظة: 250×250 عندك بيستخدم نفس path الخاص بـ300×250 (حسب سنبتك) if (byId(ID_250)) { googletag.defineSlot(ADPLUS_300x250_PATH, [250,250], ID_250).addService(googletag.pubads()); googletag.display(ID_250); } if (byId(ID_300)) { googletag.defineSlot(ADPLUS_300x250_PATH, [300,250], ID_300).addService(googletag.pubads()); googletag.display(ID_300); } if (byId(ID_336)) { googletag.defineSlot(ADPLUS_336x280_PATH, [336,280], ID_336).addService(googletag.pubads()); googletag.display(ID_336); } }); } /* حقن NeworMedia: حوّل ID العنصر نفسه لـ waldo-tag-XXXX قبل تحميل السكربت */ function ensureWaldoLoaded(cb){ if (window.__waldoScriptLoaded) return cb&&cb(); const s=document.createElement('script'); s.src='https://cdn.thisiswaldo.com/static/js/41784.js'; s.async=true; s.onload=function(){ window.__waldoScriptLoaded=true; cb&&cb(); }; document.head.appendChild(s); } function makeWaldoTag(el, waldoId){ if (!el) return; if (!el.dataset.originalId) el.dataset.originalId = el.id; // احتفظ بالقديم لو هتحتاجه في CSS el.classList.add(el.id); // يحافظ على أي ستايل كان مربوط بالـID القديم el.id = waldoId; // تحويل دائم // ارتفاع مبدئي بسيط (اختياري) if (waldoId===NEWOR_ID_300 || waldoId===NEWOR_ID_250) el.style.minHeight='250px'; if (waldoId===NEWOR_ID_336) el.style.minHeight='280px'; el.style.textAlign='center'; } function serveNewor(){ makeWaldoTag(byId(ID_250), NEWOR_ID_250); makeWaldoTag(byId(ID_300), NEWOR_ID_300); makeWaldoTag(byId(ID_336), NEWOR_ID_336); ensureWaldoLoaded(function(){ /* أغلب النسخ تلتقط العناصر تلقائيًا */ }); } /* التشغيل: نزرع المواضع، نختار الفائز، ثم نخدم نفس الشركة على الثلاثة */ googletag.cmd.push(function(){ onReady(function(){ autoMountAll(); // كنترول 1×1 مخفي if(!byId(CTRL_DIV)){ const c=document.createElement('div'); c.id=CTRL_DIV; c.style.display='none'; document.body.appendChild(c); } const ctrlSlot = googletag.defineSlot(CTRL_PATH, [1,1], CTRL_DIV).addService(googletag.pubads()); googletag.pubads().addEventListener('slotRenderEnded', function(e){ if (e.slot !== ctrlSlot || window.__winnerChosen) return; const chosen = MAP[String(e.lineItemId || e.sourceAgnosticLineItemId || '')]; // 'ADPLUS' | 'NEWORMEDIA' if (!chosen) return; window.__winnerChosen = chosen; // (اختياري) OOP للهيدر حسب الفائز if (chosen==='ADPLUS') injectAdPlusOOP(); else injectNeworOOP(); // حقن المواضع لنفس الشركة if (chosen==='ADPLUS') serveAdPlus(); else serveNewor(); // محاولة احتياطية بعد 400ms setTimeout(function(){ if (!window.__articleInjected) { if (chosen==='ADPLUS') serveAdPlus(); else serveNewor(); } }, 400); }); // تفعيل وخدمة googletag.pubads().enableSingleRequest(); googletag.enableServices(); googletag.display(CTRL_DIV); }); }); })();
Ahmed Ali
Ahmed Ali
المقالات

1

متابعهم

0

متابعهم

1

متابعهم
مشاريع تجارية
مشاريع صغيرة مربحة
مشاريع صغيرة مربحة

مشاريع صغيرة يمكن بدء مسار جديد بها والربح منها بشكل جيد