var A,Channel,absolutizeURL,checkOrigin,dedupe,fixURL,gated,getFinalImages,getImages,lastScript,loadImage,loadImages,main,mark,my_ts,origin,scripts,sendImages,sendSelection,sendTimings,src,timings,_images;my_ts=window.__flipboard_latest_ts=+new Date,timings={},mark=function(a){return"done"in timings?void 0:timings[a]=+new Date-my_ts},origin="*",checkOrigin=!1,"function"==typeof document.querySelectorAll&&(scripts=document.querySelectorAll("script"),lastScript=scripts[scripts.length-1],lastScript&&(src=lastScript.getAttribute("src"),checkOrigin&&/^(https?:\/\/[^\/]+)/.test(src)&&(origin=RegExp.$1))),fixURL=function(a){return null!=a?a.replace(new RegExp(" ","g"),"%20"):void 0},A=document.createElement("a"),absolutizeURL=function(a){return A.href=a,A.href},getImages=function(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s;for(g=[],p=a.querySelectorAll("img"),j=0,m=p.length;m>j;j++)if(c=p[j],i=fixURL(c.getAttribute("src")),i=absolutizeURL(i),!isNaN(c.naturalHeight)&&!isNaN(c.naturalWidth)&&c.naturalWidth>0&&c.naturalHeight>0){if(0===i.indexOf("data:image"))continue;0!==i.indexOf("//")?0===i.indexOf("/")?i=window.location.protocol+"//"+window.location.host+i:0!==i.indexOf("http")&&(i=window.location.protocol+"//"+window.location.host+window.location.pathname+"/"+i):i=window.location.protocol+i,g.push({url:i,height:c.naturalHeight,width:c.naturalWidth})}else g.push(i);for(b=a.querySelectorAll('*[style*="background-image"]'),h=/(?:url\([\s'"]?)(.*?)(?:[\s'"]?\))/g,d=k=0,n=b.length;n>k;d=++k)c=b[d],15>d&&(null!=(q=c.style)?q.backgroundImage:void 0)&&(f=null!=(r=h.exec(c.style.backgroundImage))?r[1]:void 0,f&&g.push(fixURL(f)));for(s=[],l=0,o=g.length;o>l;l++)e=g[l],e&&s.push(e);return s},dedupe=function(a){var b,c,d,e,f,g,h;for(b={},f=0,g=a.length;g>f;f++)c=a[f],"string"==typeof c?b[c]=c:b[c.url]=c;h=[];for(e in b)d=b[e],h.push(d);return h},loadImage=function(a,b){var c;return"object"==typeof a?b(a):(c=new Image,c.onload=function(){return b({width:c.width,height:c.height,url:c.src})},c.onerror=function(){return b()},c.src=a)},loadImages=function(a,b,c){return null==c&&(c=[]),0===a.length?void b(c):loadImage(a[0],function(d){return d&&c.push(d),loadImages(a.slice(1),b,c)})},_images=null,getFinalImages=function(a){var b,c,d,e,f,g,h,i;if(_images)return void a(_images);for(e=[],h=document.querySelectorAll("iframe"),f=0,g=h.length;g>f;f++){c=h[f];try{b=null!=(i=c.contentDocument)?i:c.contentWindow.document,b&&(e=e.concat(getImages(b)))}catch(j){d=j}}return e=dedupe(e.concat(getImages(document))),loadImages(e,function(b){return _images=b,a(_images)})},sendImages=function(a){return getFinalImages(function(b){var c,d,e;for(d=0,e=b.length;e>d;d++)c=b[d],a.send("image",c);return a.send("imagesDone")})},sendSelection=function(a){var b;return"function"==typeof window.getSelection?(b=window.getSelection().toString(),a.send("selectedText",b)):void 0},sendTimings=function(a){return a.send("timings",timings)},Channel=function(){return this.port=null,this.handleMessage=function(){},this.establish()},Channel.prototype.establish=function(){var a=this;return"function"==typeof window.addEventListener?window.addEventListener("message",function(b){var c;if(!(my_ts0?(a.port=b.ports[0],a.port.onmessage=function(b){return a.handleMessage(b.data)},a.port.postMessage("ready")):a.handleMessage(b.data)}):void 0},Channel.prototype.canPostMessages=function(){var a;if("undefined"==typeof this._canPostMessages)try{window.__flipboard.postMessage("check",origin),this._canPostMessages=!0}catch(b){a=b,this._canPostMessages=!1}return this._canPostMessages},Channel.prototype.postMessage=function(a,b){var c;null==b&&(b=null);try{return b?window.__flipboard.postMessage(a,origin,[b]):window.__flipboard.postMessage(a,origin)}catch(d){c=d}},Channel.prototype.flush=function(){var a,b,c,d;for(d=[];this.queue.length>0;)c=channel.queue.splice(0,1)[0],b=c[0],a=c[1],d.push(this.send(b,a));return d},Channel.prototype.send=function(a,b){return this.port?this.port.postMessage({type:a,data:b}):this.postMessage({type:a,data:b})},gated=function(a,b){var c;return c=0,function(){return c+=1,c>=a?b():void 0}},(main=function(){var a,b;return b=gated(2,function(){return mark("done"),sendImages(a),sendSelection(a),sendTimings(a)}),a=new Channel,a.handleMessage=function(a){return"ready"===a?(mark("channelSetup"),b()):void 0},getFinalImages(function(){return mark("imageScrape"),b()})})();