/* LinkSpin zone tag. One line on your site: Renders a banner from the LinkSpin ad pool in place, reports one viewable impression (half the banner on screen for one second), nothing else. No cookies, no personal data. */ (function () { var s = document.currentScript; if (!s) return; var zone = s.getAttribute('data-zone') || ''; if (!/^ls-[a-f0-9]{6}$/.test(zone)) return; var base = (s.src || '').replace(/\/z\.js.*$/, ''); var box = document.createElement('div'); box.style.cssText = 'display:inline-block;line-height:0;max-width:100%'; s.parentNode.insertBefore(box, s); function load() { var r = new XMLHttpRequest(); r.open('GET', base + '/api/zone/serve?z=' + encodeURIComponent(zone), true); r.withCredentials = true; r.onload = function () { if (r.status !== 200) return; var ad; try { ad = JSON.parse(r.responseText).ad; } catch (e) { return; } if (!ad || (!ad.img && !ad.frame)) return; var el; if (ad.frame) { // a network ad: rendered inside our own frame so its script lands in a page we control el = document.createElement('iframe'); el.src = base + ad.frame; el.width = ad.w; el.height = ad.h; el.title = 'Advertisement'; el.setAttribute('scrolling', 'no'); el.setAttribute('frameborder', '0'); el.style.cssText = 'max-width:100%;border:0;display:block;overflow:hidden'; el.sandbox = 'allow-scripts allow-popups allow-popups-to-escape-sandbox allow-top-navigation-by-user-activation'; box.innerHTML = ''; box.appendChild(el); } else { var a = document.createElement('a'); a.href = base + ad.click; a.target = '_blank'; a.rel = 'noopener nofollow sponsored'; var img = document.createElement('img'); img.src = /^https?:/.test(ad.img) ? ad.img : base + ad.img; img.alt = ad.alt || 'Advertisement'; img.width = ad.w; img.height = ad.h; img.style.cssText = 'max-width:100%;height:auto;border:0;display:block'; a.appendChild(img); box.innerHTML = ''; box.appendChild(a); el = img; } var sent = false, timer = null; function ping() { if (sent) return; sent = true; try { navigator.sendBeacon(base + '/api/zone/seen?i=' + ad.imp); } catch (e) { var q = new XMLHttpRequest(); q.open('GET', base + '/api/zone/seen?i=' + ad.imp, true); q.send(); } } if ('IntersectionObserver' in window) { var io = new IntersectionObserver(function (es) { es.forEach(function (e) { if (e.intersectionRatio >= 0.5) { if (!timer) timer = setTimeout(function () { ping(); io.disconnect(); }, 1000); } else if (timer) { clearTimeout(timer); timer = null; } }); }, { threshold: [0, 0.5, 1] }); io.observe(el); } else { setTimeout(ping, 1500); } }; r.send(); } load(); })();