Sindbad~EG File Manager

Current Path : /home/copmadinaarea/thecopmadinaarea.org/portal/
Upload File :
Current File : /home/copmadinaarea/thecopmadinaarea.org/portal/update_service_worker.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Update Service Worker</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
</head>
<body class="bg-gray-100 flex items-center justify-center min-h-screen">
    <div class="bg-white rounded-lg shadow-lg p-8 max-w-2xl">
        <h1 class="text-3xl font-bold text-gray-800 mb-4">
            <i class="fas fa-sync-alt text-blue-500 mr-2"></i>
            Update Service Worker
        </h1>
        <p class="text-gray-600 mb-6">Updating service worker to fix toggle issue...</p>
        
        <div id="status" class="mb-6 p-4 rounded-lg bg-blue-50 border border-blue-200">
            <p class="text-blue-800">
                <i class="fas fa-spinner fa-spin mr-2"></i>
                Processing...
            </p>
        </div>

        <div id="actions" class="hidden">
            <a href="modules/module-management/index.php" 
               class="inline-block px-6 py-3 bg-gradient-to-r from-blue-500 to-purple-600 text-white rounded-lg hover:from-blue-600 hover:to-purple-700 transition shadow-lg">
                <i class="fas fa-arrow-right mr-2"></i>
                Go to Module Management
            </a>
        </div>
    </div>

    <script>
        async function updateServiceWorker() {
            const statusDiv = document.getElementById('status');
            const actionsDiv = document.getElementById('actions');
            
            try {
                if ('serviceWorker' in navigator) {
                    // Get all registrations
                    const registrations = await navigator.serviceWorker.getRegistrations();
                    
                    statusDiv.innerHTML = `
                        <p class="text-blue-800">
                            <i class="fas fa-spinner fa-spin mr-2"></i>
                            Found ${registrations.length} service worker(s). Unregistering...
                        </p>
                    `;
                    
                    // Unregister all
                    for (let registration of registrations) {
                        await registration.unregister();
                        console.log('Unregistered:', registration);
                    }
                    
                    statusDiv.innerHTML = `
                        <p class="text-blue-800">
                            <i class="fas fa-spinner fa-spin mr-2"></i>
                            Clearing caches...
                        </p>
                    `;
                    
                    // Clear all caches
                    const cacheNames = await caches.keys();
                    for (let cacheName of cacheNames) {
                        await caches.delete(cacheName);
                        console.log('Deleted cache:', cacheName);
                    }
                    
                    statusDiv.innerHTML = `
                        <p class="text-green-800">
                            <i class="fas fa-check-circle mr-2"></i>
                            <strong>Success!</strong> Service worker updated and caches cleared.
                        </p>
                        <p class="text-sm text-green-700 mt-2">
                            The new service worker will register automatically when you visit other pages.
                        </p>
                    `;
                    statusDiv.className = 'mb-6 p-4 rounded-lg bg-green-50 border border-green-200';
                    
                    actionsDiv.classList.remove('hidden');
                    
                } else {
                    statusDiv.innerHTML = `
                        <p class="text-yellow-800">
                            <i class="fas fa-exclamation-triangle mr-2"></i>
                            Service workers not supported in this browser.
                        </p>
                    `;
                    statusDiv.className = 'mb-6 p-4 rounded-lg bg-yellow-50 border border-yellow-200';
                    actionsDiv.classList.remove('hidden');
                }
            } catch (error) {
                console.error('Error:', error);
                statusDiv.innerHTML = `
                    <p class="text-red-800">
                        <i class="fas fa-exclamation-circle mr-2"></i>
                        <strong>Error:</strong> ${error.message}
                    </p>
                `;
                statusDiv.className = 'mb-6 p-4 rounded-lg bg-red-50 border border-red-200';
            }
        }

        // Run on page load
        updateServiceWorker();
    </script>
</body>
</html>

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists