Index
Index
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Enhanced Private Chat</title>
<link href="https://fonts.googleapis.com/css2?
family=Poppins:wght@300;400;500;600&display=swap" rel="stylesheet">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
body {
min-height: 100vh;
background: linear-gradient(135deg, #1a1c2c 0%, #4a3b74 100%);
color: #ffffff;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
.glass-effect {
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 20px;
padding: 20px;
box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
}
/* Stories Section */
.stories-container {
margin: 20px 0;
padding: 20px;
overflow-x: auto;
white-space: nowrap;
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
border-radius: 20px;
}
.story-item {
display: inline-block;
margin-right: 15px;
text-align: center;
cursor: pointer;
}
.story-avatar {
width: 60px;
height: 60px;
border-radius: 50%;
padding: 3px;
background: linear-gradient(45deg, #f09433 0%, #e6683c 25%, #dc2743
50%, #cc2366 75%, #bc1888 100%);
margin-bottom: 5px;
}
.story-avatar img {
width: 100%;
height: 100%;
border-radius: 50%;
border: 2px solid #1a1c2c;
}
.story-username {
font-size: 12px;
color: #fff;
}
/* Story Modal */
.story-modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.9);
z-index: 2000;
}
.story-content {
position: relative;
width: 100%;
max-width: 400px;
margin: 40px auto;
background: #1a1c2c;
border-radius: 20px;
overflow: hidden;
}
.story-header {
padding: 15px;
display: flex;
align-items: center;
justify-content: space-between;
}
.story-image {
width: 100%;
height: auto;
}
.story-footer {
padding: 15px;
}
.story-stats {
display: flex;
gap: 20px;
margin-top: 10px;
}
/* Notifications */
.notifications-icon {
position: relative;
cursor: pointer;
}
.notifications-count {
position: absolute;
top: -5px;
right: -5px;
background: #dc2743;
color: white;
border-radius: 50%;
width: 20px;
height: 20px;
display: flex;
align-items: center;
justify-content: center;
font-size: 12px;
}
.notifications-panel {
display: none;
position: absolute;
top: 60px;
right: 20px;
width: 300px;
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
border-radius: 15px;
padding: 15px;
z-index: 1000;
}
.notification-item {
padding: 10px;
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
display: flex;
align-items: center;
gap: 10px;
}
.glass-effect {
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 20px;
padding: 20px;
box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
}
.auth-container {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.8);
display: flex;
justify-content: center;
align-items: center;
z-index: 1000;
}
.auth-form {
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
padding: 40px;
border-radius: 20px;
width: 90%;
max-width: 400px;
border: 1px solid rgba(255, 255, 255, 0.2);
box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
}
.auth-form h2 {
color: #fff;
text-align: center;
margin-bottom: 20px;
font-size: 24px;
}
.auth-form input {
width: 100%;
padding: 12px;
margin: 10px 0;
border-radius: 10px;
border: 1px solid rgba(255, 255, 255, 0.2);
background: rgba(255, 255, 255, 0.05);
color: white;
font-size: 16px;
transition: all 0.3s ease;
}
.auth-form input:focus {
outline: none;
border-color: rgba(255, 255, 255, 0.5);
background: rgba(255, 255, 255, 0.1);
}
.auth-form button {
width: 100%;
padding: 12px;
margin: 10px 0;
border-radius: 10px;
border: none;
background: linear-gradient(135deg, #6e8efb 0%, #4a3b74 100%);
color: white;
cursor: pointer;
font-size: 16px;
font-weight: 500;
transition: all 0.3s ease;
}
.auth-form button:hover {
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}
#user-info {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
}
#user-info button {
padding: 8px 20px;
border-radius: 8px;
border: none;
background: linear-gradient(135deg, #ff6b6b 0%, #c92a2a 100%);
color: white;
cursor: pointer;
transition: all 0.3s ease;
}
.chat-section {
display: flex;
gap: 20px;
margin: 20px 0;
height: calc(100vh - 200px);
}
.friends-list {
width: 300px;
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
border-radius: 20px;
padding: 20px;
display: flex;
flex-direction: column;
}
.friends-list h3 {
margin-bottom: 15px;
color: #fff;
font-size: 20px;
}
.friend-item {
padding: 12px 15px;
margin: 5px 0;
border-radius: 10px;
cursor: pointer;
transition: all 0.3s ease;
font-weight: 500;
}
.friend-item:hover {
background: rgba(255, 255, 255, 0.15);
transform: translateX(5px);
}
.friend-item.active {
background: rgba(110, 142, 251, 0.3);
border-left: 4px solid #6e8efb;
}
.add-friend-form {
margin-top: auto;
padding-top: 20px;
border-top: 1px solid rgba(255, 255, 255, 0.1);
}
.add-friend-form h4 {
margin-bottom: 10px;
color: #fff;
}
.add-friend-form input {
width: 100%;
padding: 10px;
margin-bottom: 10px;
border-radius: 8px;
border: 1px solid rgba(255, 255, 255, 0.2);
background: rgba(255, 255, 255, 0.05);
color: white;
}
.add-friend-form button {
width: 100%;
padding: 10px;
border-radius: 8px;
border: none;
background: linear-gradient(135deg, #6e8efb 0%, #4a3b74 100%);
color: white;
cursor: pointer;
transition: all 0.3s ease;
}
#chat-container {
flex: 1;
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
border-radius: 20px;
padding: 20px;
overflow-y: auto;
display: flex;
flex-direction: column;
gap: 10px;
}
.message {
max-width: 70%;
padding: 12px 16px;
border-radius: 15px;
margin: 5px 0;
word-wrap: break-word;
}
.message.sent {
background: linear-gradient(135deg, #6e8efb 0%, #4a3b74 100%);
align-self: flex-end;
border-bottom-right-radius: 5px;
}
.message.received {
background: rgba(255, 255, 255, 0.15);
align-self: flex-start;
border-bottom-left-radius: 5px;
}
#message-form {
display: flex;
gap: 10px;
padding: 20px;
margin-top: 20px;
}
#message-input {
flex: 1;
padding: 12px;
border-radius: 10px;
border: 1px solid rgba(255, 255, 255, 0.2);
background: rgba(255, 255, 255, 0.05);
color: white;
font-size: 16px;
}
#message-form button {
padding: 12px 30px;
border-radius: 10px;
border: none;
background: linear-gradient(135deg, #6e8efb 0%, #4a3b74 100%);
color: white;
cursor: pointer;
transition: all 0.3s ease;
}
#message-form button:hover {
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}
/* Custom Scrollbar */
::-webkit-scrollbar {
width: 8px;
}
::-webkit-scrollbar-track {
background: rgba(255, 255, 255, 0.1);
border-radius: 10px;
}
::-webkit-scrollbar-thumb {
background: rgba(255, 255, 255, 0.2);
border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
background: rgba(255, 255, 255, 0.3);
}
</style>
</head>
<body>
<!-- Auth Container -->
<div class="auth-container" id="auth-container">
<div class="auth-form">
<h2 id="auth-title">Login</h2>
<input type="text" id="userId" placeholder="User ID">
<input type="password" id="password" placeholder="Password">
<input type="text" id="username" placeholder="Username" style="display:
none;">
<button onclick="handleAuth()">Login</button>
<button onclick="toggleAuth()">Switch to Register</button>
</div>
</div>
<div class="chat-section">
<div class="friends-list glass-effect">
<h3>Friends</h3>
<div id="friends-container"></div>
<div class="add-friend-form">
<h4>Add Friend</h4>
<input type="text" id="friend-id" placeholder="Friend's ID">
<button onclick="addFriend()">Add</button>
</div>
</div>
<script src="/socket.io/socket.io.js"></script>
<script>
let currentUserId = '';
let currentFriendId = '';
let socket = null;
let notifications = [];
try {
const response = await fetch('/upload-story', {
method: 'POST',
body: formData
});
const result = await response.json();
if (result.success) {
loadStories();
}
} catch (error) {
console.error('Error uploading story:', error);
}
};
input.click();
}
stories.forEach(story => {
const storyElement = document.createElement('div');
storyElement.className = 'story-item';
storyElement.onclick = () => viewStory(story);
storyElement.innerHTML = `
<div class="story-avatar">
<img src="${story.userAvatar ||
'/api/placeholder/60/60'}" alt="${story.username}">
</div>
<span class="story-username">${story.username}</span>
`;
storiesList.appendChild(storyElement);
});
} catch (error) {
console.error('Error loading stories:', error);
}
}
function viewStory(story) {
const modal = document.getElementById('story-modal');
const image = modal.querySelector('.story-image');
const user = modal.querySelector('.story-user');
const views = modal.querySelector('.story-views');
const likes = modal.querySelector('.story-likes');
image.src = story.imageUrl;
user.textContent = story.username;
views.textContent = `${story.views.length} views`;
likes.textContent = `${story.likes.length} likes`;
modal.style.display = 'block';
function closeStory() {
document.getElementById('story-modal').style.display = 'none';
}
// Notification functions
function toggleNotifications() {
const panel = document.getElementById('notifications-panel');
panel.style.display = panel.style.display === 'none' ? 'block' :
'none';
}
function updateNotificationCount() {
const count = document.querySelector('.notifications-count');
count.textContent = notifications.length;
}
function addNotification(notification) {
notifications.push(notification);
updateNotificationCount();
updateNotificationPanel();
}
function updateNotificationPanel() {
const panel = document.getElementById('notifications-panel');
panel.innerHTML = notifications.map(notif => `
<div class="notification-item">
<img src="${notif.avatar || '/api/placeholder/40/40'}" alt=""
style="width: 40px; height: 40px; border-radius: 50%;">
<div>
<div>${notif.message}</div>
<small>${new
Date(notif.timestamp).toLocaleTimeString()}</small>
</div>
</div>
`).join('');
}
function toggleAuth() {
const isLogin = document.getElementById('auth-title').textContent ===
'Login';
document.getElementById('auth-title').textContent = isLogin ?
'Register' : 'Login';
document.getElementById('username').style.display = isLogin ? 'block' :
'none';
}
try {
const response = await fetch(endpoint, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
});
function initializeSocket(userId) {
socket = io({
auth: {
userId
}
});
function loadFriends(friends) {
const container = document.getElementById('friends-container');
container.innerHTML = '';
friends.forEach(friend => addFriendToList({ userId: friend }));
}
function addFriendToList(friendData) {
const container = document.getElementById('friends-container');
const friendElement = document.createElement('div');
friendElement.className = 'friend-item';
friendElement.textContent = friendData.userId;
friendElement.onclick = () => selectFriend(friendData.userId);
container.appendChild(friendElement);
}
function selectFriend(friendId) {
currentFriendId = friendId;
document.querySelectorAll('.friend-item').forEach(el =>
el.classList.remove('active'));
document.querySelector(`[onclick="selectFriend('$
{friendId}')"]`).classList.add('active');
document.getElementById('chat-container').innerHTML = '';
function logout() {
currentUserId = '';
currentFriendId = '';
if (socket) socket.disconnect();
document.getElementById('auth-container').style.display = 'flex';
document.querySelector('.container').style.display = 'none';
}
</script>
</body>
</html>