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