| import {StrictMode} from 'react'; |
| import {createRoot} from 'react-dom/client'; |
| import App, { renderTurnstileWidgets } from './App.tsx'; |
| import { ensureTurnstileScript } from './turnstile'; |
| import { initI18n } from './i18n'; |
| import { initSentry } from './sentry'; |
| import { initDebugBearRum } from './debugbear-rum'; |
| import './index.css'; |
|
|
| initSentry(); |
| initDebugBearRum(); |
|
|
| initI18n().then(() => { |
| createRoot(document.getElementById('root')!).render( |
| <StrictMode> |
| <App /> |
| </StrictMode>, |
| ); |
|
|
| |
| |
| |
| const renderWhenReady = () => { |
| if (window.turnstile && renderTurnstileWidgets() > 0) return; |
| let attempts = 0; |
| const retryInterval = window.setInterval(() => { |
| if ((window.turnstile && renderTurnstileWidgets() > 0) || ++attempts >= 20) { |
| window.clearInterval(retryInterval); |
| } |
| }, 250); |
| }; |
|
|
| const ensureTurnstile = () => { |
| void ensureTurnstileScript().then((loaded) => { |
| if (loaded) renderWhenReady(); |
| }); |
| }; |
|
|
| |
| |
| |
| |
| const isEnterpriseHash = () => window.location.hash.startsWith('#enterprise'); |
| const armViewportTrigger = (findAttempts = 0) => { |
| const widget = document.querySelector<HTMLElement>('.cf-turnstile'); |
| if (!widget) { |
| if (findAttempts < 20) window.setTimeout(() => armViewportTrigger(findAttempts + 1), 250); |
| return; |
| } |
| if (widget.dataset.wmObserved) return; |
| widget.dataset.wmObserved = 'true'; |
| if (!('IntersectionObserver' in window)) { |
| ensureTurnstile(); |
| return; |
| } |
| const observer = new IntersectionObserver((entries) => { |
| if (entries.some((entry) => entry.isIntersecting)) { |
| observer.disconnect(); |
| ensureTurnstile(); |
| } |
| }, { rootMargin: '600px 0px' }); |
| observer.observe(widget); |
| }; |
|
|
| if (isEnterpriseHash()) armViewportTrigger(); |
| window.addEventListener('hashchange', () => { |
| |
| |
| if (isEnterpriseHash()) armViewportTrigger(); |
| }); |
| }); |
|
|