<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document Download Page</title>
    <style>
        body {
            font-family: Arial, sans-serif;
        }
        ul {
            list-style-type: none;
        }
        li {
            margin: 5px 0;
        }
        #content {
            display: none;
        }
        #password-prompt {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }
    </style>
</head>
<body>
    <div id="password-prompt">
        <input type="password" id="password-input" placeholder="Enter password">
        <button onclick="checkPassword()">Submit</button>
    </div>
    <div id="content">
        <h1>Download Documents</h1>
        <ul id="document-list"></ul>
    </div>
    <script>
        const correctPassword = "your-password"; // Replace with your desired password

        function checkPassword() {
            const enteredPassword = document.getElementById('password-input').value;
            if (enteredPassword === correctPassword) {
                document.getElementById('password-prompt').style.display = 'none';
                document.getElementById('content').style.display = 'block';
                fetchDocuments();
            } else {
                alert('Incorrect password. Please try again.');
            }
        }

        async function fetchDocuments() {
            const response = await fetch('https://api.github.com/repos/lungdrug/SW/contents/');
            const data = await response.json();
            const documentList = document.getElementById('document-list');

            data.forEach(item => {
                if (item.type === 'dir') {
                    fetchFolderContents(item.path);
                } else if (item.type === 'file') {
                    addDocumentLink(item.path, item.name);
                }
            });
        }

        async function fetchFolderContents(folderPath) {
            const response = await fetch(`https://api.github.com/repos/lungdrug/SW/contents/${folderPath}`);
            const data = await response.json();
            data.forEach(item => {
                if (item.type === 'file') {
                    addDocumentLink(item.path, item.name);
                }
            });
        }

        function addDocumentLink(filePath, fileName) {
            const documentList = document.getElementById('document-list');
            const listItem = document.createElement('li');
            const link = document.createElement('a');
            link.href = `https://raw.githubusercontent.com/lungdrug/SW/main/${filePath}`;
            link.download = fileName;
            link.textContent = `Download ${fileName}`;
            listItem.appendChild(link);
            documentList.appendChild(listItem);
        }
    </script>
</body>
</html>