
<!DOCTYPE html>
<html>
<head>
  <title>IPTV Libre</title>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <style>
    body {
      margin: 0;
      padding: 0;
      font-family: Arial, sans-serif;
    }
    #iframe-container {
      width: 100%;
      height: 60vh;
      border: none;
    }
    #banner-ad {
      width: 100%;
      height: 100px;
      background-color: #f0f0f0;
      text-align: center;
      margin-bottom: 10px;
    }
    #chatbox {
      width: 100%;
      height: 40vh;
      background-color: #f0f0f0;
      padding: 10px;
      border-top: 1px solid #ccc;
    }
    #chat-messages {
      overflow-y: auto;
      max-height: 70%;
    }
    #chat-input {
      width: 80%;
      height: 30px;
      padding: 10px;
      border: none;
      border-radius: 5px;
    }
    #send-btn {
      width: 20%;
      height: 30px;
      background-color: #4CAF50;
      color: #fff;
      border: none;
      border-radius: 5px;
    }
  </style>
</head>
<body>
  <div id="banner-ad">
    <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1649976574603208"
     crossorigin="anonymous"></script>
  </div>
  <div id="iframe-container">
    <iframe src="https://iptv-libre.pages.dev" frameborder="0" width="100%" height="100%" allow="encrypted-media *;"></iframe>
  </div>
  <div id="chatbox">
    <h2>Live Chat</h2>
    <div id="chat-messages"></div>
    <input type="text" id="chat-input" placeholder="Type a message...">
    <button id="send-btn">Send</button>
    <script>
      const chatInput = document.getElementById('chat-input');
      const chatMessages = document.getElementById('chat-messages');
      const sendBtn = document.getElementById('send-btn');

      loadChatLogs();
      setInterval(loadChatLogs, 1000); // update every 1 second

      sendBtn.addEventListener('click', () => {
        const message = chatInput.value.trim();
        if (message) {
          saveMessage(message);
          chatInput.value = '';
        }
      });

      function saveMessage(message) {
        fetch('save_message.php', {
          method: 'POST',
          headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
          body: `message=${message}`,
        })
        .then(() => loadChatLogs())
        .catch((error) => console.error('Error:', error));
      }

      function loadChatLogs() {
        fetch('chat.txt')
        .then((response) => response.text())
        .then((data) => {
          const messages = data.split('\n').map((line) => `<p>${line}</p>`);
          chatMessages.innerHTML = messages.join('');
          chatMessages.scrollTop = chatMessages.scrollHeight;
        })
        .catch((error) => console.error('Error:', error));
      }
    </script>
  </div>
</body>
</html>