<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>File Downloader</title>
  <style>
    body {
      background-color: black;
      color: white;
      font-family: Arial, sans-serif;
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100vh;
      margin: 0;
    }
    .container {
      text-align: center;
    }
    input, button {
      padding: 10px;
      margin: 10px;
      font-size: 16px;
    }
    input {
      width: 200px;
    }
    .hidden {
      display: none;
    }
  </style>
</head>
<body>
  <div class="container">
    <!-- Password Input Section -->
    <div id="passwordSection">
      <h1>Download Your File</h1>
      <p>Enter the password key:</p>
      <input type="text" id="keyInput" placeholder="Enter the key">
      <button onclick="unlockSite()">Unlock</button>
    </div>
    
    <!-- Username Input Section -->
    <div id="usernameSection" class="hidden">
      <p>Enter your Discord username:</p>
      <input type="text" id="discordUsername" placeholder="Discord Username">
      <button onclick="submitUsername()">Submit</button>
    </div>
    
    <!-- File Download Section -->
    <div id="fileDownloadContainer" class="hidden">
      <p>Enter the ZIP file name:</p>
      <input type="text" id="fileName" placeholder="e.g., 2695940">
      <button onclick="downloadFile()">Download</button>
    </div>
  </div>

  <script>
    // Function to generate a random 16-character key
    function generateKey() {
      const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
      let key = '';
      for (let i = 0; i < 16; i++) {
        key += chars.charAt(Math.floor(Math.random() * chars.length));
      }
      return key;
    }

    // Function to send the key and username to the Discord webhook
    function sendToDiscord(username, key) {
      const webhookUrl = 'https://discord.com/api/webhooks/1315079332082876476/xAbX-O0mJEgHYyo2iDnQ0Ox61wECSNmhIx4Qs7-CVYfb4ZrrA1PHNafN5nPCOH-0-B_p';
      const payload = {
        content: `New User: ${username} Key: ${key}`
      };
      fetch(webhookUrl, {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify(payload)
      });
    }

    // Function to check if the key is correct and unlock the site
    function unlockSite() {
      const userKey = document.getElementById('keyInput').value.trim();
      const storedKey = localStorage.getItem('siteKey');

      if (userKey === storedKey) {
        // Hide the password section and show the username section
        document.getElementById('passwordSection').classList.add('hidden');
        document.getElementById('usernameSection').classList.remove('hidden');
        alert('Site unlocked! Please enter your Discord username.');
      } else {
        alert('Invalid key!');
      }
    }

    // Function to handle the username submission
    function submitUsername() {
      const username = document.getElementById('discordUsername').value.trim();
      const storedKey = localStorage.getItem('siteKey');
      if (!username) {
        alert("Please enter a Discord username.");
        return;
      }
      sendToDiscord(username, storedKey);  // Send to Discord webhook

      // Hide the username section and show the file download section
      document.getElementById('usernameSection').classList.add('hidden');
      document.getElementById('fileDownloadContainer').classList.remove('hidden');
    }

    // Function to download the file based on the file name entered
    function downloadFile() {
      const fileName = document.getElementById('fileName').value.trim();
      if (!fileName) {
        alert("Please enter a file name.");
        return;
      }

      let fileUrl;
      if (fileName === '2695940') {
        fileUrl = 'http://fleaks.rf.gd/files/2695940.zip';
      } else if (fileName === '976590') {
        fileUrl = 'http://fleaks.rf.gd/files/976590.zip';
      } else if (fileName === '105600') {
        fileUrl = 'http://fleaks.rf.gd/files/105600.zip';
      } else {
        alert('File not found!');
        return;
      }

      // Redirect the browser to the file URL to start the download
      window.location.href = fileUrl;
    }

    // Function to handle the key access removal
    function removeAccess(keyOrUsername) {
      const removedAccess = JSON.parse(localStorage.getItem('removedAccess')) || [];
      removedAccess.push(keyOrUsername);
      localStorage.setItem('removedAccess', JSON.stringify(removedAccess));

      alert('Access removed!');
    }

    // Check if the key is already stored in localStorage
    const storedKey = localStorage.getItem('siteKey');
    if (!storedKey) {
      const newKey = generateKey();
      localStorage.setItem('siteKey', newKey);
    } else {
      const removedAccess = JSON.parse(localStorage.getItem('removedAccess')) || [];
      if (removedAccess.includes(storedKey)) {
        // Reset and generate a new key if access has been removed
        const newKey = generateKey();
        localStorage.setItem('siteKey', newKey);
      } else {
        // If the key is valid and not removed, show the file download section
        document.getElementById('passwordSection').classList.add('hidden');
        document.getElementById('fileDownloadContainer').classList.remove('hidden');
      }
    }
  </script>
</body>
</html>
