/*************************************************************************
* ADOBE CONFIDENTIAL
* ___________________
*
*  Copyright 2015 Adobe Systems Incorporated
*  All Rights Reserved.
*
* NOTICE:  All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any.  The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and are protected by all applicable intellectual property laws,
* including trade secret and or copyright laws.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
**************************************************************************/
class FacebookExpressIntegration{previewEntryPointId="facebook-preview-adobe-express-entry-point";previewedImageClassname=["x15mokao x1ga7v0g x16uus16 xbiv7yw x193iq5w x4fas0m x19kjcj4"];previewHeaderClassname=["x9f619 x1ja2u2z x78zum5 x2lah0s x1n2onr6 x13a6bvl x1qjc9v5 xozqiw3 x1q0g3np xpdmqnj x1g0dm76 xyamay9 x1ws5yxj xw01apr x4cne27 xifccgj"];marketPlaceContainerClassname=["x6s0dn4 x78zum5 x1iyjqo2 xl56j7k x6ikm8r x10wlt62 xh8yej3 x1ja2u2z"];marketPlaceImageClassname=["xz74otr x15mokao x1ga7v0g x16uus16 xbiv7yw"];marketPlaceButtonClassName="facebookMarketPlacePreview";messengerHeaderClassname=["x9f619 x1ja2u2z x78zum5 x2lah0s x1n2onr6 x1qughib x1qjc9v5 xozqiw3 x1q0g3np xpdmqnj x1g0dm76 xexx8yu x1lxpwgx x165d6jo x4vbgl9 x1rdy4ex"];messengerImageClassname=["xt7dq6l x193iq5w x14atkfc","x19kjcj4"];touchpoint="facebookPreview";shownTouchpointOnce=!1;previewTypes=Object.freeze({MESSENGER:"messenger",MARKET_PLACE:"marketPlace",DEFAULT:"default"});previewType=this.previewTypes.DEFAULT;minifiedButton=!1;launchExpress=(e,t,s)=>{chrome.runtime.sendMessage({main_op:"launch-express",imgUrl:e,intent:s,touchpoint:t})};sendErrorLog=(e,t)=>{chrome.runtime.sendMessage({main_op:"log-error",log:{message:e,error:t}})};async loadContentScripts(){const e=chrome.runtime.getURL("content_scripts/express/single-click-cta.js"),t=chrome.runtime.getURL("content_scripts/express/express-utils.js"),s=await Promise.all([import(e),import(t)]);this.ExpressCTAClass=s[0].default,this.expressUtils=s[1].default,this.expressCTA=new this.ExpressCTAClass}_getPreviewImageElementFromSelector=()=>this.expressUtils.getElementsFromClassNames(document,this.previewedImageClassname)[0];_getMarketPlaceImageElementFromSelector=()=>{const e=this.expressUtils.getElementsFromClassNames(document,this.marketPlaceContainerClassname)[0];if(!e)return null;const t=this.expressUtils.getElementsFromClassNames(e,this.marketPlaceImageClassname)[0];return t&&"IMG"===t.tagName?t:null};_getImageElement=()=>this.previewType===this.previewTypes.MARKET_PLACE?this._getMarketPlaceImageElementFromSelector():this.previewType===this.previewTypes.MESSENGER?this._getMessengerImageElementFromSelector():this._getPreviewImageElementFromSelector();_getMessengerImageElementFromSelector=()=>{const e=this.expressUtils.getElementsFromClassNames(document,this.messengerHeaderClassname)[0];if(!e)return null;const t=e.parentElement?.parentElement;if(!t)return null;const s=this.expressUtils.getElementsFromClassNames(t,this.messengerImageClassname)[0];return s||null};_getPreviewImageAndHeaderElementFromSelector=()=>{let e=null;const t=this._getPreviewImageElementFromSelector(this.previewedImageClassname);if(!t)return{imageElement:t,headerElement:e};for(let s of this.previewHeaderClassname){const n=document.getElementsByClassName(s);if(n.length>0)for(let s of n)if(s?.parentElement?.parentElement?.contains(t)){e=s;break}}return{imageElement:t,headerElement:e}};_getMarketPlaceImageAndContainerElementFromSelector=()=>{const e=this.expressUtils.getElementsFromClassNames(document,this.marketPlaceContainerClassname)[0];if(!e)return{imageElement:null,marketPlaceContainer:null};const t=this._getMarketPlaceImageElementFromSelector();return t?{imageElement:t,marketPlaceContainer:e}:{imageElement:null,marketPlaceContainer:null}};_getMessengerImageAndHeaderElementFromSelector=()=>{const e=this.expressUtils.getElementsFromClassNames(document,this.messengerHeaderClassname)[0];if(!e)return{imageElement:null,headerElement:null};const t=e.parentElement.parentElement,s=this.expressUtils.getElementsFromClassNames(t,this.messengerImageClassname)[0];return s?{imageElement:s,headerElement:e}:{imageElement:null,headerElement:null}};_getHeaderAndImageElementFromSelector=()=>{let e=null,t=null;return({imageElement:e,headerElement:t}=this._getPreviewImageAndHeaderElementFromSelector()),e&&t?(this.previewType=this.previewTypes.DEFAULT,{imageElement:e,headerElement:t}):(({imageElement:e,marketPlaceContainer:t}=this._getMarketPlaceImageAndContainerElementFromSelector()),e&&t?(this.previewType=this.previewTypes.MARKET_PLACE,{imageElement:e,headerElement:t}):(({imageElement:e,headerElement:t}=this._getMessengerImageAndHeaderElementFromSelector()),e&&t?(this.previewType=this.previewTypes.MESSENGER,{imageElement:e,headerElement:t}):{imageElement:e,headerElement:t}))};addButtonClass=e=>{this.previewType===this.previewTypes.MARKET_PLACE&&e.classList.add(this.marketPlaceButtonClassName)};addThumbnailAndImagePreviewerObserver=()=>{new MutationObserver(()=>{this.config.enableFacebookPreviewExpressMenu&&this.imagePreviewerObserverHandler()}).observe(document.body,{childList:!0,subtree:!0}),this.runOnceOnStartup()};runOnceOnStartup=()=>{this.imagePreviewerObserverHandler()};previewEntryPointClickHandler=e=>{if(!chrome?.runtime?.id)return void this.cleanup();const t=this._getImageElement();if(!t||"IMG"!==t.tagName)return void this.sendErrorLog("Error executing express in facebook","image element not found");const s=t.src;s?this.launchExpress(s,this.touchpoint,e):this.sendErrorLog("Error executing express in facebook","image URL not found")};toggleButtonSize=(e,t=document)=>{const s=t.getElementsByClassName("cc440d50ba-express-entrypoint-button-text")[0];if(!s)return;s.classList?.toggle("minified",e);const n=t.getElementsByClassName("cc440d50ba-express-entrypoint-button-icon")[0];n&&n.classList.toggle("minified",e)};imagePreviewerObserverHandler=()=>{if(!chrome?.runtime?.id)return void this.cleanup();const e=document.getElementById(this.previewEntryPointId);let{imageElement:t,headerElement:s}=this._getHeaderAndImageElementFromSelector();s&&t&&"IMG"===t.tagName?e||(this.cleanupTooltip(),this.addPreviewEntryPoint(s,t,this.previewEntryPointId,this.previewEntryPointClickHandler),this.expressUtils.sendAnalyticsEventOncePerDay([["DCBrowserExt:Express:Facebook:PreviewEntryPoint:Shown"]])):this.cleanup()};buttonResizeHandler=()=>{const e=this._getImageElement(),t=document.getElementById(this.previewEntryPointId);if(!e||!t)return;const s=e.getBoundingClientRect(),n=t.getBoundingClientRect();0===n.width&&0===n.height||s.right>=n.left&&s.top<=n.bottom&&setTimeout(()=>{this.minifiedButton=!0,this.toggleButtonSize(this.minifiedButton)},1e3)};tooltipDelayCallback=()=>this.minifiedButton?1500:400;addPreviewEntryPoint=async(e,t,s,n)=>{if(document.getElementById(s)||this.buttonRenderStarted)return;this.buttonRenderStarted=!0;const r=await this.expressCTA.renderMenuButton(n,this.touchpoint);if(r.id=s,this.addButtonClass(r),this.toggleButtonSize(this.minifiedButton,r),e.insertBefore(r,e.firstChild),this.tooltip=this.expressCTA.attachTooltip("bottom",this.tooltipDelayCallback),this.buttonRenderStarted=!1,t.addEventListener("load",()=>{this.buttonResizeHandler()}),this.minifiedButton)return;const i=new MutationObserver(()=>{this.buttonResizeHandler(),this.minifiedButton&&i.disconnect()});i.observe(e.parentElement.parentElement,{childList:!0,subtree:!0,attributes:!0});const a=new ResizeObserver(()=>{this.buttonResizeHandler(),this.minifiedButton&&a.disconnect()});a.observe(e.parentElement.parentElement)};removePreviewEntryPoint=e=>{const t=document.getElementById(e);t&&t.remove()};cleanup=()=>{this.previewType=this.previewTypes.DEFAULT,this.removePreviewEntryPoint(this.previewEntryPointId),this.cleanupTooltip()};cleanupTooltip=()=>{this.tooltip?.tooltip?.remove(),this.tooltip=null;const e=document.getElementsByClassName("cc440d50ba-tooltiptext");for(let t of e)t.remove()};init=async()=>{const e=await chrome.runtime.sendMessage({main_op:"facebook-express-init"});this.config=e,this.config.enableFacebookPreviewExpressMenu&&(this.previewedImageClassname=this.config.selectors?.previewedImageClassname||this.previewedImageClassname,this.previewHeaderClassname=this.config.selectors?.previewHeaderClassname||this.previewHeaderClassname,this.marketPlaceContainerClassname=this.config.selectors?.marketPlaceContainerClassname||this.marketPlaceContainerClassname,this.marketPlaceImageClassname=this.config.selectors?.marketPlaceImageClassname||this.marketPlaceImageClassname,this.messengerHeaderClassname=this.config.selectors?.messengerHeaderClassname||this.messengerHeaderClassname,this.messengerImageClassname=this.config.selectors?.messengerImageClassname||this.messengerImageClassname,await this.loadContentScripts(),this.addThumbnailAndImagePreviewerObserver())}}const facebookExpressIntegration=new FacebookExpressIntegration;facebookExpressIntegration.init();