!function(){var e={};function t(){var i,n,l,s,a=[],r=100;function o(e){e=e||{},this.width=0,this.height=0,this.position={top:0,left:0},this.percentOnScreen=0,this.durationOnScreen=0,this.DOMElement={},this.timer=null,this.observer=null,this.settings={percentageToBeViewable:e.percentageToBeViewable||50,timeBeforeViewable:e.timeBeforeViewable||1e3}}function c(t){t.DOMElement.setAttribute("viewable","true"),clearInterval(t.timer);let i=a.indexOf(t);a.splice(i,1);let n=t.DOMElement.getAttribute("data-adButler-viewable-callback");if(null!=n){let i=new XMLHttpRequest;i.onreadystatechange=function(){4===this.readyState&&200===this.status&&e._logMessage("Viewability.markViewable("+t.DOMElement.id+") --\x3e "+n)},i.open("GET",n,!0),i.send()}}o.prototype.recalculate=function(){n=window.innerHeight,i=window.innerWidth,s=window.scrollX,l=window.scrollY;const e=this.DOMElement.getBoundingClientRect();this.position.left=e.left+s,this.position.top=e.top+l,this.width=e.width,this.height=e.height;const t={x1:s,y1:l+n,x2:s+i,y2:l},a={x1:this.position.left,y1:this.position.top+this.height,x2:this.position.left+this.width,y2:this.position.top},r=(a.x2-a.x1)*(a.y1-a.y2),o=Math.max(0,Math.min(t.x2,a.x2)-Math.max(t.x1,a.x1))*Math.max(0,Math.min(t.y1,a.y1)-Math.max(t.y2,a.y2));this.percentOnScreen=o/r*100},o.prototype.initialize=function(t){var i=this;if(this.DOMElement=t,this.DOMElement.setAttribute("viewable","false"),"IntersectionObserver"in window){let t={threshold:[i.settings.percentageToBeViewable/100]};this.observer=new IntersectionObserver((function(t){if(void 0===t[0])return;let n=t[0];e._logMessage("Viewability.observerIntersect("+i.DOMElement.id+") --\x3e "+(n.isIntersecting?"true":"false")),!0===n.isIntersecting?i.timer=setInterval((function(){i.durationOnScreen+=r,i.durationOnScreen>=i.settings.timeBeforeViewable&&(i.observer.unobserve(i.DOMElement),c(i))}),r):clearInterval(i.timer)}),t),this.observer.observe(this.DOMElement)}else this.timer=setInterval((function(){i.recalculate(),i.percentOnScreen>=i.settings.percentageToBeViewable?(i.durationOnScreen+=r,i.durationOnScreen>=i.settings.timeBeforeViewable&&c(i)):i.durationOnScreen=0}),r)},t.prototype.addViewableEntity=function(t,i){const n=document.getElementById(t);if(null===n)return;let l=new o(i);l.initialize(n),a.forEach((function(e){e.DOMElement.id===t&&(clearInterval(e.timer),a.splice(a.indexOf(e),1))})),a.push(l),l.recalculate(),function(t){let i=t.DOMElement.getAttribute("data-adButler-eligible-callback");if(null!=i){let n=new XMLHttpRequest;n.onreadystatechange=function(){4===this.readyState&&200===this.status&&e._logMessage("Viewability.markEligible("+t.DOMElement.id+") --\x3e "+i)},n.open("GET",i,!0),n.send()}}(l)},t.prototype.initializeViewability=function(){document.createAttribute("viewable")}}e={startTimeMS:0,timing:!1,initialized:!1,viewability:{},init:function(){this.initialized=!0,this.viewability=new t,this.viewability.initializeViewability();document.querySelectorAll("[data-adbutler]").forEach((e=>{e.innerHTML.length>0&&this.viewability.addViewableEntity(e.id,[])}))},_logMessage:function(e){if(this.timing){0===this.startTimeMS&&(this.startTimeMS=(new Date).getTime()),e="[AdButler] "+e+" ("+((new Date).getTime()-this.startTimeMS)+" ms)"}else e="[AdButler] "+e;window.console&&window.console.log&&window.console.log(e)}},window.addEventListener("DOMContentLoaded",(()=>{e.init()}))}();