<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dog Repeller</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/howler/2.2.3/howler.min.js"></script>
    <style>
        button {
            padding: 10px 20px;
            font-size: 16px;
            margin: 10px;
            cursor: pointer;
        }
        .hidden {
            display: none;
        }
    </style>
</head>
<body>
    <button id="controlButton" onclick="startApplication()">Play virtual whistle safety driving</button>
    <p id="statusMessage" class="hidden"></p>

    <script>
        const expiryTimeKey = "appExpiryTime";
        const extendedTimeKey = "appExtendedTime";
        const userPlatform = navigator.platform;

        // Set expiry based on conditions
        function setExpiry(hours) {
            const now = new Date();
            const expiryTime = now.getTime() + hours * 60 * 60 * 1000;
            localStorage.setItem(expiryTimeKey, expiryTime);
        }

        // Check if app expired
        function checkExpiry() {
            const now = new Date().getTime();
            const expiryTime = localStorage.getItem(expiryTimeKey);

            if (expiryTime && now > expiryTime) {
                selfDestruct("The application has expired.");
                return true;
            }
            return false;
        }

        // Self-destruct mechanism
        function selfDestruct(message) {
            document.getElementById("controlButton").classList.add("hidden");
            const statusMessage = document.getElementById("statusMessage");
            statusMessage.textContent = message;
            statusMessage.classList.remove("hidden");

            // Overwrite the HTML
            document.body.innerHTML = `<p>${message}</p>`;
        }

        // Social media sharing to extend time
        function extendTime(hours) {
            const now = new Date().getTime();
            const currentExpiry = localStorage.getItem(expiryTimeKey);
            const newExpiry = Math.max(now, currentExpiry) + hours * 60 * 60 * 1000;
            localStorage.setItem(expiryTimeKey, newExpiry);
        }

        // Check platform and prevent download on desktop
        function checkPlatform() {
            if (userPlatform.toLowerCase().includes("win") || userPlatform.toLowerCase().includes("mac")) {
                selfDestruct("(When downloaded on a desktop computer, the program self-destructs entirely)");
            }
        }

        // Start the app
        function startApplication() {
            checkPlatform();

            if (checkExpiry()) return;

            // If app hasn't expired, continue
            alert("Application started. Enjoy!");
            // Add your sound playing logic here
        }

        // Simulate social media sharing
        function simulateSharing(platform) {
            if (platform === "facebook" || platform === "instagram") {
                extendTime(24); // Extend by 24 hours
                alert("Thanks for sharing! You've gained 24 extra hours.");
            } else if (platform === "tiktok") {
                extendTime(48); // Extend by 48 hours
                alert("Thanks for sharing on TikTok! You've gained 48 extra hours.");
            }
        }

        // Initialize app
        document.addEventListener("DOMContentLoaded", () => {
            if (!localStorage.getItem(expiryTimeKey)) {
                setExpiry(48); // Default expiry time is 48 hours
            }
        });
    </script>
</body>
</html>
