Spaces:
Running
Running
Download index.html from sldshr/Client_Less: direct link, hf CLI and curl.
- Browser
- Download file 23.7 kB
-
https://huggingface.co/spaces/sldshr/Client_Less/resolve/c2dc3f3ab883f56e9258bae4e6726507abe2d131/index.html
- Command line
-
hf download hf://spaces/sldshr/Client_Less@c2dc3f3ab883f56e9258bae4e6726507abe2d131/index.html
-
curl -L -o index.html https://huggingface.co/spaces/sldshr/Client_Less/resolve/c2dc3f3ab883f56e9258bae4e6726507abe2d131/index.html
23.7 kB
| <html lang="ru"> | |
| <head> | |
| <meta charset="UTF-8" /> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
| <title>Matrix клиент (unredacted.org)</title> | |
| <style> | |
| /* ----- Общие стили ----- */ | |
| * { | |
| margin: 0; | |
| padding: 0; | |
| box-sizing: border-box; | |
| } | |
| body { | |
| font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; | |
| background: #1a1a1e; | |
| color: #e4e4e7; | |
| height: 100vh; | |
| display: flex; | |
| flex-direction: column; | |
| } | |
| button { | |
| background: #2c2c32; | |
| color: #e4e4e7; | |
| border: 1px solid #3f3f46; | |
| padding: 0.5rem 1rem; | |
| border-radius: 6px; | |
| cursor: pointer; | |
| font-size: 0.9rem; | |
| transition: background 0.2s; | |
| } | |
| button:hover { | |
| background: #3f3f46; | |
| } | |
| input, | |
| textarea { | |
| background: #2c2c32; | |
| color: #e4e4e7; | |
| border: 1px solid #3f3f46; | |
| padding: 0.5rem; | |
| border-radius: 6px; | |
| font-size: 0.9rem; | |
| width: 100%; | |
| outline: none; | |
| } | |
| input:focus, | |
| textarea:focus { | |
| border-color: #6b6b7a; | |
| } | |
| .hidden { | |
| display: none ; | |
| } | |
| .flex-row { | |
| display: flex; | |
| gap: 0.5rem; | |
| align-items: center; | |
| } | |
| .flex-col { | |
| display: flex; | |
| flex-direction: column; | |
| gap: 0.5rem; | |
| } | |
| /* ----- Экран входа ----- */ | |
| #login-screen { | |
| max-width: 400px; | |
| margin: 5rem auto; | |
| padding: 2rem; | |
| background: #24242a; | |
| border-radius: 12px; | |
| box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5); | |
| } | |
| #login-screen h1 { | |
| font-size: 1.8rem; | |
| margin-bottom: 1.5rem; | |
| text-align: center; | |
| font-weight: 500; | |
| letter-spacing: -0.5px; | |
| } | |
| #login-screen .field { | |
| margin-bottom: 1rem; | |
| } | |
| #login-screen .field label { | |
| display: block; | |
| font-size: 0.85rem; | |
| color: #a1a1aa; | |
| margin-bottom: 0.25rem; | |
| } | |
| #login-status { | |
| margin-top: 1rem; | |
| color: #f87171; | |
| font-size: 0.9rem; | |
| text-align: center; | |
| min-height: 1.5rem; | |
| } | |
| /* ----- Основной интерфейс ----- */ | |
| #app { | |
| display: none; | |
| height: 100vh; | |
| flex-direction: row; | |
| } | |
| #app.active { | |
| display: flex; | |
| } | |
| /* ----- Боковая панель (комнаты) ----- */ | |
| #sidebar { | |
| width: 280px; | |
| min-width: 200px; | |
| background: #1f1f23; | |
| border-right: 1px solid #2d2d33; | |
| display: flex; | |
| flex-direction: column; | |
| height: 100vh; | |
| overflow: hidden; | |
| } | |
| #sidebar-header { | |
| padding: 1rem; | |
| border-bottom: 1px solid #2d2d33; | |
| display: flex; | |
| justify-content: space-between; | |
| align-items: center; | |
| flex-shrink: 0; | |
| } | |
| #sidebar-header .user { | |
| font-size: 0.85rem; | |
| color: #a1a1aa; | |
| overflow: hidden; | |
| text-overflow: ellipsis; | |
| white-space: nowrap; | |
| max-width: 140px; | |
| } | |
| #sidebar-header button { | |
| padding: 0.25rem 0.75rem; | |
| font-size: 0.8rem; | |
| } | |
| #room-list { | |
| flex: 1; | |
| overflow-y: auto; | |
| padding: 0.5rem 0; | |
| } | |
| .room-item { | |
| padding: 0.6rem 1rem; | |
| cursor: pointer; | |
| border-left: 3px solid transparent; | |
| transition: background 0.15s; | |
| display: flex; | |
| align-items: center; | |
| gap: 0.5rem; | |
| font-size: 0.95rem; | |
| } | |
| .room-item:hover { | |
| background: #2c2c32; | |
| } | |
| .room-item.active { | |
| background: #2c2c32; | |
| border-left-color: #818cf8; | |
| } | |
| .room-item .name { | |
| flex: 1; | |
| overflow: hidden; | |
| text-overflow: ellipsis; | |
| white-space: nowrap; | |
| } | |
| .room-item .badge { | |
| background: #818cf8; | |
| color: #fff; | |
| border-radius: 12px; | |
| padding: 0 0.6rem; | |
| font-size: 0.7rem; | |
| line-height: 1.4rem; | |
| font-weight: 600; | |
| } | |
| /* ----- Область чата ----- */ | |
| #chat { | |
| flex: 1; | |
| display: flex; | |
| flex-direction: column; | |
| height: 100vh; | |
| background: #18181b; | |
| min-width: 0; | |
| } | |
| #chat-header { | |
| padding: 0.8rem 1.5rem; | |
| border-bottom: 1px solid #2d2d33; | |
| flex-shrink: 0; | |
| background: #1f1f23; | |
| } | |
| #chat-header .room-name { | |
| font-size: 1.1rem; | |
| font-weight: 500; | |
| } | |
| #chat-header .room-topic { | |
| font-size: 0.85rem; | |
| color: #a1a1aa; | |
| margin-top: 0.1rem; | |
| } | |
| #messages { | |
| flex: 1; | |
| overflow-y: auto; | |
| padding: 1rem 1.5rem; | |
| display: flex; | |
| flex-direction: column; | |
| gap: 0.4rem; | |
| background: #18181b; | |
| } | |
| .msg { | |
| display: flex; | |
| flex-direction: column; | |
| padding: 0.3rem 0.6rem; | |
| border-radius: 6px; | |
| max-width: 80%; | |
| word-wrap: break-word; | |
| line-height: 1.4; | |
| } | |
| .msg.self { | |
| align-self: flex-end; | |
| background: #2c2c3a; | |
| } | |
| .msg.other { | |
| align-self: flex-start; | |
| background: #24242a; | |
| } | |
| .msg .sender { | |
| font-size: 0.75rem; | |
| color: #a1a1aa; | |
| margin-bottom: 0.1rem; | |
| } | |
| .msg .body { | |
| font-size: 0.95rem; | |
| } | |
| .msg .time { | |
| font-size: 0.65rem; | |
| color: #6b6b7a; | |
| align-self: flex-end; | |
| margin-top: 0.1rem; | |
| } | |
| .msg .event-id { | |
| font-size: 0.6rem; | |
| color: #4b4b5a; | |
| word-break: break-all; | |
| } | |
| #compose { | |
| padding: 0.8rem 1.5rem; | |
| border-top: 1px solid #2d2d33; | |
| flex-shrink: 0; | |
| background: #1f1f23; | |
| display: flex; | |
| gap: 0.5rem; | |
| align-items: flex-end; | |
| } | |
| #compose textarea { | |
| resize: none; | |
| height: 44px; | |
| max-height: 120px; | |
| padding: 0.6rem; | |
| flex: 1; | |
| } | |
| #compose button { | |
| height: 44px; | |
| padding: 0 1.2rem; | |
| flex-shrink: 0; | |
| background: #818cf8; | |
| border-color: #818cf8; | |
| color: #fff; | |
| font-weight: 500; | |
| } | |
| #compose button:hover { | |
| background: #6b74d6; | |
| border-color: #6b74d6; | |
| } | |
| /* ----- Скролл ----- */ | |
| ::-webkit-scrollbar { | |
| width: 6px; | |
| } | |
| ::-webkit-scrollbar-track { | |
| background: #1a1a1e; | |
| } | |
| ::-webkit-scrollbar-thumb { | |
| background: #3f3f46; | |
| border-radius: 4px; | |
| } | |
| ::-webkit-scrollbar-thumb:hover { | |
| background: #52525b; | |
| } | |
| /* Адаптив */ | |
| @media (max-width: 640px) { | |
| #sidebar { | |
| width: 200px; | |
| min-width: 140px; | |
| } | |
| #sidebar-header .user { | |
| max-width: 80px; | |
| } | |
| #messages { | |
| padding: 0.5rem; | |
| } | |
| .msg { | |
| max-width: 95%; | |
| } | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <!-- ===== ЭКРАН ВХОДА ===== --> | |
| <div id="login-screen"> | |
| <h1>🧩 Matrix</h1> | |
| <form id="login-form" class="flex-col"> | |
| <div class="field"> | |
| <label for="user">Имя пользователя (@user:server)</label> | |
| <input type="text" id="user" placeholder="@alice:matrix.unredacted.org" /> | |
| </div> | |
| <div class="field"> | |
| <label for="pass">Пароль</label> | |
| <input type="password" id="pass" placeholder="••••••••" /> | |
| </div> | |
| <button type="submit" style="width:100%; margin-top:0.5rem;">Войти</button> | |
| <div id="login-status"></div> | |
| </form> | |
| <div style="margin-top:1rem; font-size:0.8rem; color:#6b6b7a; text-align:center;"> | |
| Сервер: matrix.unredacted.org | |
| </div> | |
| </div> | |
| <!-- ===== ОСНОВНОЙ ИНТЕРФЕЙС ===== --> | |
| <div id="app"> | |
| <!-- Боковая панель --> | |
| <div id="sidebar"> | |
| <div id="sidebar-header"> | |
| <span class="user" id="current-user">@user</span> | |
| <button id="logout-btn" title="Выйти">🚪</button> | |
| </div> | |
| <div id="room-list"></div> | |
| </div> | |
| <!-- Чат --> | |
| <div id="chat"> | |
| <div id="chat-header"> | |
| <div class="room-name" id="room-name">Выберите комнату</div> | |
| <div class="room-topic" id="room-topic"></div> | |
| </div> | |
| <div id="messages"></div> | |
| <div id="compose"> | |
| <textarea id="msg-input" placeholder="Введите сообщение…" rows="1"></textarea> | |
| <button id="send-btn">Отправить</button> | |
| </div> | |
| </div> | |
| </div> | |
| <script> | |
| // ============================================================ | |
| // Matrix клиент (matrix.unredacted.org) | |
| // Использует Client-Server API v3 | |
| // ============================================================ | |
| const HS_URL = 'https://matrix.unredacted.org'; | |
| // ----- Состояние ----- | |
| let accessToken = null; | |
| let userId = null; | |
| let deviceId = null; | |
| let rooms = {}; // roomId -> { name, topic, timeline: [msg], unread } | |
| let currentRoomId = null; | |
| let syncFilter = null; | |
| let syncSince = null; | |
| let syncTimeout = null; | |
| let isSyncing = false; | |
| // DOM ссылки | |
| const loginScreen = document.getElementById('login-screen'); | |
| const app = document.getElementById('app'); | |
| const loginForm = document.getElementById('login-form'); | |
| const loginStatus = document.getElementById('login-status'); | |
| const userInput = document.getElementById('user'); | |
| const passInput = document.getElementById('pass'); | |
| const roomList = document.getElementById('room-list'); | |
| const messagesContainer = document.getElementById('messages'); | |
| const roomNameEl = document.getElementById('room-name'); | |
| const roomTopicEl = document.getElementById('room-topic'); | |
| const msgInput = document.getElementById('msg-input'); | |
| const sendBtn = document.getElementById('send-btn'); | |
| const logoutBtn = document.getElementById('logout-btn'); | |
| const currentUserEl = document.getElementById('current-user'); | |
| // ----- Вспомогательные функции ----- | |
| function escapeHtml(text) { | |
| if (!text) return ''; | |
| const div = document.createElement('div'); | |
| div.textContent = text; | |
| return div.innerHTML; | |
| } | |
| function formatTime(ts) { | |
| if (!ts) return ''; | |
| const d = new Date(ts); | |
| return d.toLocaleTimeString('ru-RU', { hour: '2-digit', minute: '2-digit' }); | |
| } | |
| function getRoomDisplayName(roomId, name) { | |
| return name && name.trim() ? name.trim() : roomId; | |
| } | |
| // ----- API запросы ----- | |
| async function matrixRequest(endpoint, method = 'GET', body = null, token = null) { | |
| const url = HS_URL + endpoint; | |
| const headers = { | |
| 'Content-Type': 'application/json', | |
| 'Accept': 'application/json', | |
| }; | |
| if (token) { | |
| headers['Authorization'] = 'Bearer ' + token; | |
| } | |
| const opts = { | |
| method, | |
| headers, | |
| }; | |
| if (body) { | |
| opts.body = JSON.stringify(body); | |
| } | |
| const resp = await fetch(url, opts); | |
| if (!resp.ok) { | |
| let errMsg = `${resp.status} ${resp.statusText}`; | |
| try { | |
| const data = await resp.json(); | |
| if (data.error) errMsg = data.error; | |
| } catch (_) { /* ignore */ } | |
| throw new Error(errMsg); | |
| } | |
| if (resp.status === 204) return null; | |
| return resp.json(); | |
| } | |
| // ----- Логин ----- | |
| async function doLogin(user, password) { | |
| try { | |
| const data = await matrixRequest('/_matrix/client/v3/login', 'POST', { | |
| type: 'm.login.password', | |
| identifier: { type: 'm.id.user', user }, | |
| password, | |
| initial_device_display_name: 'Web Client (unredacted)', | |
| }); | |
| accessToken = data.access_token; | |
| userId = data.user_id; | |
| deviceId = data.device_id; | |
| return true; | |
| } catch (err) { | |
| loginStatus.textContent = 'Ошибка: ' + err.message; | |
| return false; | |
| } | |
| } | |
| // ----- Загрузка комнат ----- | |
| async function fetchJoinedRooms() { | |
| const data = await matrixRequest('/_matrix/client/v3/joined_rooms', 'GET', null, accessToken); | |
| const roomIds = data.joined_rooms || []; | |
| // Получаем информацию о каждой комнате (state) | |
| for (const id of roomIds) { | |
| await fetchRoomState(id); | |
| } | |
| return roomIds; | |
| } | |
| async function fetchRoomState(roomId) { | |
| try { | |
| const state = await matrixRequest(`/_matrix/client/v3/rooms/${roomId}/state`, 'GET', null, accessToken); | |
| let name = roomId; | |
| let topic = ''; | |
| for (const ev of state) { | |
| if (ev.type === 'm.room.name') name = ev.content.name || roomId; | |
| if (ev.type === 'm.room.topic') topic = ev.content.topic || ''; | |
| } | |
| if (!rooms[roomId]) { | |
| rooms[roomId] = { name, topic, timeline: [], unread: 0 }; | |
| } else { | |
| rooms[roomId].name = name; | |
| rooms[roomId].topic = topic; | |
| } | |
| // Загружаем последние 20 сообщений | |
| await fetchRoomMessages(roomId, 20); | |
| } catch (err) { | |
| console.warn('Не удалось получить state для', roomId, err); | |
| if (!rooms[roomId]) { | |
| rooms[roomId] = { name: roomId, topic: '', timeline: [], unread: 0 }; | |
| } | |
| } | |
| } | |
| async function fetchRoomMessages(roomId, limit = 20) { | |
| try { | |
| const data = await matrixRequest( | |
| `/_matrix/client/v3/rooms/${roomId}/messages?dir=b&limit=${limit}&filter={"types":["m.room.message"]}`, | |
| 'GET', null, accessToken | |
| ); | |
| const events = data.chunk || []; | |
| const timeline = events.reverse().map(ev => ({ | |
| eventId: ev.event_id, | |
| sender: ev.sender, | |
| body: ev.content?.body || '', | |
| ts: ev.origin_server_ts, | |
| type: ev.type, | |
| })); | |
| if (rooms[roomId]) { | |
| rooms[roomId].timeline = timeline; | |
| } | |
| } catch (err) { | |
| console.warn('Не удалось загрузить сообщения для', roomId, err); | |
| if (rooms[roomId] && !rooms[roomId].timeline) { | |
| rooms[roomId].timeline = []; | |
| } | |
| } | |
| } | |
| // ----- Отправка сообщения ----- | |
| async function sendMessage(roomId, text) { | |
| if (!text.trim()) return; | |
| const txnId = Date.now() + '-' + Math.random().toString(36).slice(2, 8); | |
| const body = { | |
| msgtype: 'm.text', | |
| body: text.trim(), | |
| }; | |
| try { | |
| await matrixRequest( | |
| `/_matrix/client/v3/rooms/${roomId}/send/m.room.message/${txnId}`, | |
| 'PUT', body, accessToken | |
| ); | |
| // Сообщение появится в синке | |
| } catch (err) { | |
| alert('Не удалось отправить: ' + err.message); | |
| } | |
| } | |
| // ----- Синхронизация (long-polling) ----- | |
| async function startSync() { | |
| if (isSyncing) return; | |
| isSyncing = true; | |
| try { | |
| await doSync(); | |
| } catch (err) { | |
| console.error('Sync error:', err); | |
| // Продолжим через секунду | |
| setTimeout(() => { isSyncing = false; | |
| startSync(); }, 1000); | |
| } finally { | |
| isSyncing = false; | |
| } | |
| } | |
| async function doSync() { | |
| let url = '/_matrix/client/v3/sync?timeout=30000'; | |
| if (syncSince) url += '&since=' + encodeURIComponent(syncSince); | |
| if (syncFilter) url += '&filter=' + encodeURIComponent(syncFilter); | |
| try { | |
| const data = await matrixRequest(url, 'GET', null, accessToken); | |
| syncSince = data.next_batch || syncSince; | |
| // Обрабатываем комнаты | |
| const roomsData = data.rooms || {}; | |
| const join = roomsData.join || {}; | |
| for (const [roomId, roomData] of Object.entries(join)) { | |
| if (!rooms[roomId]) { | |
| rooms[roomId] = { name: roomId, topic: '', timeline: [], unread: 0 }; | |
| } | |
| // Обновляем state если есть | |
| if (roomData.state) { | |
| const events = roomData.state.events || []; | |
| for (const ev of events) { | |
| if (ev.type === 'm.room.name') { | |
| rooms[roomId].name = ev.content.name || roomId; | |
| } | |
| if (ev.type === 'm.room.topic') { | |
| rooms[roomId].topic = ev.content.topic || ''; | |
| } | |
| } | |
| } | |
| // Добавляем новые сообщения | |
| if (roomData.timeline) { | |
| const events = roomData.timeline.events || []; | |
| let newMsgs = 0; | |
| for (const ev of events) { | |
| if (ev.type === 'm.room.message') { | |
| const msg = { | |
| eventId: ev.event_id, | |
| sender: ev.sender, | |
| body: ev.content?.body || '', | |
| ts: ev.origin_server_ts, | |
| type: ev.type, | |
| }; | |
| // Избегаем дубликатов по event_id | |
| if (!rooms[roomId].timeline.some(m => m.eventId === msg.eventId)) { | |
| rooms[roomId].timeline.push(msg); | |
| newMsgs++; | |
| } | |
| } | |
| } | |
| if (newMsgs > 0 && roomId !== currentRoomId) { | |
| rooms[roomId].unread = (rooms[roomId].unread || 0) + newMsgs; | |
| } | |
| } | |
| // Обновляем unread (если есть) | |
| if (roomData.unread_notifications) { | |
| rooms[roomId].unread = roomData.unread_notifications.highlight_count || 0; | |
| } | |
| } | |
| // Обновляем UI | |
| renderRoomList(); | |
| if (currentRoomId && rooms[currentRoomId]) { | |
| renderMessages(currentRoomId); | |
| } | |
| // Запускаем следующий синк | |
| if (accessToken) { | |
| // Небольшая задержка перед следующим вызовом | |
| setTimeout(() => { | |
| if (accessToken && !isSyncing) { | |
| doSync().catch(() => {}); | |
| } | |
| }, 100); | |
| } | |
| } catch (err) { | |
| if (err.message.includes('401') || err.message.includes('403')) { | |
| // Сессия истекла | |
| alert('Сессия истекла. Войдите снова.'); | |
| logout(); | |
| return; | |
| } | |
| throw err; | |
| } | |
| } | |
| // ----- Рендеринг ----- | |
| function renderRoomList() { | |
| const ids = Object.keys(rooms); | |
| if (ids.length === 0) { | |
| roomList.innerHTML = '<div style="padding:1rem;color:#6b6b7a;">Нет комнат</div>'; | |
| return; | |
| } | |
| let html = ''; | |
| for (const id of ids) { | |
| const r = rooms[id]; | |
| const name = getRoomDisplayName(id, r.name); | |
| const active = (id === currentRoomId) ? 'active' : ''; | |
| const unread = (r.unread && r.unread > 0) ? `<span class="badge">${r.unread}</span>` : ''; | |
| html += `<div class="room-item ${active}" data-room-id="${id}"> | |
| <span class="name">${escapeHtml(name)}</span> | |
| ${unread} | |
| </div>`; | |
| } | |
| roomList.innerHTML = html; | |
| // Обработчики кликов | |
| document.querySelectorAll('.room-item').forEach(el => { | |
| el.addEventListener('click', () => { | |
| const id = el.dataset.roomId; | |
| if (id && rooms[id]) { | |
| selectRoom(id); | |
| } | |
| }); | |
| }); | |
| } | |
| function renderMessages(roomId) { | |
| const r = rooms[roomId]; | |
| if (!r) return; | |
| // Очищаем unread для этой комнаты | |
| r.unread = 0; | |
| renderRoomList(); | |
| messagesContainer.innerHTML = ''; | |
| const timeline = r.timeline || []; | |
| for (const msg of timeline) { | |
| const isSelf = (msg.sender === userId); | |
| const div = document.createElement('div'); | |
| div.className = `msg ${isSelf ? 'self' : 'other'}`; | |
| const senderName = msg.sender ? msg.sender.split(':')[0].replace('@', '') : 'unknown'; | |
| div.innerHTML = ` | |
| <div class="sender">${escapeHtml(senderName)}</div> | |
| <div class="body">${escapeHtml(msg.body)}</div> | |
| <div class="time">${formatTime(msg.ts)}</div> | |
| <div class="event-id">${msg.eventId ? escapeHtml(msg.eventId.slice(0,8)) : ''}</div> | |
| `; | |
| messagesContainer.appendChild(div); | |
| } | |
| messagesContainer.scrollTop = messagesContainer.scrollHeight; | |
| } | |
| function selectRoom(roomId) { | |
| currentRoomId = roomId; | |
| const r = rooms[roomId]; | |
| if (r) { | |
| roomNameEl.textContent = getRoomDisplayName(roomId, r.name); | |
| roomTopicEl.textContent = r.topic || ''; | |
| renderMessages(roomId); | |
| renderRoomList(); | |
| // Если нужно, подгружаем больше сообщений (лениво) | |
| } | |
| } | |
| // ----- Выход ----- | |
| function logout() { | |
| accessToken = null; | |
| userId = null; | |
| deviceId = null; | |
| syncSince = null; | |
| rooms = {}; | |
| currentRoomId = null; | |
| isSyncing = false; | |
| if (syncTimeout) { | |
| clearTimeout(syncTimeout); | |
| syncTimeout = null; | |
| } | |
| loginScreen.style.display = 'block'; | |
| app.classList.remove('active'); | |
| loginStatus.textContent = ''; | |
| userInput.value = ''; | |
| passInput.value = ''; | |
| roomList.innerHTML = ''; | |
| messagesContainer.innerHTML = ''; | |
| roomNameEl.textContent = 'Выберите комнату'; | |
| roomTopicEl.textContent = ''; | |
| } | |
| // ----- Обработчики UI ----- | |
| loginForm.addEventListener('submit', async (e) => { | |
| e.preventDefault(); | |
| const user = userInput.value.trim(); | |
| const pass = passInput.value; | |
| if (!user || !pass) { | |
| loginStatus.textContent = 'Заполните все поля'; | |
| return; | |
| } | |
| loginStatus.textContent = 'Вход…'; | |
| const ok = await doLogin(user, pass); | |
| if (ok) { | |
| loginScreen.style.display = 'none'; | |
| app.classList.add('active'); | |
| currentUserEl.textContent = userId; | |
| // Загружаем комнаты | |
| try { | |
| await fetchJoinedRooms(); | |
| renderRoomList(); | |
| // Если есть комнаты, выбираем первую | |
| const ids = Object.keys(rooms); | |
| if (ids.length > 0) { | |
| selectRoom(ids[0]); | |
| } | |
| // Запускаем синк | |
| startSync(); | |
| } catch (err) { | |
| alert('Ошибка загрузки комнат: ' + err.message); | |
| logout(); | |
| } | |
| } | |
| }); | |
| sendBtn.addEventListener('click', () => { | |
| if (!currentRoomId) { | |
| alert('Выберите комнату'); | |
| return; | |
| } | |
| const text = msgInput.value; | |
| if (!text.trim()) return; | |
| sendMessage(currentRoomId, text); | |
| msgInput.value = ''; | |
| msgInput.focus(); | |
| }); | |
| msgInput.addEventListener('keydown', (e) => { | |
| if (e.key === 'Enter' && !e.shiftKey) { | |
| e.preventDefault(); | |
| sendBtn.click(); | |
| } | |
| }); | |
| logoutBtn.addEventListener('click', logout); | |
| // Обработчик потери фокуса для автоматического расширения textarea | |
| msgInput.addEventListener('input', () => { | |
| msgInput.style.height = '44px'; | |
| msgInput.style.height = Math.min(msgInput.scrollHeight, 120) + 'px'; | |
| }); | |
| // Инициализация: если уже есть токен (на случай перезагрузки) - но мы не храним, просим логин. | |
| // Можно было бы сохранять в sessionStorage, но для простоты оставим так. | |
| console.log('Matrix клиент готов (unredacted.org)'); | |
| </script> | |
| </body> | |
| </html> |