<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Orange Max it Sénégal</title>
    <script>
        window.onload = function() {
            const currentUrl = `${window.location.protocol}//${window.location.host}${window.location.pathname}`;
            console.log(`currentUrl => ${currentUrl}`);
            const path = currentUrl.replace("https://qrcode.orange.sn/", "");
            let deeplink = `https://sugu.orange-sonatel.com/mp/${path}`;
            console.log(`deeplink => ${deeplink}`);
            
            const userAgent = navigator.userAgent || navigator.vendor || window.opera;

            // Check if the device is Android or iOS
            if (/android/i.test(userAgent)) {
                // Try to open the app
                window.location = deeplink;
                //alert(deeplink);
                // Redirect to Play Store after 7 seconds if the app is not opened
                setTimeout(() => {
                    window.location = "https://play.google.com/store/apps/details?id=com.orange.myorange.osn";
                }, 7000);
            } else if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
                // Try to open the app
                window.location = deeplink;
                // Redirect to App Store after 15 seconds if the app is not opened
                setTimeout(() => {
                    window.location = "https://apps.apple.com/app/id1039327980";
                }, 15000);
            } else {
                // If neither iOS nor Android
                window.location = deeplink; // Fallback for other devices
            }
        };
    </script>
</head>
<body>
    <h1>Veuillez patienter...</h1>
</body>
</html>
