1/** 2 * Pick a random OnNetwork SID client-side and inject the embed script (cache-safe rotation). 3 */ 4(function () { 5 'use strict'; 6 7 var EMBED_BASE = 'https://video.onnetwork.tv/embed.php'; 8 var initialized = new WeakSet(); 9 10 function parsePool(raw) { 11 if (!raw) { 12 return []; 13 } 14 15 try { 16 var parsed = JSON.parse(raw); 17 return Array.isArray(parsed) ? parsed : []; 18 } catch (error) { 19 return []; 20 } 21 } 22 23 function pickRandomItem(pool) { 24 if (!pool.length) { 25 return null; 26 } 27 28 var index = Math.floor(Math.random() * pool.length); 29 return pool[index] || null; 30 } 31 32 function injectEmbed(container, sid) { 33 if (!container || !sid || initialized.has(container)) { 34 return false; 35 } 36 37 initialized.add(container); 38 container.innerHTML = ''; 39 40 var script = document.createElement('script'); 41 script.type = 'text/javascript'; 42 script.src = EMBED_BASE + '?sid=' + encodeURIComponent(sid); 43 container.appendChild(script); 44 45 container.setAttribute('data-onnetwork-sid', sid); 46 return true; 47 } 48 49 function initContainer(container) { 50 if (!container || initialized.has(container)) { 51 return false; 52 } 53 54 var candidate = container.closest('.js-doit-ad-candidate'); 55 if (candidate) { 56 if (candidate.hidden || candidate.classList.contains('doit-ad-candidate--pending')) { 57 return false; 58 } 59 } 60 61 var pool = parsePool(container.getAttribute('data-onnetwork-pool')); 62 var item = pickRandomItem(pool); 63 if (!item || !item.sid) { 64 if (candidate) { 65 candidate.hidden = true; 66 candidate.classList.add('doit-ad-candidate--pending'); 67 candidate.classList.add('doit-ad-candidate--no-fill'); 68 69 var slot = candidate.closest('.js-doit-ad-slot'); 70 if (slot) { 71 slot.dispatchEvent(new CustomEvent('doit_ads_schedule_resolved', { bubbles: true })); 72 } 73 } 74 return false; 75 } 76 77 return injectEmbed(container, item.sid); 78 } 79 80 function initVisibleOnnetworkCreatives(root) { 81 var scope = root || document; 82 scope.querySelectorAll('[data-doit-onnetwork="1"]').forEach(function (container) { 83 initContainer(container); 84 }); 85 } 86 87 document.addEventListener('doit_ads_ad_shown', function (event) { 88 var slot = event.target; 89 if (!slot || !slot.querySelectorAll) { 90 return; 91 } 92 93 initVisibleOnnetworkCreatives(slot); 94 }); 95 96 document.addEventListener('doit_ads_schedule_resolved', function () { 97 initVisibleOnnetworkCreatives(document); 98 }); 99 100 if (document.readyState === 'loading') { 101 document.addEventListener('DOMContentLoaded', function () { 102 initVisibleOnnetworkCreatives(document); 103 }); 104 } else { 105 initVisibleOnnetworkCreatives(document); 106 } 107})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.