Advertisement
Kelsondre69

Site

May 20th, 2025
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  6. <title>Anonymous Chat</title>
  7. <style>
  8. body {
  9. background-color: white;
  10. font-family: Arial, sans-serif;
  11. margin: 0;
  12. padding: 0;
  13. }
  14. .chat-container {
  15. max-width: 600px;
  16. margin: 40px auto;
  17. padding: 20px;
  18. border: 2px solid #ddd;
  19. border-radius: 8px;
  20. height: 80vh;
  21. display: flex;
  22. flex-direction: column;
  23. background-color: #fff;
  24. }
  25. h2 {
  26. text-align: center;
  27. margin-bottom: 10px;
  28. color: #333;
  29. }
  30. .messages {
  31. flex: 1;
  32. overflow-y: auto;
  33. padding: 10px;
  34. border: 1px solid #ccc;
  35. margin-bottom: 10px;
  36. background: #fafafa;
  37. border-radius: 5px;
  38. }
  39. .message {
  40. margin-bottom: 10px;
  41. padding: 8px 12px;
  42. background-color: #e6e6e6;
  43. border-radius: 6px;
  44. }
  45. .input-container {
  46. display: flex;
  47. gap: 10px;
  48. }
  49. input[type="text"] {
  50. flex: 1;
  51. padding: 10px;
  52. font-size: 16px;
  53. border: 1px solid #aaa;
  54. border-radius: 4px;
  55. }
  56. button {
  57. padding: 10px 15px;
  58. font-size: 16px;
  59. background-color: #333;
  60. color: white;
  61. border: none;
  62. border-radius: 4px;
  63. cursor: pointer;
  64. }
  65. </style>
  66. </head>
  67. <body>
  68. <div class="chat-container">
  69. <h2>Anonymous Chat</h2>
  70. <div class="messages" id="messages"></div>
  71. <div class="input-container">
  72. <input type="text" id="chatInput" placeholder="Type your message..." />
  73. <button onclick="sendMessage()">Send</button>
  74. </div>
  75. </div>
  76.  
  77. <!-- Firebase SDKs -->
  78. <script src="https://www.gstatic.com/firebasejs/9.0.0/firebase-app-compat.js"></script>
  79. <script src="https://www.gstatic.com/firebasejs/9.0.0/firebase-database-compat.js"></script>
  80. <script>
  81. // Replace with your Firebase project config
  82. const firebaseConfig = {
  83. apiKey: "YOUR_API_KEY",
  84. authDomain: "YOUR_PROJECT_ID.firebaseapp.com",
  85. databaseURL: "https://YOUR_PROJECT_ID.firebaseio.com",
  86. projectId: "YOUR_PROJECT_ID",
  87. storageBucket: "YOUR_PROJECT_ID.appspot.com",
  88. messagingSenderId: "YOUR_SENDER_ID",
  89. appId: "YOUR_APP_ID"
  90. };
  91.  
  92. firebase.initializeApp(firebaseConfig);
  93. const db = firebase.database();
  94. const messagesRef = db.ref("messages");
  95.  
  96. function sendMessage() {
  97. const input = document.getElementById("chatInput");
  98. const text = input.value.trim();
  99. if (text) {
  100. messagesRef.push({ text: text, timestamp: Date.now() });
  101. input.value = "";
  102. }
  103. }
  104.  
  105. messagesRef.on("child_added", (snapshot) => {
  106. const msg = snapshot.val();
  107. const msgDiv = document.createElement("div");
  108. msgDiv.classList.add("message");
  109. msgDiv.textContent = msg.text;
  110. document.getElementById("messages").appendChild(msgDiv);
  111. const container = document.getElementById("messages");
  112. container.scrollTop = container.scrollHeight;
  113. });
  114. </script>
  115. </body>
  116. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement