File "export_002.html"

Full Path: /home/analogde/www/Diabete/Provisoire/export_002.html
File size: 2.96 KB
MIME-type: text/html
Charset: utf-8

<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Générateur de chaînes JSON</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background-color: #f0f0f0;
        }

        .container {
            background-color: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            text-align: center;
        }

        button {
            background-color: #007BFF;
            color: white;
            border: none;
            padding: 10px 20px;
            margin: 5px;
            border-radius: 4px;
            cursor: pointer;
        }

        button:hover {
            background-color: #0056b3;
        }

        #jsonOutput {
            margin-top: 20px;
            text-align: left;
            background-color: #f8f9fa;
            padding: 10px;
            border-radius: 4px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>Générateur de chaînes JSON</h1>
        <button id="generateBtn">Générer les chaînes</button>
        <button id="saveBtn">Sauvegarder</button>
        <pre id="jsonOutput"></pre>
    </div>
    <script>
        document.getElementById('generateBtn').addEventListener('click', function() {
            const strings = [];
            for (let i = 0; i < 10; i++) {
                strings.push(`Chaîne ${i + 1}`);
            }
            const jsonData = JSON.stringify(strings, null, 2);
            document.getElementById('jsonOutput').textContent = jsonData;
        });

        document.getElementById('saveBtn').addEventListener('click', async function() {
            const jsonData = document.getElementById('jsonOutput').textContent;
            if (!jsonData) {
                alert('Veuillez d\'abord générer les chaînes.');
                return;
            }

            try {
                const options = {
                    types: [{
                        description: 'JSON Files',
                        accept: {
                            'application/json': ['.json'],
                        },
                    }],
                    suggestedName: 'chaines.json',
                };

                const fileHandle = await window.showSaveFilePicker(options);
                const writableStream = await fileHandle.createWritable();
                await writableStream.write(jsonData);
                await writableStream.close();

                alert('Fichier sauvegardé avec succès!');
            } catch (error) {
                console.error('Erreur lors de la sauvegarde du fichier:', error);
                alert('Erreur lors de la sauvegarde du fichier.');
            }
        });
    </script>
</body>
</html>