Dmitriy commited on
Add the option to send an image in the following formats: .gif, .jpeg, .jpg, .webp. + sending files in the following formats: .zip, .txt, well, all files - Initial Deployment
Browse files- README.md +7 -5
- index.html +474 -19
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: test
|
| 3 |
+
emoji: 🐳
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: pink
|
| 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,474 @@
|
|
| 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>Neon Chat</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 |
+
@keyframes fadeIn {
|
| 11 |
+
from { opacity: 0; transform: translateY(10px); }
|
| 12 |
+
to { opacity: 1; transform: translateY(0); }
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
@keyframes pulse {
|
| 16 |
+
0%, 100% { opacity: 1; }
|
| 17 |
+
50% { opacity: 0.5; }
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
.message-animation {
|
| 21 |
+
animation: fadeIn 0.3s ease-out forwards;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
.typing-animation {
|
| 25 |
+
animation: pulse 1.5s infinite;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
.chat-container {
|
| 29 |
+
height: calc(100vh - 120px);
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
@media (max-width: 640px) {
|
| 33 |
+
.chat-container {
|
| 34 |
+
height: calc(100vh - 100px);
|
| 35 |
+
}
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
/* Custom scrollbar */
|
| 39 |
+
.messages-container::-webkit-scrollbar {
|
| 40 |
+
width: 6px;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.messages-container::-webkit-scrollbar-track {
|
| 44 |
+
background: rgba(255, 255, 255, 0.1);
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
.messages-container::-webkit-scrollbar-thumb {
|
| 48 |
+
background: #4f46e5;
|
| 49 |
+
border-radius: 3px;
|
| 50 |
+
}
|
| 51 |
+
</style>
|
| 52 |
+
</head>
|
| 53 |
+
<body class="bg-gray-900 text-white">
|
| 54 |
+
<div class="container mx-auto max-w-6xl p-4">
|
| 55 |
+
<!-- Header -->
|
| 56 |
+
<header class="flex justify-between items-center mb-6 border-b border-indigo-900 pb-4">
|
| 57 |
+
<div class="flex items-center space-x-3">
|
| 58 |
+
<div class="w-10 h-10 rounded-full bg-gradient-to-br from-indigo-500 to-purple-600 flex items-center justify-center">
|
| 59 |
+
<i class="fas fa-comment-dots text-white"></i>
|
| 60 |
+
</div>
|
| 61 |
+
<h1 class="text-2xl font-bold bg-gradient-to-r from-indigo-400 to-purple-500 bg-clip-text text-transparent">Neon Chat</h1>
|
| 62 |
+
</div>
|
| 63 |
+
<div class="flex items-center space-x-4">
|
| 64 |
+
<button id="themeToggle" class="p-2 rounded-full hover:bg-gray-800 transition">
|
| 65 |
+
<i class="fas fa-moon text-indigo-300"></i>
|
| 66 |
+
</button>
|
| 67 |
+
<div class="relative">
|
| 68 |
+
<button id="userMenu" class="flex items-center space-x-2 focus:outline-none">
|
| 69 |
+
<div class="w-8 h-8 rounded-full bg-gradient-to-br from-indigo-400 to-purple-500 flex items-center justify-center">
|
| 70 |
+
<span class="text-xs font-bold">ME</span>
|
| 71 |
+
</div>
|
| 72 |
+
</button>
|
| 73 |
+
</div>
|
| 74 |
+
</div>
|
| 75 |
+
</header>
|
| 76 |
+
|
| 77 |
+
<!-- Chat Area -->
|
| 78 |
+
<div class="flex flex-col h-full">
|
| 79 |
+
<!-- Online Users (for future implementation) -->
|
| 80 |
+
<div class="hidden md:flex items-center space-x-4 mb-4 overflow-x-auto pb-2">
|
| 81 |
+
<div class="flex-shrink-0">
|
| 82 |
+
<div class="relative">
|
| 83 |
+
<div class="w-10 h-10 rounded-full bg-gradient-to-br from-green-400 to-blue-500 flex items-center justify-center">
|
| 84 |
+
<span class="text-xs font-bold">JD</span>
|
| 85 |
+
</div>
|
| 86 |
+
<div class="absolute bottom-0 right-0 w-3 h-3 bg-green-400 rounded-full border-2 border-gray-900"></div>
|
| 87 |
+
</div>
|
| 88 |
+
</div>
|
| 89 |
+
<div class="flex-shrink-0">
|
| 90 |
+
<div class="relative">
|
| 91 |
+
<div class="w-10 h-10 rounded-full bg-gradient-to-br from-pink-500 to-red-500 flex items-center justify-center">
|
| 92 |
+
<span class="text-xs font-bold">AM</span>
|
| 93 |
+
</div>
|
| 94 |
+
<div class="absolute bottom-0 right-0 w-3 h-3 bg-green-400 rounded-full border-2 border-gray-900"></div>
|
| 95 |
+
</div>
|
| 96 |
+
</div>
|
| 97 |
+
<div class="flex-shrink-0">
|
| 98 |
+
<div class="relative">
|
| 99 |
+
<div class="w-10 h-10 rounded-full bg-gradient-to-br from-yellow-400 to-orange-500 flex items-center justify-center">
|
| 100 |
+
<span class="text-xs font-bold">TS</span>
|
| 101 |
+
</div>
|
| 102 |
+
<div class="absolute bottom-0 right-0 w-3 h-3 bg-gray-400 rounded-full border-2 border-gray-900"></div>
|
| 103 |
+
</div>
|
| 104 |
+
</div>
|
| 105 |
+
<div class="flex-shrink-0">
|
| 106 |
+
<div class="relative">
|
| 107 |
+
<div class="w-10 h-10 rounded-full bg-gradient-to-br from-blue-400 to-cyan-500 flex items-center justify-center">
|
| 108 |
+
<span class="text-xs font-bold">KT</span>
|
| 109 |
+
</div>
|
| 110 |
+
<div class="absolute bottom-0 right-0 w-3 h-3 bg-green-400 rounded-full border-2 border-gray-900"></div>
|
| 111 |
+
</div>
|
| 112 |
+
</div>
|
| 113 |
+
</div>
|
| 114 |
+
|
| 115 |
+
<!-- Messages Container -->
|
| 116 |
+
<div class="chat-container flex flex-col">
|
| 117 |
+
<div class="messages-container flex-1 overflow-y-auto p-4 space-y-4">
|
| 118 |
+
<!-- Messages will be inserted here by JavaScript -->
|
| 119 |
+
</div>
|
| 120 |
+
|
| 121 |
+
<!-- Typing Indicator -->
|
| 122 |
+
<div id="typingIndicator" class="hidden items-center space-x-2 px-4 py-2 bg-gray-800 rounded-lg mb-2 mx-4">
|
| 123 |
+
<div class="w-8 h-8 rounded-full bg-gray-700 flex items-center justify-center">
|
| 124 |
+
<i class="fas fa-user text-gray-400"></i>
|
| 125 |
+
</div>
|
| 126 |
+
<div class="flex space-x-1">
|
| 127 |
+
<div class="w-2 h-2 bg-indigo-400 rounded-full typing-animation" style="animation-delay: 0s"></div>
|
| 128 |
+
<div class="w-2 h-2 bg-indigo-400 rounded-full typing-animation" style="animation-delay: 0.2s"></div>
|
| 129 |
+
<div class="w-2 h-2 bg-indigo-400 rounded-full typing-animation" style="animation-delay: 0.4s"></div>
|
| 130 |
+
</div>
|
| 131 |
+
<span class="text-gray-400 text-sm">is typing...</span>
|
| 132 |
+
</div>
|
| 133 |
+
|
| 134 |
+
<!-- Message Input -->
|
| 135 |
+
<div class="p-4 border-t border-gray-800">
|
| 136 |
+
<form id="messageForm" class="flex items-center space-x-2">
|
| 137 |
+
<div class="flex-1 relative">
|
| 138 |
+
<input
|
| 139 |
+
id="messageInput"
|
| 140 |
+
type="text"
|
| 141 |
+
placeholder="Type your message..."
|
| 142 |
+
class="w-full bg-gray-800 border border-gray-700 rounded-full py-3 px-4 pr-12 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-transparent"
|
| 143 |
+
autocomplete="off"
|
| 144 |
+
>
|
| 145 |
+
<div class="absolute right-3 top-3 flex space-x-2">
|
| 146 |
+
<button type="button" class="text-gray-400 hover:text-indigo-400 transition emoji-trigger">
|
| 147 |
+
<i class="far fa-smile"></i>
|
| 148 |
+
</button>
|
| 149 |
+
<div class="hidden absolute bottom-14 right-0 w-64 h-64 bg-gray-800 rounded-lg shadow-xl overflow-y-auto p-2 emoji-picker">
|
| 150 |
+
<!-- Emojis will be inserted here by JavaScript -->
|
| 151 |
+
<div class="grid grid-cols-5 gap-2"></div>
|
| 152 |
+
</div>
|
| 153 |
+
<button type="button" class="text-gray-400 hover:text-indigo-400 transition" id="fileButton">
|
| 154 |
+
<i class="fas fa-paperclip"></i>
|
| 155 |
+
</button>
|
| 156 |
+
</div>
|
| 157 |
+
</div>
|
| 158 |
+
<button
|
| 159 |
+
type="submit"
|
| 160 |
+
class="w-12 h-12 rounded-full bg-gradient-to-br from-indigo-500 to-purple-600 flex items-center justify-center hover:from-indigo-600 hover:to-purple-700 transition transform hover:scale-105 focus:outline-none"
|
| 161 |
+
>
|
| 162 |
+
<i class="fas fa-paper-plane text-white"></i>
|
| 163 |
+
</button>
|
| 164 |
+
</form>
|
| 165 |
+
<input type="file" id="fileInput" class="hidden" accept=".gif,.jpeg,.jpg,.webp,.png,.zip,.txt" multiple>
|
| 166 |
+
</div>
|
| 167 |
+
</div>
|
| 168 |
+
</div>
|
| 169 |
+
</div>
|
| 170 |
+
|
| 171 |
+
<script>
|
| 172 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 173 |
+
// DOM Elements
|
| 174 |
+
const messageForm = document.getElementById('messageForm');
|
| 175 |
+
const messageInput = document.getElementById('messageInput');
|
| 176 |
+
const messagesContainer = document.querySelector('.messages-container');
|
| 177 |
+
const typingIndicator = document.getElementById('typingIndicator');
|
| 178 |
+
const themeToggle = document.getElementById('themeToggle');
|
| 179 |
+
|
| 180 |
+
// Sample user data
|
| 181 |
+
const users = [
|
| 182 |
+
{ id: 1, name: "You", initials: "ME", color: "from-indigo-400 to-purple-500" },
|
| 183 |
+
{ id: 2, name: "John Doe", initials: "JD", color: "from-green-400 to-blue-500" },
|
| 184 |
+
{ id: 3, name: "Alice", initials: "AM", color: "from-pink-500 to-red-500" },
|
| 185 |
+
{ id: 4, name: "Tom", initials: "TS", color: "from-yellow-400 to-orange-500" }
|
| 186 |
+
];
|
| 187 |
+
|
| 188 |
+
// Load messages from localStorage or initialize
|
| 189 |
+
let messages = JSON.parse(localStorage.getItem('chatMessages')) || [
|
| 190 |
+
{ id: 1, userId: 2, text: "Hey there! 👋", timestamp: new Date().getTime() - 3600000 },
|
| 191 |
+
{ id: 2, userId: 1, text: "Hi John! How are you?", timestamp: new Date().getTime() - 3500000 },
|
| 192 |
+
{ id: 3, userId: 2, text: "I'm good, thanks! Working on that project we discussed.", timestamp: new Date().getTime() - 3400000 },
|
| 193 |
+
{ id: 4, userId: 3, text: "Hello everyone! 😊", timestamp: new Date().getTime() - 3000000 },
|
| 194 |
+
{ id: 5, userId: 1, text: "Hi Alice! Welcome to the chat.", timestamp: new Date().getTime() - 2900000 },
|
| 195 |
+
{ id: 6, userId: 4, text: "Sorry I'm late to the party. What did I miss?", timestamp: new Date().getTime() - 1000000 }
|
| 196 |
+
];
|
| 197 |
+
|
| 198 |
+
// Display existing messages
|
| 199 |
+
renderMessages();
|
| 200 |
+
|
| 201 |
+
// Emoji handling
|
| 202 |
+
const emojiTrigger = document.querySelector('.emoji-trigger');
|
| 203 |
+
const emojiPicker = document.querySelector('.emoji-picker');
|
| 204 |
+
const emojiContainer = emojiPicker.querySelector('div');
|
| 205 |
+
|
| 206 |
+
// Common emojis
|
| 207 |
+
const emojis = ['😀', '😂', '😊', '🤔', '😎', '😍', '🥳', '😱', '🤯', '👋',
|
| 208 |
+
'👍', '👎', '❤️', '🔥', '🎉', '💯', '😢', '😡', '😴', '🤑'];
|
| 209 |
+
|
| 210 |
+
// Populate emoji picker
|
| 211 |
+
emojis.forEach(emoji => {
|
| 212 |
+
const emojiButton = document.createElement('button');
|
| 213 |
+
emojiButton.classList.add('emoji', 'text-2xl', 'hover:bg-gray-700', 'rounded',
|
| 214 |
+
'p-1', 'w-full', 'h-8', 'flex', 'items-center', 'justify-center');
|
| 215 |
+
emojiButton.textContent = emoji;
|
| 216 |
+
emojiButton.addEventListener('click', () => {
|
| 217 |
+
messageInput.value += emoji;
|
| 218 |
+
messageInput.focus();
|
| 219 |
+
emojiPicker.classList.add('hidden');
|
| 220 |
+
});
|
| 221 |
+
emojiContainer.appendChild(emojiButton);
|
| 222 |
+
});
|
| 223 |
+
|
| 224 |
+
// Toggle emoji picker
|
| 225 |
+
emojiTrigger.addEventListener('click', () => {
|
| 226 |
+
emojiPicker.classList.toggle('hidden');
|
| 227 |
+
// Position picker above input
|
| 228 |
+
emojiPicker.style.bottom = `${messageInput.offsetHeight + 16}px`;
|
| 229 |
+
});
|
| 230 |
+
|
| 231 |
+
// Hide emoji picker when clicking elsewhere
|
| 232 |
+
document.addEventListener('click', (e) => {
|
| 233 |
+
if (!emojiTrigger.contains(e.target) && !emojiPicker.contains(e.target)) {
|
| 234 |
+
emojiPicker.classList.add('hidden');
|
| 235 |
+
}
|
| 236 |
+
});
|
| 237 |
+
|
| 238 |
+
// File upload handling
|
| 239 |
+
const fileButton = document.getElementById('fileButton');
|
| 240 |
+
const fileInput = document.getElementById('fileInput');
|
| 241 |
+
|
| 242 |
+
fileButton.addEventListener('click', () => {
|
| 243 |
+
fileInput.click();
|
| 244 |
+
});
|
| 245 |
+
|
| 246 |
+
fileInput.addEventListener('change', (e) => {
|
| 247 |
+
const files = Array.from(e.target.files);
|
| 248 |
+
if (files.length > 0) {
|
| 249 |
+
files.forEach(file => {
|
| 250 |
+
// Create a message for each file
|
| 251 |
+
const newMessage = {
|
| 252 |
+
id: messages.length + 1,
|
| 253 |
+
userId: 1, // Current user
|
| 254 |
+
text: `📁 ${file.name} (${formatFileSize(file.size)})`,
|
| 255 |
+
isFile: true,
|
| 256 |
+
file: file,
|
| 257 |
+
timestamp: new Date().getTime()
|
| 258 |
+
};
|
| 259 |
+
|
| 260 |
+
messages.push(newMessage);
|
| 261 |
+
localStorage.setItem('chatMessages', JSON.stringify(messages));
|
| 262 |
+
renderMessage(newMessage);
|
| 263 |
+
scrollToBottom();
|
| 264 |
+
});
|
| 265 |
+
|
| 266 |
+
// Reset input
|
| 267 |
+
fileInput.value = '';
|
| 268 |
+
|
| 269 |
+
// Simulate reply
|
| 270 |
+
setTimeout(() => {
|
| 271 |
+
simulateReply();
|
| 272 |
+
}, Math.random() * 2000 + 1000);
|
| 273 |
+
}
|
| 274 |
+
});
|
| 275 |
+
|
| 276 |
+
function formatFileSize(bytes) {
|
| 277 |
+
if (bytes === 0) return '0 Bytes';
|
| 278 |
+
const k = 1024;
|
| 279 |
+
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
|
| 280 |
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
| 281 |
+
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
|
| 282 |
+
}
|
| 283 |
+
|
| 284 |
+
// Theme toggle
|
| 285 |
+
themeToggle.addEventListener('click', function() {
|
| 286 |
+
document.body.classList.toggle('bg-gray-100');
|
| 287 |
+
document.body.classList.toggle('text-gray-900');
|
| 288 |
+
document.body.classList.toggle('bg-gray-900');
|
| 289 |
+
document.body.classList.toggle('text-white');
|
| 290 |
+
|
| 291 |
+
const isDark = document.body.classList.contains('bg-gray-900');
|
| 292 |
+
themeToggle.innerHTML = isDark
|
| 293 |
+
? '<i class="fas fa-sun text-yellow-300"></i>'
|
| 294 |
+
: '<i class="fas fa-moon text-indigo-700"></i>';
|
| 295 |
+
});
|
| 296 |
+
|
| 297 |
+
// Form submission
|
| 298 |
+
messageForm.addEventListener('submit', function(e) {
|
| 299 |
+
e.preventDefault();
|
| 300 |
+
const messageText = messageInput.value.trim();
|
| 301 |
+
|
| 302 |
+
if (messageText) {
|
| 303 |
+
// Create new message
|
| 304 |
+
const newMessage = {
|
| 305 |
+
id: messages.length + 1,
|
| 306 |
+
userId: 1, // Current user
|
| 307 |
+
text: messageText,
|
| 308 |
+
timestamp: new Date().getTime()
|
| 309 |
+
};
|
| 310 |
+
|
| 311 |
+
// Add to messages array
|
| 312 |
+
messages.push(newMessage);
|
| 313 |
+
|
| 314 |
+
// Save to localStorage
|
| 315 |
+
localStorage.setItem('chatMessages', JSON.stringify(messages));
|
| 316 |
+
|
| 317 |
+
// Clear input
|
| 318 |
+
messageInput.value = '';
|
| 319 |
+
|
| 320 |
+
// Render new message
|
| 321 |
+
renderMessage(newMessage);
|
| 322 |
+
|
| 323 |
+
// Scroll to bottom
|
| 324 |
+
scrollToBottom();
|
| 325 |
+
|
| 326 |
+
// Simulate reply after 1-3 seconds
|
| 327 |
+
setTimeout(() => {
|
| 328 |
+
simulateReply();
|
| 329 |
+
}, Math.random() * 2000 + 1000);
|
| 330 |
+
}
|
| 331 |
+
});
|
| 332 |
+
|
| 333 |
+
// Typing indicator
|
| 334 |
+
let typingTimeout;
|
| 335 |
+
messageInput.addEventListener('input', function() {
|
| 336 |
+
// Show typing indicator
|
| 337 |
+
typingIndicator.classList.remove('hidden');
|
| 338 |
+
|
| 339 |
+
// Clear previous timeout
|
| 340 |
+
clearTimeout(typingTimeout);
|
| 341 |
+
|
| 342 |
+
// Hide after 2 seconds of inactivity
|
| 343 |
+
typingTimeout = setTimeout(() => {
|
| 344 |
+
typingIndicator.classList.add('hidden');
|
| 345 |
+
}, 2000);
|
| 346 |
+
});
|
| 347 |
+
|
| 348 |
+
// Render all messages
|
| 349 |
+
function renderMessages() {
|
| 350 |
+
messagesContainer.innerHTML = '';
|
| 351 |
+
messages.forEach(message => {
|
| 352 |
+
renderMessage(message);
|
| 353 |
+
});
|
| 354 |
+
scrollToBottom();
|
| 355 |
+
}
|
| 356 |
+
|
| 357 |
+
// Render a single message
|
| 358 |
+
function renderMessage(message) {
|
| 359 |
+
const user = users.find(u => u.id === message.userId);
|
| 360 |
+
const isCurrentUser = message.userId === 1;
|
| 361 |
+
|
| 362 |
+
const messageElement = document.createElement('div');
|
| 363 |
+
messageElement.className = `message-animation flex ${isCurrentUser ? 'justify-end' : 'justify-start'}`;
|
| 364 |
+
|
| 365 |
+
let content = `<p>${message.text}</p>`;
|
| 366 |
+
if (message.isFile) {
|
| 367 |
+
const fileExt = message.file.name.split('.').pop().toLowerCase();
|
| 368 |
+
if (['gif', 'jpeg', 'jpg', 'webp', 'png'].includes(fileExt)) {
|
| 369 |
+
content = `
|
| 370 |
+
<div class="mb-1">
|
| 371 |
+
<img src="${URL.createObjectURL(message.file)}"
|
| 372 |
+
alt="${message.file.name}"
|
| 373 |
+
class="max-h-48 rounded-lg cursor-pointer hover:opacity-90 transition">
|
| 374 |
+
</div>
|
| 375 |
+
<p class="text-sm">${message.file.name}</p>
|
| 376 |
+
`;
|
| 377 |
+
} else {
|
| 378 |
+
content = `
|
| 379 |
+
<div class="flex items-center space-x-2 p-2 bg-gray-700 rounded-lg">
|
| 380 |
+
<i class="fas fa-file-alt text-2xl"></i>
|
| 381 |
+
<div>
|
| 382 |
+
<p class="text-sm font-medium">${message.file.name}</p>
|
| 383 |
+
<p class="text-xs text-gray-400">${formatFileSize(message.file.size)}</p>
|
| 384 |
+
</div>
|
| 385 |
+
</div>
|
| 386 |
+
`;
|
| 387 |
+
}
|
| 388 |
+
}
|
| 389 |
+
|
| 390 |
+
messageElement.innerHTML = `
|
| 391 |
+
<div class="flex ${isCurrentUser ? 'flex-row-reverse' : ''} max-w-xs md:max-w-md lg:max-w-lg">
|
| 392 |
+
<div class="flex-shrink-0 mr-3 ml-3">
|
| 393 |
+
<div class="w-10 h-10 rounded-full bg-gradient-to-br ${user.color} flex items-center justify-center">
|
| 394 |
+
<span class="text-xs font-bold">${user.initials}</span>
|
| 395 |
+
</div>
|
| 396 |
+
</div>
|
| 397 |
+
<div>
|
| 398 |
+
<div class="${isCurrentUser ? 'bg-indigo-600 text-white' : 'bg-gray-800 text-white'} rounded-2xl px-4 py-2 shadow-lg">
|
| 399 |
+
${content}
|
| 400 |
+
</div>
|
| 401 |
+
<div class="text-xs text-gray-400 mt-1 ${isCurrentUser ? 'text-right' : 'text-left'}">
|
| 402 |
+
${formatTime(message.timestamp)}
|
| 403 |
+
</div>
|
| 404 |
+
</div>
|
| 405 |
+
</div>
|
| 406 |
+
`;
|
| 407 |
+
|
| 408 |
+
messagesContainer.appendChild(messageElement);
|
| 409 |
+
}
|
| 410 |
+
|
| 411 |
+
// Simulate a reply from another user
|
| 412 |
+
function simulateReply() {
|
| 413 |
+
const replies = [
|
| 414 |
+
"Sounds good!",
|
| 415 |
+
"I'll get back to you on that.",
|
| 416 |
+
"What time works for you?",
|
| 417 |
+
"Let me check my schedule.",
|
| 418 |
+
"That's interesting!",
|
| 419 |
+
"Can we discuss this tomorrow?",
|
| 420 |
+
"I agree with you.",
|
| 421 |
+
"Thanks for letting me know!",
|
| 422 |
+
"Have you seen the latest updates?",
|
| 423 |
+
"Let's meet up soon!"
|
| 424 |
+
];
|
| 425 |
+
|
| 426 |
+
const randomUser = users[Math.floor(Math.random() * (users.length - 1)) + 1];
|
| 427 |
+
const randomReply = replies[Math.floor(Math.random() * replies.length)];
|
| 428 |
+
|
| 429 |
+
// Show typing indicator
|
| 430 |
+
typingIndicator.classList.remove('hidden');
|
| 431 |
+
|
| 432 |
+
setTimeout(() => {
|
| 433 |
+
// Hide typing indicator
|
| 434 |
+
typingIndicator.classList.add('hidden');
|
| 435 |
+
|
| 436 |
+
// Create new message
|
| 437 |
+
const newMessage = {
|
| 438 |
+
id: messages.length + 1,
|
| 439 |
+
userId: randomUser.id,
|
| 440 |
+
text: randomReply,
|
| 441 |
+
timestamp: new Date().getTime()
|
| 442 |
+
};
|
| 443 |
+
|
| 444 |
+
// Add to messages array
|
| 445 |
+
messages.push(newMessage);
|
| 446 |
+
|
| 447 |
+
// Save to localStorage
|
| 448 |
+
localStorage.setItem('chatMessages', JSON.stringify(messages));
|
| 449 |
+
|
| 450 |
+
// Render new message
|
| 451 |
+
renderMessage(newMessage);
|
| 452 |
+
|
| 453 |
+
// Scroll to bottom
|
| 454 |
+
scrollToBottom();
|
| 455 |
+
}, 1500);
|
| 456 |
+
}
|
| 457 |
+
|
| 458 |
+
// Format timestamp
|
| 459 |
+
function formatTime(timestamp) {
|
| 460 |
+
const date = new Date(timestamp);
|
| 461 |
+
return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
| 462 |
+
}
|
| 463 |
+
|
| 464 |
+
// Scroll to bottom of messages
|
| 465 |
+
function scrollToBottom() {
|
| 466 |
+
messagesContainer.scrollTop = messagesContainer.scrollHeight;
|
| 467 |
+
}
|
| 468 |
+
|
| 469 |
+
// Initial scroll to bottom
|
| 470 |
+
scrollToBottom();
|
| 471 |
+
});
|
| 472 |
+
</script>
|
| 473 |
+
<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=pcudima/test" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
|
| 474 |
+
</html>
|