(function() { console.log('SB banner run...'); const postId = '67fda90572a40527486be7a1'; const bannerUrl = 'https://app.seobotai.com/banner/inline/'; const popupUrl = 'https://app.seobotai.com/banner/popup/'; window.addEventListener('message', function(event) { if (event.origin === new URL(bannerUrl).origin) { const { id, height } = event.data; let iframe = document.getElementById(id); if (iframe?.tagName === 'IFRAME') { iframe.style.height = height + 'px'; iframe.style.marginLeft = 'auto'; iframe.style.marginRight = 'auto'; iframe.style.borderRadius = '24px' } // fallback iframe = document.querySelector('iframe.' + id); if (iframe) { iframe.style.height = height + 'px'; iframe.style.borderRadius = '24px' } } }, false); function handleInline(banner, id) { // const id = banner.id || banner.innerText; console.log('SB inline banner rendering: ' + id); const skeleton = document.createElement('div'); skeleton.id = 'skeleton-' + id; skeleton.style.width = '100%'; skeleton.style.height = '400px'; skeleton.style.backgroundColor = '#eee'; skeleton.style.borderRadius = '1em'; skeleton.style.marginTop = '1em'; skeleton.style.marginBottom = '1em'; skeleton.style.marginLeft = 'auto'; skeleton.style.marginRight = 'auto'; banner.parentNode.replaceChild(skeleton, banner); const iframe = document.createElement('iframe'); iframe.id = id; iframe.className = id; iframe.style.display = 'block'; iframe.style.border = 'none'; iframe.style.borderRadius = '24px' iframe.style.width = '100%'; iframe.style.height = '0'; iframe.style.marginTop = '1em'; iframe.style.marginBottom = '1em'; iframe.style.marginLeft = 'auto'; iframe.style.marginRight = 'auto'; iframe.src = bannerUrl + '?id=' + id; iframe.onload = function() { const skeletonPlaceholder = document.getElementById('skeleton-' + id); if (skeletonPlaceholder) { skeletonPlaceholder.parentNode.replaceChild(iframe, skeletonPlaceholder); } }; skeleton.parentNode.insertBefore(iframe, skeleton.nextSibling); } async function handlePopup() { try { const res = await fetch(popupUrl + '?postId=' + postId); const result = await res.json(); if (!result?.data?.success) return; const data = result.data; const container = document.createElement('div'); container.innerHTML = data.html; document.body.appendChild(container); const style = document.createElement('style'); style.type = 'text/css'; style.appendChild(document.createTextNode(data.styles)); document.head.appendChild(style); const script = document.createElement('script'); script.type = 'text/javascript'; script.textContent = data.script; document.body.appendChild(script); } catch {} } const divs = Array.from(document.querySelectorAll('div.sb-banner')); const h6 = Array.from(document.querySelectorAll('h6')).filter(el => el.textContent.trim().startsWith('sbb-itb-')); const banners = [...divs, ...h6]; console.log('SB banner tags ' + banners.length); const seenBaseIds = new Set(); banners.forEach(banner => { const id = banner.id || banner.innerText; const text = banner.innerText; // Check both id and innerText for regex match const idMatch = id ? id.match(/^(sbb-(itb|ptb|unk)-[a-zA-Z0-9]+)(-d+)?/) : null; const textMatch = text ? text.match(/^(sbb-(itb|ptb|unk)-[a-zA-Z0-9]+)(-d+)?/) : null; // Use whichever passes the test const baseIdMatch = idMatch || textMatch; const baseId = baseIdMatch ? baseIdMatch[1] : null; const validIdentifier = idMatch ? id : (textMatch ? text : id); if (baseId && seenBaseIds.has(baseId)) { banner.remove(); return; } if (baseId) { seenBaseIds.add(baseId); } if (validIdentifier.startsWith('sbb-itb-')) handleInline(banner, validIdentifier); handlePopup(); }); })();