| 1 |
import domReady from '@wordpress/dom-ready'; |
| 2 |
import '@shared/shared.css'; |
| 3 |
import { EditPageToolTip } from '@shared/components/EditPageToolTip'; |
| 4 |
import '@shared/lib/api-fetch'; |
| 5 |
import { ProductAccountActivation } from '@shared/components/ProductAccountActivation/ProductAccountActivation'; |
| 6 |
import { render } from '@shared/lib/dom'; |
| 7 |
import { preFetchImages as preFetchUnsplashImages } from '@shared/lib/unsplash'; |
| 8 |
|
| 9 |
const showAIAgents = window.extSharedData.showAIAgents; |
| 10 |
|
| 11 |
const isOnLaunch = () => { |
| 12 |
const query = new URLSearchParams(window.location.search); |
| 13 |
const page = query.get('page'); |
| 14 |
return page === 'extendify-launch' || page === 'extendify-auto-launch'; |
| 15 |
}; |
| 16 |
|
| 17 |
domReady(() => { |
| 18 |
if (isOnLaunch()) return; |
| 19 |
|
| 20 |
preFetchUnsplashImages(); |
| 21 |
|
| 22 |
const urlParams = new URLSearchParams(window.location.search); |
| 23 |
|
| 24 |
if (!urlParams.has('extendify-launch-success')) return; |
| 25 |
|
| 26 |
if (window.extSharedData?.showProductActivation?.length) { |
| 27 |
const container = Object.assign(document.createElement('div'), { |
| 28 |
id: 'extendify-product-activation-container', |
| 29 |
}); |
| 30 |
|
| 31 |
document.body.appendChild(container); |
| 32 |
|
| 33 |
render(<ProductAccountActivation />, container); |
| 34 |
} |
| 35 |
|
| 36 |
const currentUrl = new URL(window.location.href); |
| 37 |
// Remove the query param so it doesn't show again |
| 38 |
urlParams.delete('extendify-launch-success'); |
| 39 |
const newUrl = `${currentUrl.origin}${currentUrl.pathname}`; |
| 40 |
window.history.replaceState({}, '', newUrl); |
| 41 |
// Trigger an event other features can listen to |
| 42 |
// Give time for others to add listeners |
| 43 |
requestAnimationFrame(() => { |
| 44 |
requestAnimationFrame(() => { |
| 45 |
window.dispatchEvent(new CustomEvent('extendify-launch-success')); |
| 46 |
// Open the Agent if not open |
| 47 |
window.dispatchEvent(new CustomEvent('extendify-agent:open')); |
| 48 |
}); |
| 49 |
}); |
| 50 |
if (showAIAgents) return; |
| 51 |
// This will show the toolbar for users not using AI Agent |
| 52 |
// but are redirected to home |
| 53 |
const homeUrl = new URL(window.extSharedData.homeUrl); |
| 54 |
const isHomePage = |
| 55 |
currentUrl.origin === homeUrl.origin && |
| 56 |
currentUrl.pathname === homeUrl.pathname; |
| 57 |
if (!isHomePage) return; |
| 58 |
const div = Object.assign(document.createElement('div'), { |
| 59 |
id: 'extendify-edit-page-modal-tooltip', |
| 60 |
}); |
| 61 |
document.body.appendChild(div); |
| 62 |
render(<EditPageToolTip />, div); |
| 63 |
}); |
| 64 |
|