FuckingChat/index.html

458 lines
16 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FuckingChat</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: #1a1a2e;
color: #e0e0e0;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
}
.chat-container {
background: #16213e;
border-radius: 12px;
box-shadow: 0 8px 32px rgba(0,0,0,0.5);
width: 100%;
max-width: 900px;
height: 90vh;
display: flex;
flex-direction: column;
overflow: hidden;
}
.chat-header {
background: #0f3460;
padding: 16px 20px;
border-bottom: 1px solid #1a4a7a;
display: flex;
justify-content: space-between;
align-items: center;
}
.chat-header h1 {
color: #e94560;
font-size: 18px;
font-weight: 700;
letter-spacing: 1px;
}
.chat-header .status {
font-size: 12px;
background: #1a4a7a;
padding: 4px 12px;
border-radius: 12px;
color: #a0c4ff;
}
.channel-bar {
display: flex;
background: #1a2744;
padding: 8px 12px;
gap: 6px;
border-bottom: 1px solid #0f3460;
overflow-x: auto;
}
.channel-btn {
padding: 6px 16px;
border: 1px solid #2a4a7a;
border-radius: 20px;
background: transparent;
color: #8899aa;
cursor: pointer;
font-size: 13px;
white-space: nowrap;
transition: all 0.2s;
}
.channel-btn:hover {
background: #1a3a5a;
color: #c0d0e0;
}
.channel-btn.active {
background: #e94560;
color: #fff;
border-color: #e94560;
}
.chat-messages {
flex: 1;
overflow-y: auto;
padding: 16px 20px;
background: #121e38;
}
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-track { background: #0d1528; }
.chat-messages::-webkit-scrollbar-thumb { background: #2a4a7a; border-radius: 3px; }
.message {
background: #1a2d4a;
border-radius: 8px;
padding: 10px 14px;
margin-bottom: 8px;
border-left: 3px solid #e94560;
}
.message .msg-ip {
font-size: 11px;
color: #6a8aaa;
margin-bottom: 4px;
}
.message .msg-content {
font-size: 14px;
line-height: 1.5;
word-wrap: break-word;
}
.message .msg-time {
font-size: 11px;
color: #556677;
text-align: right;
margin-top: 4px;
}
.empty-state {
text-align: center;
color: #556677;
padding: 40px;
font-size: 14px;
}
.input-area {
background: #0f3460;
padding: 12px 16px;
border-top: 1px solid #1a4a7a;
display: flex;
gap: 10px;
align-items: center;
}
.input-area input {
flex: 1;
padding: 10px 14px;
border: 1px solid #1a4a7a;
border-radius: 8px;
background: #121e38;
color: #e0e0e0;
font-size: 14px;
outline: none;
transition: border 0.2s;
}
.input-area input:focus { border-color: #e94560; }
.input-area input::placeholder { color: #4a6a8a; }
.input-area button {
padding: 10px 20px;
background: #e94560;
color: #fff;
border: none;
border-radius: 8px;
font-size: 14px;
font-weight: 600;
cursor: pointer;
transition: background 0.2s;
}
.input-area button:hover { background: #d63850; }
.input-area button:disabled {
background: #4a5a7a;
cursor: not-allowed;
}
.input-area .gif-btn {
padding: 8px 12px;
background: transparent;
border: 1px solid #2a4a7a;
border-radius: 8px;
color: #a0c4ff;
font-size: 18px;
cursor: pointer;
transition: all 0.2s;
line-height: 1;
}
.input-area .gif-btn:hover {
background: #1a3a5a;
border-color: #e94560;
}
.gif-picker {
display: none;
background: #0d1528;
border-top: 1px solid #1a4a7a;
padding: 12px 16px;
max-height: 300px;
overflow-y: auto;
}
.gif-picker.open { display: block; }
.gif-search {
display: flex;
gap: 8px;
margin-bottom: 10px;
}
.gif-search input {
flex: 1;
padding: 8px 12px;
border: 1px solid #1a4a7a;
border-radius: 6px;
background: #121e38;
color: #e0e0e0;
font-size: 13px;
outline: none;
}
.gif-search input:focus { border-color: #e94560; }
.gif-search button {
padding: 8px 14px;
background: #e94560;
color: #fff;
border: none;
border-radius: 6px;
cursor: pointer;
font-size: 13px;
}
.gif-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
gap: 8px;
}
.gif-grid img {
width: 100%;
border-radius: 6px;
cursor: pointer;
transition: transform 0.15s;
}
.gif-grid img:hover {
transform: scale(1.05);
box-shadow: 0 4px 12px rgba(233,69,96,0.3);
}
.gif-spinner {
text-align: center;
padding: 20px;
color: #556677;
font-size: 24px;
}
.message .msg-content img.inline-gif {
max-width: 200px;
max-height: 150px;
border-radius: 6px;
display: block;
margin-top: 6px;
}
.toast {
position: fixed;
bottom: 30px;
left: 50%;
transform: translateX(-50%);
padding: 10px 24px;
border-radius: 8px;
font-size: 14px;
opacity: 0;
transition: opacity 0.3s;
pointer-events: none;
z-index: 1000;
}
.toast.visible { opacity: 1; }
.toast.error { background: #c0392b; color: #fff; }
.toast.success { background: #27ae60; color: #fff; }
.toast.info { background: #2980b9; color: #fff; }
</style>
</head>
<body>
<div class="chat-container">
<div class="chat-header">
<h1>💬 FuckingChat</h1>
<span class="status" id="status-badge">Encrypted 🔒</span>
</div>
<div class="channel-bar" id="channel-bar"></div>
<div class="chat-messages" id="messages"></div>
<div class="gif-picker" id="gif-picker">
<div class="gif-search">
<input type="text" id="gif-search-input" placeholder="Search GIFs...">
<button id="gif-search-btn">Search</button>
</div>
<div class="gif-grid" id="gif-grid"></div>
</div>
<div class="input-area">
<button class="gif-btn" id="gif-btn" title="Add GIF">GIF</button>
<input type="text" id="msg-input" placeholder="Type a message..." maxlength="2000">
<button id="send-btn">Send</button>
</div>
</div>
<div class="toast" id="toast"></div>
<script>
const CHANNELS = [
{ id: 'general', name: 'General', icon: '💬' },
{ id: 'games', name: 'Games', icon: '🎮' },
{ id: 'anime', name: 'Anime', icon: '🎌' },
{ id: 'politics', name: 'Politics', icon: '⚖️' }
];
let currentChannel = 'general';
let pollInterval = null;
let selectedGifUrl = null;
const messagesEl = document.getElementById('messages');
const inputEl = document.getElementById('msg-input');
const sendBtn = document.getElementById('send-btn');
const toastEl = document.getElementById('toast');
const channelBar = document.getElementById('channel-bar');
const gifPicker = document.getElementById('gif-picker');
const gifBtn = document.getElementById('gif-btn');
const gifGrid = document.getElementById('gif-grid');
const gifSearchInput = document.getElementById('gif-search-input');
const gifSearchBtn = document.getElementById('gif-search-btn');
function escapeHtml(text) {
const d = document.createElement('div');
d.textContent = text;
return d.innerHTML;
}
// --- Tenor GIF integration ---
async function searchGifs(query) {
gifGrid.innerHTML = '<div class="gif-spinner">⏳</div>';
try {
const url = query
? `/api/gifs/search?q=${encodeURIComponent(query)}&limit=20`
: `/api/gifs/trending?limit=20`;
const r = await fetch(url);
const data = await r.json();
if (data.success) renderGifs(data.results || []);
else gifGrid.innerHTML = '<div class="empty-state">Failed to load GIFs</div>';
} catch (e) {
gifGrid.innerHTML = '<div class="empty-state">Network error</div>';
}
}
function renderGifs(results) {
if (!results.length) {
gifGrid.innerHTML = '<div class="empty-state">No GIFs found</div>';
return;
}
gifGrid.innerHTML = results.map(gif => {
const url = gif.media_formats?.tinygif?.url || gif.url;
return `<img src="${escapeHtml(url)}" alt="gif" data-gif-url="${escapeHtml(gif.url || url)}">`;
}).join('');
gifGrid.querySelectorAll('img').forEach(img => {
img.addEventListener('click', () => {
const gifUrl = img.dataset.gifUrl;
selectedGifUrl = gifUrl;
inputEl.placeholder = 'GIF selected! Add a caption or send...';
gifPicker.classList.remove('open');
showToast('GIF selected ✓', 'success');
});
});
}
gifBtn.addEventListener('click', () => {
const isOpen = gifPicker.classList.toggle('open');
if (isOpen) {
searchGifs('');
}
});
gifSearchBtn.addEventListener('click', () => {
const q = gifSearchInput.value.trim();
searchGifs(q || '');
});
gifSearchInput.addEventListener('keydown', e => {
if (e.key === 'Enter') gifSearchBtn.click();
});
function showToast(msg, type = 'info') {
toastEl.textContent = msg;
toastEl.className = 'toast visible ' + type;
setTimeout(() => toastEl.classList.remove('visible'), 3000);
}
function renderChannels() {
channelBar.innerHTML = '';
CHANNELS.forEach(ch => {
const btn = document.createElement('button');
btn.className = 'channel-btn' + (ch.id === currentChannel ? ' active' : '');
btn.textContent = ch.icon + ' ' + ch.name;
btn.onclick = () => switchChannel(ch.id);
channelBar.appendChild(btn);
});
}
function switchChannel(channel) {
if (channel === currentChannel) return;
currentChannel = channel;
renderChannels();
messagesEl.innerHTML = '<div class="empty-state">Loading...</div>';
loadMessages();
}
async function loadMessages() {
try {
const r = await fetch(`/api/messages?channel=${currentChannel}&limit=50`);
const data = await r.json();
if (data.success) renderMessages(data.messages || []);
else showToast('Failed to load messages', 'error');
} catch (e) {
showToast('Network error', 'error');
}
}
function renderMessages(msgs) {
if (msgs.length === 0) {
messagesEl.innerHTML = '<div class="empty-state">💬 No messages yet. Be the first!</div>';
return;
}
let html = '';
msgs.forEach(msg => {
const time = new Date(msg.timestamp).toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' });
let contentHtml = escapeHtml(msg.content);
// Render inline GIFs from stored <img> tags
contentHtml = contentHtml.replace(/&lt;img class=&quot;inline-gif&quot; src=&quot;(.*?)&quot;&gt;/g, (_, url) => {
return `<img class="inline-gif" src="${escapeHtml(url)}" alt="gif">`;
});
html += `<div class="message">
<div class="msg-ip">🔑 ${escapeHtml(msg.ip)}</div>
<div class="msg-content">${contentHtml}</div>
<div class="msg-time">${time}</div>
</div>`;
});
messagesEl.innerHTML = html;
messagesEl.scrollTop = messagesEl.scrollHeight;
}
async function sendMessage() {
const text = inputEl.value.trim();
if (!text && !selectedGifUrl) return;
let payload = text;
if (selectedGifUrl) {
payload = text
? `${text}\n<img class="inline-gif" src="${selectedGifUrl}">`
: `<img class="inline-gif" src="${selectedGifUrl}">`;
}
sendBtn.disabled = true;
try {
const r = await fetch('/api/messages', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ channel: currentChannel, message: payload })
});
const data = await r.json();
if (data.success) {
inputEl.value = '';
selectedGifUrl = null;
inputEl.placeholder = 'Type a message...';
loadMessages();
} else {
showToast(data.error || 'Failed to send', 'error');
}
} catch (e) {
showToast('Network error', 'error');
}
sendBtn.disabled = false;
}
// Init
renderChannels();
loadMessages();
sendBtn.addEventListener('click', sendMessage);
inputEl.addEventListener('keydown', e => { if (e.key === 'Enter') sendMessage(); });
// Auto-poll every 3 seconds
setInterval(() => loadMessages(), 3000);
</script>
</body>
</html>