Spaces:
Running
Running
Kağan Muslu commited on
Add 3 files
Browse files- README.md +7 -5
- index.html +842 -19
- prompts.txt +0 -0
README.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: modern-chat-interface
|
| 3 |
+
emoji: 🐳
|
| 4 |
+
colorFrom: purple
|
| 5 |
+
colorTo: purple
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
+
tags:
|
| 9 |
+
- deepsite
|
| 10 |
---
|
| 11 |
|
| 12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
index.html
CHANGED
|
@@ -1,19 +1,842 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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>Modern Chat Interface</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
| 9 |
+
<style>
|
| 10 |
+
/* Custom scrollbar */
|
| 11 |
+
.custom-scrollbar::-webkit-scrollbar {
|
| 12 |
+
width: 6px;
|
| 13 |
+
}
|
| 14 |
+
.custom-scrollbar::-webkit-scrollbar-track {
|
| 15 |
+
background: #f1f1f1;
|
| 16 |
+
border-radius: 10px;
|
| 17 |
+
}
|
| 18 |
+
.custom-scrollbar::-webkit-scrollbar-thumb {
|
| 19 |
+
background: #888;
|
| 20 |
+
border-radius: 10px;
|
| 21 |
+
}
|
| 22 |
+
.custom-scrollbar::-webkit-scrollbar-thumb:hover {
|
| 23 |
+
background: #555;
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
/* Animation for new messages */
|
| 27 |
+
@keyframes fadeIn {
|
| 28 |
+
from { opacity: 0; transform: translateY(10px); }
|
| 29 |
+
to { opacity: 1; transform: translateY(0); }
|
| 30 |
+
}
|
| 31 |
+
.message-animation {
|
| 32 |
+
animation: fadeIn 0.3s ease-out;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
/* Pulse animation for active users */
|
| 36 |
+
@keyframes pulse {
|
| 37 |
+
0%, 100% { opacity: 1; }
|
| 38 |
+
50% { opacity: 0.5; }
|
| 39 |
+
}
|
| 40 |
+
.pulse-active {
|
| 41 |
+
animation: pulse 2s infinite;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
/* Tab styling */
|
| 45 |
+
.tab {
|
| 46 |
+
position: relative;
|
| 47 |
+
padding: 0.5rem 1rem;
|
| 48 |
+
cursor: pointer;
|
| 49 |
+
border-radius: 0.5rem 0.5rem 0 0;
|
| 50 |
+
transition: all 0.2s;
|
| 51 |
+
}
|
| 52 |
+
.tab.active {
|
| 53 |
+
background-color: white;
|
| 54 |
+
color: #4f46e5;
|
| 55 |
+
font-weight: 600;
|
| 56 |
+
}
|
| 57 |
+
.tab.active::after {
|
| 58 |
+
content: '';
|
| 59 |
+
position: absolute;
|
| 60 |
+
bottom: -1px;
|
| 61 |
+
left: 0;
|
| 62 |
+
right: 0;
|
| 63 |
+
height: 2px;
|
| 64 |
+
background-color: #4f46e5;
|
| 65 |
+
}
|
| 66 |
+
.tab-badge {
|
| 67 |
+
position: absolute;
|
| 68 |
+
top: -0.5rem;
|
| 69 |
+
right: -0.5rem;
|
| 70 |
+
background-color: #ef4444;
|
| 71 |
+
color: white;
|
| 72 |
+
border-radius: 50%;
|
| 73 |
+
width: 1.25rem;
|
| 74 |
+
height: 1.25rem;
|
| 75 |
+
display: flex;
|
| 76 |
+
align-items: center;
|
| 77 |
+
justify-content: center;
|
| 78 |
+
font-size: 0.75rem;
|
| 79 |
+
}
|
| 80 |
+
</style>
|
| 81 |
+
</head>
|
| 82 |
+
<body class="bg-gray-100 font-sans">
|
| 83 |
+
<!-- Main Container -->
|
| 84 |
+
<div class="container mx-auto px-4 py-8 max-w-6xl">
|
| 85 |
+
<!-- Login Section (shown by default) -->
|
| 86 |
+
<div id="login-section" class="bg-white rounded-xl shadow-lg p-8 max-w-md mx-auto mb-8 transition-all duration-300">
|
| 87 |
+
<div class="text-center mb-6">
|
| 88 |
+
<h1 class="text-3xl font-bold text-indigo-600">Welcome to ChatApp</h1>
|
| 89 |
+
<p class="text-gray-500 mt-2">Connect with people around the world</p>
|
| 90 |
+
</div>
|
| 91 |
+
<div class="space-y-4">
|
| 92 |
+
<div>
|
| 93 |
+
<label for="username" class="block text-sm font-medium text-gray-700 mb-1">Username</label>
|
| 94 |
+
<input type="text" id="username" placeholder="Enter your username"
|
| 95 |
+
class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 transition">
|
| 96 |
+
</div>
|
| 97 |
+
<button id="login-btn"
|
| 98 |
+
class="w-full bg-indigo-600 text-white py-2 px-4 rounded-lg hover:bg-indigo-700 transition flex items-center justify-center">
|
| 99 |
+
<i class="fas fa-sign-in-alt mr-2"></i> Login
|
| 100 |
+
</button>
|
| 101 |
+
</div>
|
| 102 |
+
</div>
|
| 103 |
+
|
| 104 |
+
<!-- Main Chat Interface (hidden by default) -->
|
| 105 |
+
<div id="chat-interface" class="hidden">
|
| 106 |
+
<!-- Header with user info -->
|
| 107 |
+
<div class="flex justify-between items-center mb-6">
|
| 108 |
+
<div class="flex items-center">
|
| 109 |
+
<div class="w-10 h-10 rounded-full bg-indigo-500 flex items-center justify-center text-white font-bold text-xl mr-3" id="user-avatar">
|
| 110 |
+
U
|
| 111 |
+
</div>
|
| 112 |
+
<div>
|
| 113 |
+
<h2 class="font-bold text-lg" id="username-display">Username</h2>
|
| 114 |
+
<p class="text-sm text-gray-500">Online</p>
|
| 115 |
+
</div>
|
| 116 |
+
</div>
|
| 117 |
+
<button id="logout-btn" class="text-gray-500 hover:text-gray-700 transition">
|
| 118 |
+
<i class="fas fa-sign-out-alt text-xl"></i>
|
| 119 |
+
</button>
|
| 120 |
+
</div>
|
| 121 |
+
|
| 122 |
+
<!-- Chat tabs -->
|
| 123 |
+
<div class="flex mb-4 bg-gray-200 rounded-t-lg overflow-hidden">
|
| 124 |
+
<div id="room-tab" class="tab active relative" data-type="room">
|
| 125 |
+
<i class="fas fa-hashtag mr-2"></i>Rooms
|
| 126 |
+
<span id="room-notification" class="tab-badge hidden"></span>
|
| 127 |
+
</div>
|
| 128 |
+
<div id="private-tab" class="tab" data-type="private">
|
| 129 |
+
<i class="fas fa-user-friends mr-2"></i>Private
|
| 130 |
+
<span id="private-notification" class="tab-badge hidden"></span>
|
| 131 |
+
</div>
|
| 132 |
+
</div>
|
| 133 |
+
|
| 134 |
+
<!-- Dual List Layout -->
|
| 135 |
+
<div id="room-section" class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
|
| 136 |
+
<!-- Rooms User is In -->
|
| 137 |
+
<div class="bg-white rounded-xl shadow p-4">
|
| 138 |
+
<div class="flex justify-between items-center mb-3">
|
| 139 |
+
<h3 class="font-semibold text-indigo-600 flex items-center">
|
| 140 |
+
<i class="fas fa-door-open mr-2"></i> Your Rooms
|
| 141 |
+
</h3>
|
| 142 |
+
<span class="bg-indigo-100 text-indigo-800 text-xs px-2 py-1 rounded-full" id="room-count">0</span>
|
| 143 |
+
</div>
|
| 144 |
+
<div id="user-rooms" class="space-y-2 max-h-40 overflow-y-auto custom-scrollbar">
|
| 145 |
+
<p class="text-gray-500 text-sm italic">You haven't joined any rooms yet</p>
|
| 146 |
+
</div>
|
| 147 |
+
</div>
|
| 148 |
+
|
| 149 |
+
<!-- Online Users -->
|
| 150 |
+
<div class="bg-white rounded-xl shadow p-4">
|
| 151 |
+
<div class="flex justify-between items-center mb-3">
|
| 152 |
+
<h3 class="font-semibold text-green-600 flex items-center">
|
| 153 |
+
<i class="fas fa-users mr-2"></i> Online Users
|
| 154 |
+
</h3>
|
| 155 |
+
<span class="bg-green-100 text-green-800 text-xs px-2 py-1 rounded-full" id="user-count">0</span>
|
| 156 |
+
</div>
|
| 157 |
+
<div id="online-users" class="space-y-2 max-h-40 overflow-y-auto custom-scrollbar">
|
| 158 |
+
<p class="text-gray-500 text-sm italic">Loading users...</p>
|
| 159 |
+
</div>
|
| 160 |
+
</div>
|
| 161 |
+
</div>
|
| 162 |
+
|
| 163 |
+
<!-- Private chat section (hidden by default) -->
|
| 164 |
+
<div id="private-section" class="hidden mb-6">
|
| 165 |
+
<div class="bg-white rounded-xl shadow p-4">
|
| 166 |
+
<div class="flex justify-between items-center mb-3">
|
| 167 |
+
<h3 class="font-semibold text-purple-600 flex items-center">
|
| 168 |
+
<i class="fas fa-comments mr-2"></i> Private Conversations
|
| 169 |
+
</h3>
|
| 170 |
+
<span class="bg-purple-100 text-purple-800 text-xs px-2 py-1 rounded-full" id="private-count">0</span>
|
| 171 |
+
</div>
|
| 172 |
+
<div id="private-chats" class="space-y-2 max-h-40 overflow-y-auto custom-scrollbar">
|
| 173 |
+
<p class="text-gray-500 text-sm italic">No private conversations yet</p>
|
| 174 |
+
</div>
|
| 175 |
+
</div>
|
| 176 |
+
</div>
|
| 177 |
+
|
| 178 |
+
<!-- Chat Area -->
|
| 179 |
+
<div class="bg-white rounded-xl shadow-lg overflow-hidden mb-6">
|
| 180 |
+
<!-- Chat header -->
|
| 181 |
+
<div id="chat-header" class="p-4 border-b border-gray-200 bg-gray-50 flex items-center">
|
| 182 |
+
<div id="chat-type-icon" class="text-indigo-600 mr-2">
|
| 183 |
+
<i class="fas fa-hashtag"></i>
|
| 184 |
+
</div>
|
| 185 |
+
<h3 id="chat-title" class="font-semibold">Select a chat</h3>
|
| 186 |
+
</div>
|
| 187 |
+
|
| 188 |
+
<!-- Messages Display -->
|
| 189 |
+
<div id="messages-container" class="p-4 h-64 overflow-y-auto custom-scrollbar bg-gray-50">
|
| 190 |
+
<div class="text-center text-gray-500 py-10">
|
| 191 |
+
<i class="fas fa-comments text-4xl mb-2 text-gray-300"></i>
|
| 192 |
+
<p>No messages yet. Start the conversation!</p>
|
| 193 |
+
</div>
|
| 194 |
+
</div>
|
| 195 |
+
|
| 196 |
+
<!-- Message Input -->
|
| 197 |
+
<div class="p-4 border-t border-gray-200 bg-white">
|
| 198 |
+
<div class="flex space-x-2">
|
| 199 |
+
<input type="text" id="message-input" placeholder="Type your message here..."
|
| 200 |
+
class="flex-1 px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 transition">
|
| 201 |
+
<button id="send-btn" class="bg-indigo-600 text-white px-4 py-2 rounded-lg hover:bg-indigo-700 transition">
|
| 202 |
+
<i class="fas fa-paper-plane"></i>
|
| 203 |
+
</button>
|
| 204 |
+
</div>
|
| 205 |
+
</div>
|
| 206 |
+
</div>
|
| 207 |
+
|
| 208 |
+
<!-- Rooms Section -->
|
| 209 |
+
<div id="room-management-section" class="grid grid-cols-1 md:grid-cols-2 gap-6">
|
| 210 |
+
<!-- Available Rooms -->
|
| 211 |
+
<div class="bg-white rounded-xl shadow p-4">
|
| 212 |
+
<div class="flex justify-between items-center mb-3">
|
| 213 |
+
<h3 class="font-semibold text-blue-600 flex items-center">
|
| 214 |
+
<i class="fas fa-hashtag mr-2"></i> Available Rooms
|
| 215 |
+
</h3>
|
| 216 |
+
<span class="bg-blue-100 text-blue-800 text-xs px-2 py-1 rounded-full" id="available-room-count">0</span>
|
| 217 |
+
</div>
|
| 218 |
+
<div id="available-rooms" class="space-y-2 max-h-40 overflow-y-auto custom-scrollbar">
|
| 219 |
+
<p class="text-gray-500 text-sm italic">Loading rooms...</p>
|
| 220 |
+
</div>
|
| 221 |
+
</div>
|
| 222 |
+
|
| 223 |
+
<!-- Add Room Section -->
|
| 224 |
+
<div class="bg-white rounded-xl shadow p-4">
|
| 225 |
+
<h3 class="font-semibold text-purple-600 flex items-center mb-3">
|
| 226 |
+
<i class="fas fa-plus-circle mr-2"></i> Create New Room
|
| 227 |
+
</h3>
|
| 228 |
+
<div class="flex space-x-2">
|
| 229 |
+
<input type="text" id="new-room-input" placeholder="Enter room name"
|
| 230 |
+
class="flex-1 px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-purple-500 focus:border-purple-500 transition">
|
| 231 |
+
<button id="add-room-btn" class="bg-purple-600 text-white px-4 py-2 rounded-lg hover:bg-purple-700 transition">
|
| 232 |
+
<i class="fas fa-check"></i>
|
| 233 |
+
</button>
|
| 234 |
+
</div>
|
| 235 |
+
</div>
|
| 236 |
+
</div>
|
| 237 |
+
</div>
|
| 238 |
+
</div>
|
| 239 |
+
|
| 240 |
+
<!-- Join Room Modal -->
|
| 241 |
+
<div id="join-room-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
|
| 242 |
+
<div class="bg-white rounded-xl shadow-xl p-6 max-w-sm w-full mx-4 transform transition-all duration-300 scale-95 opacity-0">
|
| 243 |
+
<div class="flex justify-between items-center mb-4">
|
| 244 |
+
<h3 class="font-bold text-lg">Join Room</h3>
|
| 245 |
+
<button id="close-modal-btn" class="text-gray-500 hover:text-gray-700">
|
| 246 |
+
<i class="fas fa-times"></i>
|
| 247 |
+
</button>
|
| 248 |
+
</div>
|
| 249 |
+
<p class="mb-4">Do you want to join <span id="room-name-display" class="font-semibold">General</span>?</p>
|
| 250 |
+
<div class="flex justify-end space-x-3">
|
| 251 |
+
<button id="cancel-join-btn" class="px-4 py-2 border border-gray-300 rounded-lg hover:bg-gray-100 transition">
|
| 252 |
+
Cancel
|
| 253 |
+
</button>
|
| 254 |
+
<button id="confirm-join-btn" class="px-4 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition">
|
| 255 |
+
Join
|
| 256 |
+
</button>
|
| 257 |
+
</div>
|
| 258 |
+
</div>
|
| 259 |
+
</div>
|
| 260 |
+
|
| 261 |
+
<script>
|
| 262 |
+
// DOM Elements
|
| 263 |
+
const loginSection = document.getElementById('login-section');
|
| 264 |
+
const chatInterface = document.getElementById('chat-interface');
|
| 265 |
+
const loginBtn = document.getElementById('login-btn');
|
| 266 |
+
const logoutBtn = document.getElementById('logout-btn');
|
| 267 |
+
const usernameInput = document.getElementById('username');
|
| 268 |
+
const usernameDisplay = document.getElementById('username-display');
|
| 269 |
+
const userAvatar = document.getElementById('user-avatar');
|
| 270 |
+
const messageInput = document.getElementById('message-input');
|
| 271 |
+
const sendBtn = document.getElementById('send-btn');
|
| 272 |
+
const messagesContainer = document.getElementById('messages-container');
|
| 273 |
+
const userRooms = document.getElementById('user-rooms');
|
| 274 |
+
const onlineUsers = document.getElementById('online-users');
|
| 275 |
+
const availableRooms = document.getElementById('available-rooms');
|
| 276 |
+
const newRoomInput = document.getElementById('new-room-input');
|
| 277 |
+
const addRoomBtn = document.getElementById('add-room-btn');
|
| 278 |
+
const joinRoomModal = document.getElementById('join-room-modal');
|
| 279 |
+
const closeModalBtn = document.getElementById('close-modal-btn');
|
| 280 |
+
const cancelJoinBtn = document.getElementById('cancel-join-btn');
|
| 281 |
+
const confirmJoinBtn = document.getElementById('confirm-join-btn');
|
| 282 |
+
const roomNameDisplay = document.getElementById('room-name-display');
|
| 283 |
+
const roomCount = document.getElementById('room-count');
|
| 284 |
+
const userCount = document.getElementById('user-count');
|
| 285 |
+
const availableRoomCount = document.getElementById('available-room-count');
|
| 286 |
+
const roomTab = document.getElementById('room-tab');
|
| 287 |
+
const privateTab = document.getElementById('private-tab');
|
| 288 |
+
const roomSection = document.getElementById('room-section');
|
| 289 |
+
const privateSection = document.getElementById('private-section');
|
| 290 |
+
const privateChats = document.getElementById('private-chats');
|
| 291 |
+
const chatHeader = document.getElementById('chat-header');
|
| 292 |
+
const chatTitle = document.getElementById('chat-title');
|
| 293 |
+
const chatTypeIcon = document.getElementById('chat-type-icon');
|
| 294 |
+
const roomManagementSection = document.getElementById('room-management-section');
|
| 295 |
+
const roomNotification = document.getElementById('room-notification');
|
| 296 |
+
const privateNotification = document.getElementById('private-notification');
|
| 297 |
+
const privateCount = document.getElementById('private-count');
|
| 298 |
+
|
| 299 |
+
// State
|
| 300 |
+
let currentUser = '';
|
| 301 |
+
let currentRooms = [];
|
| 302 |
+
let allUsers = [];
|
| 303 |
+
let allRooms = ['General', 'Random', 'Help'];
|
| 304 |
+
let selectedChat = null;
|
| 305 |
+
let chatType = 'room'; // 'room' or 'private'
|
| 306 |
+
let messages = {};
|
| 307 |
+
let privateMessages = {};
|
| 308 |
+
let unreadCounts = { rooms: {}, private: {} };
|
| 309 |
+
|
| 310 |
+
// Initialize with some sample data
|
| 311 |
+
function initializeSampleData() {
|
| 312 |
+
// Sample users
|
| 313 |
+
allUsers = ['Alice', 'Bob', 'Charlie', 'Diana', 'Eve'];
|
| 314 |
+
|
| 315 |
+
// Sample messages for rooms
|
| 316 |
+
messages = {
|
| 317 |
+
'General': [
|
| 318 |
+
{ user: 'Alice', text: 'Hello everyone!', time: '10:30 AM' },
|
| 319 |
+
{ user: 'Bob', text: 'Hi Alice! How are you?', time: '10:32 AM' }
|
| 320 |
+
],
|
| 321 |
+
'Random': [
|
| 322 |
+
{ user: 'Charlie', text: 'Did you see that movie?', time: '9:15 AM' },
|
| 323 |
+
{ user: 'Diana', text: 'Yes, it was amazing!', time: '9:20 AM' }
|
| 324 |
+
],
|
| 325 |
+
'Help': [
|
| 326 |
+
{ user: 'Eve', text: 'Can someone help me with this?', time: '11:05 AM' }
|
| 327 |
+
]
|
| 328 |
+
};
|
| 329 |
+
|
| 330 |
+
// Initialize private messages
|
| 331 |
+
privateMessages = {};
|
| 332 |
+
allUsers.forEach(user => {
|
| 333 |
+
if (user !== currentUser) {
|
| 334 |
+
privateMessages[user] = [];
|
| 335 |
+
}
|
| 336 |
+
});
|
| 337 |
+
|
| 338 |
+
// Initialize unread counts
|
| 339 |
+
unreadCounts = {
|
| 340 |
+
rooms: {},
|
| 341 |
+
private: {}
|
| 342 |
+
};
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
// Login function
|
| 346 |
+
function login() {
|
| 347 |
+
const username = usernameInput.value.trim();
|
| 348 |
+
if (username) {
|
| 349 |
+
currentUser = username;
|
| 350 |
+
usernameDisplay.textContent = username;
|
| 351 |
+
userAvatar.textContent = username.charAt(0).toUpperCase();
|
| 352 |
+
|
| 353 |
+
// Generate a random color for the avatar
|
| 354 |
+
const colors = ['bg-indigo-500', 'bg-blue-500', 'bg-green-500', 'bg-purple-500', 'bg-pink-500', 'bg-red-500', 'bg-yellow-500'];
|
| 355 |
+
const randomColor = colors[Math.floor(Math.random() * colors.length)];
|
| 356 |
+
userAvatar.className = `w-10 h-10 rounded-full ${randomColor} flex items-center justify-center text-white font-bold text-xl mr-3`;
|
| 357 |
+
|
| 358 |
+
// Show chat interface and hide login
|
| 359 |
+
loginSection.classList.add('hidden');
|
| 360 |
+
chatInterface.classList.remove('hidden');
|
| 361 |
+
|
| 362 |
+
// Initialize data and UI
|
| 363 |
+
initializeSampleData();
|
| 364 |
+
updateUI();
|
| 365 |
+
|
| 366 |
+
// Add user to online users if not already there
|
| 367 |
+
if (!allUsers.includes(username)) {
|
| 368 |
+
allUsers.push(username);
|
| 369 |
+
}
|
| 370 |
+
|
| 371 |
+
// Focus on message input
|
| 372 |
+
messageInput.focus();
|
| 373 |
+
} else {
|
| 374 |
+
alert('Please enter a username');
|
| 375 |
+
}
|
| 376 |
+
}
|
| 377 |
+
|
| 378 |
+
// Logout function
|
| 379 |
+
function logout() {
|
| 380 |
+
currentUser = '';
|
| 381 |
+
chatInterface.classList.add('hidden');
|
| 382 |
+
loginSection.classList.remove('hidden');
|
| 383 |
+
usernameInput.value = '';
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
// Switch between room and private chat tabs
|
| 387 |
+
function switchTab(type) {
|
| 388 |
+
if (type === chatType) return;
|
| 389 |
+
|
| 390 |
+
chatType = type;
|
| 391 |
+
|
| 392 |
+
// Update tab styling
|
| 393 |
+
if (type === 'room') {
|
| 394 |
+
roomTab.classList.add('active');
|
| 395 |
+
privateTab.classList.remove('active');
|
| 396 |
+
roomSection.classList.remove('hidden');
|
| 397 |
+
privateSection.classList.add('hidden');
|
| 398 |
+
roomManagementSection.classList.remove('hidden');
|
| 399 |
+
} else {
|
| 400 |
+
roomTab.classList.remove('active');
|
| 401 |
+
privateTab.classList.add('active');
|
| 402 |
+
roomSection.classList.add('hidden');
|
| 403 |
+
privateSection.classList.remove('hidden');
|
| 404 |
+
roomManagementSection.classList.add('hidden');
|
| 405 |
+
}
|
| 406 |
+
|
| 407 |
+
// Clear selected chat when switching tabs
|
| 408 |
+
selectedChat = null;
|
| 409 |
+
updateMessages();
|
| 410 |
+
updateChatHeader();
|
| 411 |
+
}
|
| 412 |
+
|
| 413 |
+
// Update all UI elements
|
| 414 |
+
function updateUI() {
|
| 415 |
+
updateUserRooms();
|
| 416 |
+
updateOnlineUsers();
|
| 417 |
+
updateAvailableRooms();
|
| 418 |
+
updatePrivateChats();
|
| 419 |
+
updateMessages();
|
| 420 |
+
updateChatHeader();
|
| 421 |
+
updateNotifications();
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
// Update the user's rooms list
|
| 425 |
+
function updateUserRooms() {
|
| 426 |
+
userRooms.innerHTML = '';
|
| 427 |
+
|
| 428 |
+
if (currentRooms.length === 0) {
|
| 429 |
+
userRooms.innerHTML = '<p class="text-gray-500 text-sm italic">You haven\'t joined any rooms yet</p>';
|
| 430 |
+
roomCount.textContent = '0';
|
| 431 |
+
return;
|
| 432 |
+
}
|
| 433 |
+
|
| 434 |
+
roomCount.textContent = currentRooms.length;
|
| 435 |
+
|
| 436 |
+
currentRooms.forEach(room => {
|
| 437 |
+
const roomElement = document.createElement('div');
|
| 438 |
+
roomElement.className = 'flex items-center justify-between p-2 hover:bg-gray-100 rounded-lg cursor-pointer transition';
|
| 439 |
+
roomElement.innerHTML = `
|
| 440 |
+
<div class="flex items-center">
|
| 441 |
+
<i class="fas fa-hashtag text-gray-400 mr-2"></i>
|
| 442 |
+
<span>${room}</span>
|
| 443 |
+
</div>
|
| 444 |
+
<span class="text-xs text-gray-500">${messages[room] ? messages[room].length : 0} messages</span>
|
| 445 |
+
`;
|
| 446 |
+
|
| 447 |
+
roomElement.addEventListener('click', () => {
|
| 448 |
+
chatType = 'room';
|
| 449 |
+
selectedChat = room;
|
| 450 |
+
switchTab('room');
|
| 451 |
+
updateMessages();
|
| 452 |
+
|
| 453 |
+
// Mark as read
|
| 454 |
+
if (unreadCounts.rooms[room]) {
|
| 455 |
+
unreadCounts.rooms[room] = 0;
|
| 456 |
+
updateNotifications();
|
| 457 |
+
}
|
| 458 |
+
});
|
| 459 |
+
|
| 460 |
+
userRooms.appendChild(roomElement);
|
| 461 |
+
});
|
| 462 |
+
}
|
| 463 |
+
|
| 464 |
+
// Update online users list
|
| 465 |
+
function updateOnlineUsers() {
|
| 466 |
+
onlineUsers.innerHTML = '';
|
| 467 |
+
userCount.textContent = allUsers.length;
|
| 468 |
+
|
| 469 |
+
if (allUsers.length === 0) {
|
| 470 |
+
onlineUsers.innerHTML = '<p class="text-gray-500 text-sm italic">No users online</p>';
|
| 471 |
+
return;
|
| 472 |
+
}
|
| 473 |
+
|
| 474 |
+
allUsers.forEach(user => {
|
| 475 |
+
if (user === currentUser) return;
|
| 476 |
+
|
| 477 |
+
const userElement = document.createElement('div');
|
| 478 |
+
userElement.className = 'flex items-center justify-between p-2 hover:bg-gray-100 rounded-lg cursor-pointer transition';
|
| 479 |
+
|
| 480 |
+
userElement.innerHTML = `
|
| 481 |
+
<div class="flex items-center">
|
| 482 |
+
<div class="w-6 h-6 rounded-full bg-green-500 flex items-center justify-center text-white text-xs mr-2">
|
| 483 |
+
${user.charAt(0).toUpperCase()}
|
| 484 |
+
</div>
|
| 485 |
+
<span>${user}</span>
|
| 486 |
+
</div>
|
| 487 |
+
<span class="text-xs text-gray-500">Online</span>
|
| 488 |
+
`;
|
| 489 |
+
|
| 490 |
+
userElement.addEventListener('click', () => {
|
| 491 |
+
// Start private chat with this user
|
| 492 |
+
chatType = 'private';
|
| 493 |
+
selectedChat = user;
|
| 494 |
+
switchTab('private');
|
| 495 |
+
updateMessages();
|
| 496 |
+
|
| 497 |
+
// Mark as read
|
| 498 |
+
if (unreadCounts.private[user]) {
|
| 499 |
+
unreadCounts.private[user] = 0;
|
| 500 |
+
updateNotifications();
|
| 501 |
+
}
|
| 502 |
+
});
|
| 503 |
+
|
| 504 |
+
onlineUsers.appendChild(userElement);
|
| 505 |
+
});
|
| 506 |
+
}
|
| 507 |
+
|
| 508 |
+
// Update available rooms list
|
| 509 |
+
function updateAvailableRooms() {
|
| 510 |
+
availableRooms.innerHTML = '';
|
| 511 |
+
availableRoomCount.textContent = allRooms.length;
|
| 512 |
+
|
| 513 |
+
if (allRooms.length === 0) {
|
| 514 |
+
availableRooms.innerHTML = '<p class="text-gray-500 text-sm italic">No rooms available</p>';
|
| 515 |
+
return;
|
| 516 |
+
}
|
| 517 |
+
|
| 518 |
+
allRooms.forEach(room => {
|
| 519 |
+
// Skip rooms the user is already in
|
| 520 |
+
if (currentRooms.includes(room)) return;
|
| 521 |
+
|
| 522 |
+
const roomElement = document.createElement('div');
|
| 523 |
+
roomElement.className = 'flex items-center justify-between p-2 hover:bg-gray-100 rounded-lg cursor-pointer transition';
|
| 524 |
+
roomElement.innerHTML = `
|
| 525 |
+
<div class="flex items-center">
|
| 526 |
+
<i class="fas fa-hashtag text-gray-400 mr-2"></i>
|
| 527 |
+
<span>${room}</span>
|
| 528 |
+
</div>
|
| 529 |
+
<span class="text-xs text-gray-500">${messages[room] ? messages[room].length : 0} messages</span>
|
| 530 |
+
`;
|
| 531 |
+
|
| 532 |
+
roomElement.addEventListener('click', () => {
|
| 533 |
+
showJoinRoomModal(room);
|
| 534 |
+
});
|
| 535 |
+
|
| 536 |
+
availableRooms.appendChild(roomElement);
|
| 537 |
+
});
|
| 538 |
+
}
|
| 539 |
+
|
| 540 |
+
// Update private chats list
|
| 541 |
+
function updatePrivateChats() {
|
| 542 |
+
privateChats.innerHTML = '';
|
| 543 |
+
const privateChatUsers = Object.keys(privateMessages).filter(user =>
|
| 544 |
+
user !== currentUser && (privateMessages[user].length > 0 || allUsers.includes(user))
|
| 545 |
+
);
|
| 546 |
+
|
| 547 |
+
privateCount.textContent = privateChatUsers.length;
|
| 548 |
+
|
| 549 |
+
if (privateChatUsers.length === 0) {
|
| 550 |
+
privateChats.innerHTML = '<p class="text-gray-500 text-sm italic">No private conversations yet</p>';
|
| 551 |
+
return;
|
| 552 |
+
}
|
| 553 |
+
|
| 554 |
+
privateChatUsers.forEach(user => {
|
| 555 |
+
const chatElement = document.createElement('div');
|
| 556 |
+
chatElement.className = 'flex items-center justify-between p-2 hover:bg-gray-100 rounded-lg cursor-pointer transition';
|
| 557 |
+
|
| 558 |
+
const lastMessage = privateMessages[user].length > 0
|
| 559 |
+
? privateMessages[user][privateMessages[user].length - 1].text
|
| 560 |
+
: 'No messages yet';
|
| 561 |
+
|
| 562 |
+
chatElement.innerHTML = `
|
| 563 |
+
<div class="flex items-center">
|
| 564 |
+
<div class="w-6 h-6 rounded-full bg-purple-500 flex items-center justify-center text-white text-xs mr-2">
|
| 565 |
+
${user.charAt(0).toUpperCase()}
|
| 566 |
+
</div>
|
| 567 |
+
<div>
|
| 568 |
+
<div class="font-medium">${user}</div>
|
| 569 |
+
<div class="text-xs text-gray-500 truncate max-w-xs">${lastMessage}</div>
|
| 570 |
+
</div>
|
| 571 |
+
</div>
|
| 572 |
+
${unreadCounts.private[user] > 0 ?
|
| 573 |
+
`<span class="bg-red-500 text-white text-xs px-1.5 py-0.5 rounded-full">${unreadCounts.private[user]}</span>` :
|
| 574 |
+
''}
|
| 575 |
+
`;
|
| 576 |
+
|
| 577 |
+
chatElement.addEventListener('click', () => {
|
| 578 |
+
chatType = 'private';
|
| 579 |
+
selectedChat = user;
|
| 580 |
+
switchTab('private');
|
| 581 |
+
updateMessages();
|
| 582 |
+
|
| 583 |
+
// Mark as read
|
| 584 |
+
if (unreadCounts.private[user]) {
|
| 585 |
+
unreadCounts.private[user] = 0;
|
| 586 |
+
updateNotifications();
|
| 587 |
+
}
|
| 588 |
+
});
|
| 589 |
+
|
| 590 |
+
privateChats.appendChild(chatElement);
|
| 591 |
+
});
|
| 592 |
+
}
|
| 593 |
+
|
| 594 |
+
// Update messages display
|
| 595 |
+
function updateMessages() {
|
| 596 |
+
messagesContainer.innerHTML = '';
|
| 597 |
+
|
| 598 |
+
if (!selectedChat) {
|
| 599 |
+
messagesContainer.innerHTML = `
|
| 600 |
+
<div class="text-center text-gray-500 py-10">
|
| 601 |
+
<i class="fas fa-comments text-4xl mb-2 text-gray-300"></i>
|
| 602 |
+
<p>Select a chat to start messaging</p>
|
| 603 |
+
</div>
|
| 604 |
+
`;
|
| 605 |
+
return;
|
| 606 |
+
}
|
| 607 |
+
|
| 608 |
+
let messageList = [];
|
| 609 |
+
if (chatType === 'room') {
|
| 610 |
+
messageList = messages[selectedChat] || [];
|
| 611 |
+
} else {
|
| 612 |
+
messageList = privateMessages[selectedChat] || [];
|
| 613 |
+
}
|
| 614 |
+
|
| 615 |
+
if (messageList.length === 0) {
|
| 616 |
+
messagesContainer.innerHTML = `
|
| 617 |
+
<div class="text-center text-gray-500 py-10">
|
| 618 |
+
<i class="fas fa-comments text-4xl mb-2 text-gray-300"></i>
|
| 619 |
+
<p>No messages in this chat yet</p>
|
| 620 |
+
</div>
|
| 621 |
+
`;
|
| 622 |
+
return;
|
| 623 |
+
}
|
| 624 |
+
|
| 625 |
+
messageList.forEach((msg, index) => {
|
| 626 |
+
const isCurrentUser = msg.user === currentUser;
|
| 627 |
+
const messageElement = document.createElement('div');
|
| 628 |
+
messageElement.className = `mb-4 message-animation ${isCurrentUser ? 'pl-8' : 'pr-8'}`;
|
| 629 |
+
|
| 630 |
+
messageElement.innerHTML = `
|
| 631 |
+
<div class="flex ${isCurrentUser ? 'justify-end' : ''}">
|
| 632 |
+
<div class="max-w-xs md:max-w-md lg:max-w-lg ${isCurrentUser ? 'bg-indigo-100' : 'bg-white'} p-3 rounded-lg shadow-sm border border-gray-200">
|
| 633 |
+
${!isCurrentUser ? `<div class="font-medium text-sm mb-1">${msg.user}</div>` : ''}
|
| 634 |
+
<div class="text-gray-800">${msg.text}</div>
|
| 635 |
+
<div class="text-xs text-gray-500 mt-1 text-right">${msg.time}</div>
|
| 636 |
+
</div>
|
| 637 |
+
</div>
|
| 638 |
+
`;
|
| 639 |
+
|
| 640 |
+
messagesContainer.appendChild(messageElement);
|
| 641 |
+
});
|
| 642 |
+
|
| 643 |
+
// Scroll to bottom
|
| 644 |
+
messagesContainer.scrollTop = messagesContainer.scrollHeight;
|
| 645 |
+
}
|
| 646 |
+
|
| 647 |
+
// Update chat header
|
| 648 |
+
function updateChatHeader() {
|
| 649 |
+
if (!selectedChat) {
|
| 650 |
+
chatTitle.textContent = 'Select a chat';
|
| 651 |
+
chatTypeIcon.innerHTML = '<i class="fas fa-comments"></i>';
|
| 652 |
+
return;
|
| 653 |
+
}
|
| 654 |
+
|
| 655 |
+
if (chatType === 'room') {
|
| 656 |
+
chatTitle.textContent = selectedChat;
|
| 657 |
+
chatTypeIcon.innerHTML = '<i class="fas fa-hashtag"></i>';
|
| 658 |
+
} else {
|
| 659 |
+
chatTitle.textContent = selectedChat;
|
| 660 |
+
chatTypeIcon.innerHTML = '<i class="fas fa-user-friends"></i>';
|
| 661 |
+
}
|
| 662 |
+
}
|
| 663 |
+
|
| 664 |
+
// Update notification badges
|
| 665 |
+
function updateNotifications() {
|
| 666 |
+
// Room notifications
|
| 667 |
+
let totalRoomUnread = 0;
|
| 668 |
+
Object.keys(unreadCounts.rooms).forEach(room => {
|
| 669 |
+
totalRoomUnread += unreadCounts.rooms[room];
|
| 670 |
+
});
|
| 671 |
+
|
| 672 |
+
if (totalRoomUnread > 0) {
|
| 673 |
+
roomNotification.textContent = totalRoomUnread;
|
| 674 |
+
roomNotification.classList.remove('hidden');
|
| 675 |
+
} else {
|
| 676 |
+
roomNotification.classList.add('hidden');
|
| 677 |
+
}
|
| 678 |
+
|
| 679 |
+
// Private notifications
|
| 680 |
+
let totalPrivateUnread = 0;
|
| 681 |
+
Object.keys(unreadCounts.private).forEach(user => {
|
| 682 |
+
totalPrivateUnread += unreadCounts.private[user];
|
| 683 |
+
});
|
| 684 |
+
|
| 685 |
+
if (totalPrivateUnread > 0) {
|
| 686 |
+
privateNotification.textContent = totalPrivateUnread;
|
| 687 |
+
privateNotification.classList.remove('hidden');
|
| 688 |
+
} else {
|
| 689 |
+
privateNotification.classList.add('hidden');
|
| 690 |
+
}
|
| 691 |
+
}
|
| 692 |
+
|
| 693 |
+
// Send message
|
| 694 |
+
function sendMessage() {
|
| 695 |
+
const messageText = messageInput.value.trim();
|
| 696 |
+
if (!messageText || !selectedChat) return;
|
| 697 |
+
|
| 698 |
+
// Create new message
|
| 699 |
+
const now = new Date();
|
| 700 |
+
const timeString = now.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
| 701 |
+
|
| 702 |
+
const newMessage = {
|
| 703 |
+
user: currentUser,
|
| 704 |
+
text: messageText,
|
| 705 |
+
time: timeString
|
| 706 |
+
};
|
| 707 |
+
|
| 708 |
+
// Add to messages
|
| 709 |
+
if (chatType === 'room') {
|
| 710 |
+
if (!messages[selectedChat]) {
|
| 711 |
+
messages[selectedChat] = [];
|
| 712 |
+
}
|
| 713 |
+
messages[selectedChat].push(newMessage);
|
| 714 |
+
|
| 715 |
+
// Update unread count for other users in the room
|
| 716 |
+
// (In a real app, this would be handled by the server)
|
| 717 |
+
} else {
|
| 718 |
+
if (!privateMessages[selectedChat]) {
|
| 719 |
+
privateMessages[selectedChat] = [];
|
| 720 |
+
}
|
| 721 |
+
privateMessages[selectedChat].push(newMessage);
|
| 722 |
+
|
| 723 |
+
// Update unread count for the recipient
|
| 724 |
+
if (chatType !== 'private' || selectedChat !== currentUser) {
|
| 725 |
+
if (!unreadCounts.private[selectedChat]) {
|
| 726 |
+
unreadCounts.private[selectedChat] = 0;
|
| 727 |
+
}
|
| 728 |
+
unreadCounts.private[selectedChat]++;
|
| 729 |
+
updateNotifications();
|
| 730 |
+
}
|
| 731 |
+
}
|
| 732 |
+
|
| 733 |
+
// Clear input
|
| 734 |
+
messageInput.value = '';
|
| 735 |
+
|
| 736 |
+
// Update UI
|
| 737 |
+
updateMessages();
|
| 738 |
+
if (chatType === 'private') {
|
| 739 |
+
updatePrivateChats();
|
| 740 |
+
}
|
| 741 |
+
}
|
| 742 |
+
|
| 743 |
+
// Show join room modal
|
| 744 |
+
function showJoinRoomModal(roomName) {
|
| 745 |
+
roomNameDisplay.textContent = roomName;
|
| 746 |
+
selectedChat = roomName;
|
| 747 |
+
chatType = 'room';
|
| 748 |
+
|
| 749 |
+
// Show modal with animation
|
| 750 |
+
joinRoomModal.classList.remove('hidden');
|
| 751 |
+
setTimeout(() => {
|
| 752 |
+
const modalContent = joinRoomModal.querySelector('div > div');
|
| 753 |
+
modalContent.classList.remove('scale-95', 'opacity-0');
|
| 754 |
+
modalContent.classList.add('scale-100', 'opacity-100');
|
| 755 |
+
}, 10);
|
| 756 |
+
}
|
| 757 |
+
|
| 758 |
+
// Hide join room modal
|
| 759 |
+
function hideJoinRoomModal() {
|
| 760 |
+
const modalContent = joinRoomModal.querySelector('div > div');
|
| 761 |
+
modalContent.classList.remove('scale-100', 'opacity-100');
|
| 762 |
+
modalContent.classList.add('scale-95', 'opacity-0');
|
| 763 |
+
|
| 764 |
+
setTimeout(() => {
|
| 765 |
+
joinRoomModal.classList.add('hidden');
|
| 766 |
+
}, 300);
|
| 767 |
+
}
|
| 768 |
+
|
| 769 |
+
// Join room
|
| 770 |
+
function joinRoom() {
|
| 771 |
+
if (!selectedChat || currentRooms.includes(selectedChat)) {
|
| 772 |
+
hideJoinRoomModal();
|
| 773 |
+
return;
|
| 774 |
+
}
|
| 775 |
+
|
| 776 |
+
currentRooms.push(selectedChat);
|
| 777 |
+
updateUI();
|
| 778 |
+
hideJoinRoomModal();
|
| 779 |
+
}
|
| 780 |
+
|
| 781 |
+
// Add new room
|
| 782 |
+
function addRoom() {
|
| 783 |
+
const roomName = newRoomInput.value.trim();
|
| 784 |
+
if (!roomName) return;
|
| 785 |
+
|
| 786 |
+
// Check if room already exists
|
| 787 |
+
if (allRooms.includes(roomName)) {
|
| 788 |
+
alert('Room already exists!');
|
| 789 |
+
return;
|
| 790 |
+
}
|
| 791 |
+
|
| 792 |
+
// Add new room
|
| 793 |
+
allRooms.push(roomName);
|
| 794 |
+
newRoomInput.value = '';
|
| 795 |
+
|
| 796 |
+
// Update UI
|
| 797 |
+
updateAvailableRooms();
|
| 798 |
+
|
| 799 |
+
// Show join modal for the new room
|
| 800 |
+
showJoinRoomModal(roomName);
|
| 801 |
+
}
|
| 802 |
+
|
| 803 |
+
// Event Listeners
|
| 804 |
+
loginBtn.addEventListener('click', login);
|
| 805 |
+
logoutBtn.addEventListener('click', logout);
|
| 806 |
+
|
| 807 |
+
// Allow login with Enter key
|
| 808 |
+
usernameInput.addEventListener('keypress', (e) => {
|
| 809 |
+
if (e.key === 'Enter') login();
|
| 810 |
+
});
|
| 811 |
+
|
| 812 |
+
sendBtn.addEventListener('click', sendMessage);
|
| 813 |
+
|
| 814 |
+
// Allow sending with Enter key
|
| 815 |
+
messageInput.addEventListener('keypress', (e) => {
|
| 816 |
+
if (e.key === 'Enter') sendMessage();
|
| 817 |
+
});
|
| 818 |
+
|
| 819 |
+
addRoomBtn.addEventListener('click', addRoom);
|
| 820 |
+
|
| 821 |
+
// Allow adding room with Enter key
|
| 822 |
+
newRoomInput.addEventListener('keypress', (e) => {
|
| 823 |
+
if (e.key === 'Enter') addRoom();
|
| 824 |
+
});
|
| 825 |
+
|
| 826 |
+
closeModalBtn.addEventListener('click', hideJoinRoomModal);
|
| 827 |
+
cancelJoinBtn.addEventListener('click', hideJoinRoomModal);
|
| 828 |
+
confirmJoinBtn.addEventListener('click', joinRoom);
|
| 829 |
+
|
| 830 |
+
// Close modal when clicking outside
|
| 831 |
+
joinRoomModal.addEventListener('click', (e) => {
|
| 832 |
+
if (e.target === joinRoomModal) {
|
| 833 |
+
hideJoinRoomModal();
|
| 834 |
+
}
|
| 835 |
+
});
|
| 836 |
+
|
| 837 |
+
// Tab switching
|
| 838 |
+
roomTab.addEventListener('click', () => switchTab('room'));
|
| 839 |
+
privateTab.addEventListener('click', () => switchTab('private'));
|
| 840 |
+
</script>
|
| 841 |
+
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=swordmeister-zoro/modern-chat-interface" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
|
| 842 |
+
</html>
|
prompts.txt
ADDED
|
File without changes
|