OwlCyberSecurity - MANAGER
Edit File: amp-paired-browsing-app.js
(()=>{"use strict";var e={};function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t(e)}function i(e,i,n){return(i=function(e){var i=function(e){if("object"!=t(e)||!e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var n=i.call(e,"string");if("object"!=t(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==t(i)?i:i+""}(i))in e?Object.defineProperty(e,i,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[i]=n,e}e.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}();const n=window.wp.url,{ampPairedBrowsingAppData:r,history:s}=window,{noampQueryVar:o,noampMobile:a,ampPairedBrowsingQueryVar:m,documentTitlePrefix:c}=r;window.pairedBrowsingApp=new class{constructor(){i(this,"disconnectedClient",void 0),i(this,"ampIframe",void 0),i(this,"ampHeartbeatTimestamp",Date.now()),i(this,"nonAmpIframe",void 0),i(this,"nonAmpHeartbeatTimestamp",Date.now()),i(this,"currentAmpUrl",void 0),i(this,"initialAmpUrlObject",void 0),i(this,"navigateAmpUrl",void 0),i(this,"currentNonAmpUrl",void 0),i(this,"initialNonAmpUrlObject",void 0),i(this,"navigateNonAmpUrl",void 0),i(this,"nonAmpLink",void 0),i(this,"ampLink",void 0),i(this,"activeIframe",void 0),this.nonAmpIframe=document.querySelector("#non-amp iframe"),this.ampIframe=document.querySelector("#amp iframe"),this.currentNonAmpUrl=this.nonAmpIframe.src,this.initialNonAmpUrlObject=new URL(this.currentNonAmpUrl),this.currentAmpUrl=this.ampIframe.src,this.initialAmpUrlObject=new URL(this.currentNonAmpUrl),this.nonAmpLink=document.getElementById("non-amp-link"),this.ampLink=document.getElementById("amp-link"),this.disconnectOverlay=document.querySelector(".disconnect-overlay"),this.disconnectButtons={exit:document.querySelector(".disconnect-overlay .button.exit"),goBack:document.querySelector(".disconnect-overlay .button.go-back")},this.addDisconnectButtonListeners(),e.g.addEventListener("message",(e=>{this.receiveMessage(e)})),document.getElementById("non-amp").addEventListener("mouseenter",(()=>{this.activeIframe=this.nonAmpIframe})),document.getElementById("amp").addEventListener("mouseenter",(()=>{this.activeIframe=this.ampIframe})),Promise.all(this.getIframeLoadedPromises()).then((()=>{setInterval((()=>{this.checkConnectedClients()}),100)}))}isAmpWindow(e){return e===this.ampIframe.contentWindow}isNonAmpWindow(e){return e===this.nonAmpIframe.contentWindow}sendMessage(e,t,i={}){e.postMessage({type:t,...i,ampPairedBrowsing:!0},this.isAmpWindow(e)?this.currentAmpUrl:this.currentNonAmpUrl)}receiveMessage(e){if(e.data&&e.data.type&&e.data.ampPairedBrowsing&&e.source&&[this.initialNonAmpUrlObject.origin,this.initialAmpUrlObject.origin].includes(e.origin)&&(this.isAmpWindow(e.source)||this.isNonAmpWindow(e.source)))switch(e.data.type){case"loaded":this.receiveLoaded(e.data,e.source);break;case"scroll":this.receiveScroll(e.data,e.source);break;case"heartbeat":this.receiveHeartbeat(e.source);break;case"navigate":this.receiveNavigate(e.data,e.source)}}getIframeLoadedPromises(){return[new Promise((e=>{this.nonAmpIframe.addEventListener("load",e)})),new Promise((e=>{this.ampIframe.addEventListener("load",e)}))]}receiveHeartbeat(e){this.isAmpWindow(e)?this.ampHeartbeatTimestamp=Date.now():this.nonAmpHeartbeatTimestamp=Date.now()}receiveNavigate({href:e},t){this.isAmpWindow(t)?this.navigateAmpUrl=e:this.navigateNonAmpUrl=e}checkConnectedClients(){this.sendMessage(this.ampIframe.contentWindow,"init"),this.sendMessage(this.nonAmpIframe.contentWindow,"init"),this.isClientConnected(this.ampIframe)?this.isClientConnected(this.nonAmpIframe)?this.disconnectOverlay.classList.remove("disconnected"):this.showDisconnectOverlay(this.nonAmpIframe):this.showDisconnectOverlay(this.ampIframe)}addDisconnectButtonListeners(){this.disconnectButtons.goBack.addEventListener("click",(()=>{window.history.back()}))}showDisconnectOverlay(e){const t=this.ampIframe===e?this.navigateAmpUrl:this.navigateNonAmpUrl;t?(this.disconnectButtons.exit.hidden=!1,this.disconnectButtons.exit.href=t):this.disconnectButtons.exit.hidden=!0,this.disconnectButtons.goBack.hidden=0>=window.history.length,this.disconnectOverlay.classList.toggle("amp",this.ampIframe===e),this.disconnectOverlay.classList.add("disconnected")}isClientConnected(e){return e===this.ampIframe?Date.now()-this.ampHeartbeatTimestamp<2e3:Date.now()-this.nonAmpHeartbeatTimestamp<2e3}purgeRemovableQueryVars(e){return(0,n.removeQueryArgs)(e,o,m)}addPairedBrowsingQueryVar(e){return(0,n.addQueryArgs)(e,{[m]:"1"})}removeUrlHash(e){const t=new URL(e);return t.hash="",t.href}replaceLocation(e,t){this.sendMessage(e.contentWindow,"replaceLocation",{href:t})}receiveScroll({x:e,y:t},i){if(this.activeIframe||(this.activeIframe=this.isAmpWindow(i)?this.ampIframe:this.nonAmpIframe),!this.activeIframe||i!==this.activeIframe.contentWindow)return;const n=this.isAmpWindow(i)?this.nonAmpIframe.contentWindow:this.ampIframe.contentWindow;this.sendMessage(n,"scroll",{x:e,y:t})}receiveLoaded({isAmpDocument:e,ampUrl:t,nonAmpUrl:i,documentTitle:r},m){const h=this.isAmpWindow(m),d=h?this.ampIframe:this.nonAmpIframe;if(h){if(!e)return void this.replaceLocation(d,t);this.currentAmpUrl=t,this.ampLink.href=(0,n.removeQueryArgs)(t,o)}else{if(e)return void this.replaceLocation(d,i);this.currentNonAmpUrl=i,this.nonAmpLink.href=(0,n.addQueryArgs)(i,{[o]:a})}const p=h?i:t,l=h?this.currentNonAmpUrl:this.currentAmpUrl;if(this.purgeRemovableQueryVars(this.removeUrlHash(p))===this.purgeRemovableQueryVars(this.removeUrlHash(l)))document.title=c+" "+r,s.replaceState({},"",this.addPairedBrowsingQueryVar(this.purgeRemovableQueryVars(i)));else{const e=h?i:t;this.replaceLocation(h?this.nonAmpIframe:this.ampIframe,this.purgeRemovableQueryVars(e))}}}})();