Add chat dock
This commit is contained in:
parent
c0bc2298cc
commit
aad6675a28
10 changed files with 1712 additions and 4 deletions
554
app/assets/web/widgets/chatdock/app.js
Normal file
554
app/assets/web/widgets/chatdock/app.js
Normal file
|
|
@ -0,0 +1,554 @@
|
|||
class ChatDockWidget {
|
||||
constructor() {
|
||||
this.ws = null;
|
||||
this.messagesContainer = document.getElementById('chat-messages');
|
||||
this.messageInput = document.getElementById('message-input');
|
||||
this.sendButton = document.getElementById('send-button');
|
||||
this.charCount = document.getElementById('char-count');
|
||||
this.statusDot = document.querySelector('.status-dot');
|
||||
this.statusText = document.querySelector('.status-text');
|
||||
this.maxMessages = 100;
|
||||
this.autoScroll = true;
|
||||
this.reconnectAttempts = 0;
|
||||
this.maxReconnectAttempts = 10;
|
||||
|
||||
// Current platform filter (all, twitch, youtube)
|
||||
this.currentFilter = 'all';
|
||||
// Platform to send messages to (twitch or youtube)
|
||||
this.sendPlatform = 'twitch';
|
||||
|
||||
this.platformIcons = {
|
||||
twitch: `<svg width="20" height="20" viewBox="0 0 24 24" fill="#9146FF"><path d="M11.571 4.714h1.715v5.143H11.57zm4.715 0H18v5.143h-1.714zM6 0L1.714 4.286v15.428h5.143V24l4.286-4.286h3.428L22.286 12V0zm14.571 11.143l-3.428 3.428h-3.429l-3 3v-3H6.857V1.714h13.714Z"/></svg>`,
|
||||
youtube: `<svg width="20" height="20" viewBox="0 0 24 24" fill="#FF0000"><path d="M23.498 6.186a3.016 3.016 0 0 0-2.122-2.136C19.505 3.545 12 3.545 12 3.545s-7.505 0-9.377.505A3.017 3.017 0 0 0 .502 6.186C0 8.07 0 12 0 12s0 3.93.502 5.814a3.016 3.016 0 0 0 2.122 2.136c1.871.505 9.376.505 9.376.505s7.505 0 9.377-.505a3.015 3.015 0 0 0 2.122-2.136C24 15.93 24 12 24 12s0-3.93-.502-5.814zM9.545 15.568V8.432L15.818 12l-6.273 3.568z"/></svg>`,
|
||||
};
|
||||
|
||||
// Apply settings from URL query params
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
|
||||
// Theme: dark (default), light
|
||||
const theme = urlParams.get('theme');
|
||||
if (theme === 'light') {
|
||||
document.body.classList.add('theme-light');
|
||||
} else {
|
||||
document.body.classList.add('theme-dark');
|
||||
}
|
||||
|
||||
// Direction: 'down' = newest at bottom (default), 'up' = newest at top
|
||||
this.direction = urlParams.get('direction') || 'down';
|
||||
if (this.direction === 'up') {
|
||||
document.body.classList.add('direction-up');
|
||||
}
|
||||
|
||||
// Font size: small, medium (default), large, xlarge
|
||||
this.fontSize = urlParams.get('fontsize') || 'medium';
|
||||
document.body.classList.add(`font-${this.fontSize}`);
|
||||
|
||||
// Emote resolution based on font size
|
||||
this.emoteScale = (this.fontSize === 'medium' || this.fontSize === 'large' || this.fontSize === 'xlarge') ? 2 : 1;
|
||||
|
||||
// Hide timestamp option
|
||||
const hideTime = urlParams.get('hidetime');
|
||||
if (hideTime === 'true' || hideTime === '1') {
|
||||
document.body.classList.add('hide-time');
|
||||
}
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
init() {
|
||||
this.setupEventListeners();
|
||||
this.connect();
|
||||
this.updateSendPlatformIndicator();
|
||||
this.checkAuthStatus();
|
||||
|
||||
// Handle scroll to detect manual scrolling
|
||||
this.messagesContainer.addEventListener('scroll', () => {
|
||||
const container = this.messagesContainer;
|
||||
const isAtBottom = container.scrollHeight - container.scrollTop <= container.clientHeight + 50;
|
||||
this.autoScroll = isAtBottom;
|
||||
});
|
||||
}
|
||||
|
||||
setupEventListeners() {
|
||||
// Tab switching
|
||||
document.querySelectorAll('.tab').forEach(tab => {
|
||||
tab.addEventListener('click', () => this.switchTab(tab.dataset.platform));
|
||||
});
|
||||
|
||||
// Message input
|
||||
this.messageInput.addEventListener('input', () => {
|
||||
this.charCount.textContent = this.messageInput.value.length;
|
||||
});
|
||||
|
||||
this.messageInput.addEventListener('keydown', (e) => {
|
||||
if (e.key === 'Enter' && !e.shiftKey) {
|
||||
e.preventDefault();
|
||||
this.sendMessage();
|
||||
}
|
||||
});
|
||||
|
||||
// Send button
|
||||
this.sendButton.addEventListener('click', () => this.sendMessage());
|
||||
|
||||
// Platform indicator click to switch send platform
|
||||
document.getElementById('send-platform-indicator').addEventListener('click', () => {
|
||||
this.toggleSendPlatform();
|
||||
});
|
||||
|
||||
// Reconnect button
|
||||
document.getElementById('reconnect-btn').addEventListener('click', () => {
|
||||
this.reconnectChat();
|
||||
});
|
||||
}
|
||||
|
||||
switchTab(platform) {
|
||||
this.currentFilter = platform;
|
||||
|
||||
// Update tab UI
|
||||
document.querySelectorAll('.tab').forEach(tab => {
|
||||
tab.classList.toggle('active', tab.dataset.platform === platform);
|
||||
});
|
||||
|
||||
// Filter messages
|
||||
this.filterMessages();
|
||||
|
||||
// Update send target based on selected tab
|
||||
this.sendPlatform = platform; // Can be 'all', 'twitch', or 'youtube'
|
||||
this.updateSendPlatformIndicator();
|
||||
}
|
||||
|
||||
filterMessages() {
|
||||
const messages = this.messagesContainer.querySelectorAll('.chat-message');
|
||||
messages.forEach(msg => {
|
||||
if (this.currentFilter === 'all') {
|
||||
msg.style.display = '';
|
||||
} else {
|
||||
const msgPlatform = msg.classList.contains('twitch') ? 'twitch' : 'youtube';
|
||||
msg.style.display = msgPlatform === this.currentFilter ? '' : 'none';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
toggleSendPlatform() {
|
||||
// Cycle through: all -> twitch -> youtube -> all
|
||||
if (this.sendPlatform === 'all') {
|
||||
this.sendPlatform = 'twitch';
|
||||
} else if (this.sendPlatform === 'twitch') {
|
||||
this.sendPlatform = 'youtube';
|
||||
} else {
|
||||
this.sendPlatform = 'all';
|
||||
}
|
||||
this.updateSendPlatformIndicator();
|
||||
}
|
||||
|
||||
updateSendPlatformIndicator() {
|
||||
const iconEl = document.getElementById('send-platform-icon');
|
||||
const nameEl = document.getElementById('send-platform-name');
|
||||
const indicator = document.getElementById('send-platform-indicator');
|
||||
|
||||
if (this.sendPlatform === 'all') {
|
||||
// Show both icons for "all"
|
||||
iconEl.innerHTML = `
|
||||
<span class="dual-icons">
|
||||
${this.platformIcons.twitch}
|
||||
${this.platformIcons.youtube}
|
||||
</span>
|
||||
`;
|
||||
nameEl.textContent = 'All';
|
||||
indicator.className = 'all';
|
||||
} else {
|
||||
iconEl.innerHTML = this.platformIcons[this.sendPlatform];
|
||||
nameEl.textContent = this.sendPlatform === 'twitch' ? 'Twitch' : 'YouTube';
|
||||
indicator.className = this.sendPlatform;
|
||||
}
|
||||
}
|
||||
|
||||
connect() {
|
||||
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||
const wsUrl = `${protocol}//${window.location.host}/ws`;
|
||||
|
||||
this.ws = new WebSocket(wsUrl);
|
||||
|
||||
this.ws.onopen = () => {
|
||||
console.log('Chat WebSocket connected');
|
||||
this.reconnectAttempts = 0;
|
||||
this.setStatus('connected', 'Connected');
|
||||
};
|
||||
|
||||
this.ws.onmessage = (event) => {
|
||||
try {
|
||||
const data = JSON.parse(event.data);
|
||||
this.handleMessage(data);
|
||||
} catch (err) {
|
||||
console.error('Failed to parse message:', err);
|
||||
}
|
||||
};
|
||||
|
||||
this.ws.onerror = (error) => {
|
||||
console.error('WebSocket error:', error);
|
||||
this.setStatus('error', 'Connection error');
|
||||
};
|
||||
|
||||
this.ws.onclose = () => {
|
||||
console.log('Chat WebSocket disconnected');
|
||||
this.setStatus('disconnected', 'Disconnected');
|
||||
this.reconnect();
|
||||
};
|
||||
}
|
||||
|
||||
reconnect() {
|
||||
if (this.reconnectAttempts >= this.maxReconnectAttempts) {
|
||||
this.setStatus('error', 'Failed to connect');
|
||||
return;
|
||||
}
|
||||
|
||||
this.reconnectAttempts++;
|
||||
const delay = Math.min(1000 * Math.pow(2, this.reconnectAttempts), 30000);
|
||||
this.setStatus('connecting', 'Reconnecting...');
|
||||
|
||||
setTimeout(() => {
|
||||
console.log(`Reconnecting... (attempt ${this.reconnectAttempts})`);
|
||||
this.connect();
|
||||
}, delay);
|
||||
}
|
||||
|
||||
setStatus(state, text) {
|
||||
this.statusDot.className = 'status-dot ' + state;
|
||||
this.statusText.textContent = text;
|
||||
}
|
||||
|
||||
handleMessage(data) {
|
||||
switch (data.type) {
|
||||
case 'chat_message':
|
||||
this.addChatMessage(data.data);
|
||||
break;
|
||||
case 'chat_history':
|
||||
if (data.data && Array.isArray(data.data)) {
|
||||
// For both directions, add messages in order
|
||||
data.data.forEach(msg => this.addChatMessage(msg, false));
|
||||
|
||||
if (this.direction === 'down') {
|
||||
this.scrollToBottom();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'send_result':
|
||||
// Handle send message result
|
||||
if (data.success) {
|
||||
this.messageInput.value = '';
|
||||
this.charCount.textContent = '0';
|
||||
} else {
|
||||
this.showSendError(data.error || 'Failed to send message');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
addChatMessage(messageData, shouldAnimate = true) {
|
||||
const msgElement = this.createMessageElement(messageData);
|
||||
|
||||
if (!shouldAnimate) {
|
||||
msgElement.style.animation = 'none';
|
||||
}
|
||||
|
||||
// Apply filter
|
||||
if (this.currentFilter !== 'all') {
|
||||
const msgPlatform = messageData.platform;
|
||||
if (msgPlatform !== this.currentFilter) {
|
||||
msgElement.style.display = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
if (this.direction === 'up') {
|
||||
// Direction UP: newest at bottom (anchored), older messages bubble upward
|
||||
this.messagesContainer.insertBefore(msgElement, this.messagesContainer.firstChild);
|
||||
|
||||
// Limit total messages (remove oldest = last child)
|
||||
while (this.messagesContainer.children.length > this.maxMessages) {
|
||||
this.messagesContainer.removeChild(this.messagesContainer.lastChild);
|
||||
}
|
||||
} else {
|
||||
// Direction DOWN (default): newest at bottom, scroll down
|
||||
this.messagesContainer.appendChild(msgElement);
|
||||
|
||||
// Limit total messages (remove oldest = first child)
|
||||
while (this.messagesContainer.children.length > this.maxMessages) {
|
||||
this.messagesContainer.removeChild(this.messagesContainer.firstChild);
|
||||
}
|
||||
|
||||
if (this.autoScroll) {
|
||||
this.scrollToBottom();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
createMessageElement(data) {
|
||||
const msg = document.createElement('div');
|
||||
msg.className = `chat-message ${data.platform}`;
|
||||
msg.dataset.messageId = data.id;
|
||||
|
||||
if (data.is_action) {
|
||||
msg.classList.add('action');
|
||||
}
|
||||
|
||||
// Platform icon
|
||||
if (data.platform) {
|
||||
const iconDiv = document.createElement('div');
|
||||
iconDiv.className = 'platform-icon';
|
||||
iconDiv.innerHTML = this.platformIcons[data.platform] || '';
|
||||
msg.appendChild(iconDiv);
|
||||
}
|
||||
|
||||
// Message content
|
||||
const content = document.createElement('div');
|
||||
content.className = 'message-content';
|
||||
|
||||
// User info line
|
||||
const userInfo = document.createElement('div');
|
||||
userInfo.className = 'user-info';
|
||||
|
||||
// Badges
|
||||
if (data.user.badges && data.user.badges.length > 0) {
|
||||
const badgesContainer = document.createElement('div');
|
||||
badgesContainer.className = 'user-badges';
|
||||
|
||||
data.user.badges.forEach(badge => {
|
||||
const badgeEl = document.createElement('span');
|
||||
badgeEl.className = 'badge';
|
||||
badgeEl.title = badge.name;
|
||||
if (badge.icon_url) {
|
||||
badgeEl.innerHTML = `<img src="${badge.icon_url}" alt="${badge.name}">`;
|
||||
} else {
|
||||
badgeEl.textContent = badge.name.charAt(0).toUpperCase();
|
||||
}
|
||||
badgesContainer.appendChild(badgeEl);
|
||||
});
|
||||
|
||||
userInfo.appendChild(badgesContainer);
|
||||
}
|
||||
|
||||
// Username
|
||||
const username = document.createElement('span');
|
||||
username.className = 'username';
|
||||
username.textContent = data.user.display_name;
|
||||
if (data.user.color) {
|
||||
username.style.color = data.user.color;
|
||||
}
|
||||
userInfo.appendChild(username);
|
||||
|
||||
// Timestamp
|
||||
const timestamp = document.createElement('span');
|
||||
timestamp.className = 'timestamp';
|
||||
timestamp.textContent = this.formatTime(data.timestamp);
|
||||
userInfo.appendChild(timestamp);
|
||||
|
||||
content.appendChild(userInfo);
|
||||
|
||||
// Message text with emotes
|
||||
const messageText = document.createElement('div');
|
||||
messageText.className = 'message-text';
|
||||
messageText.innerHTML = this.parseMessageWithEmotes(data.message, data.emotes);
|
||||
content.appendChild(messageText);
|
||||
|
||||
msg.appendChild(content);
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
getEmoteUrl(emote) {
|
||||
if (!emote.emote_id) {
|
||||
return emote.url;
|
||||
}
|
||||
|
||||
const scale = this.emoteScale;
|
||||
const provider = emote.provider;
|
||||
|
||||
switch (provider) {
|
||||
case 'twitch':
|
||||
return `https://static-cdn.jtvnw.net/emoticons/v2/${emote.emote_id}/default/dark/${scale}.0`;
|
||||
case 'bttv':
|
||||
return `https://cdn.betterttv.net/emote/${emote.emote_id}/${scale}x`;
|
||||
case 'ffz':
|
||||
const ffzScale = scale === 2 ? 2 : 1;
|
||||
return emote.url.replace(/\/[124]$/, `/${ffzScale}`);
|
||||
case '7tv':
|
||||
return emote.url.replace(/\/[123]x\.webp$/, `/${scale}x.webp`);
|
||||
default:
|
||||
return emote.url;
|
||||
}
|
||||
}
|
||||
|
||||
parseMessageWithEmotes(message, emotes) {
|
||||
if (!emotes || emotes.length === 0) {
|
||||
return this.escapeHtml(message);
|
||||
}
|
||||
|
||||
const emoteMap = {};
|
||||
emotes.forEach(emote => {
|
||||
emoteMap[emote.code] = emote;
|
||||
});
|
||||
|
||||
const words = message.split(' ');
|
||||
const result = words.map(word => {
|
||||
if (emoteMap[word]) {
|
||||
const emote = emoteMap[word];
|
||||
const animatedClass = emote.is_animated ? 'animated' : '';
|
||||
const url = this.getEmoteUrl(emote);
|
||||
return `<img class="emote ${animatedClass}" src="${url}" alt="${emote.code}" title="${emote.code} (${emote.provider})">`;
|
||||
}
|
||||
return this.escapeHtml(word);
|
||||
});
|
||||
|
||||
return result.join(' ');
|
||||
}
|
||||
|
||||
escapeHtml(text) {
|
||||
const div = document.createElement('div');
|
||||
div.textContent = text;
|
||||
return div.innerHTML;
|
||||
}
|
||||
|
||||
formatTime(timestamp) {
|
||||
const date = new Date(timestamp);
|
||||
const hours = date.getHours().toString().padStart(2, '0');
|
||||
const minutes = date.getMinutes().toString().padStart(2, '0');
|
||||
return `${hours}:${minutes}`;
|
||||
}
|
||||
|
||||
scrollToBottom() {
|
||||
this.messagesContainer.scrollTop = this.messagesContainer.scrollHeight;
|
||||
}
|
||||
|
||||
async sendMessage() {
|
||||
const message = this.messageInput.value.trim();
|
||||
if (!message) return;
|
||||
|
||||
// Disable input while sending
|
||||
this.messageInput.disabled = true;
|
||||
this.sendButton.disabled = true;
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/chat/send', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
platform: this.sendPlatform,
|
||||
message: message,
|
||||
}),
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
this.messageInput.value = '';
|
||||
this.charCount.textContent = '0';
|
||||
} else {
|
||||
this.showSendError(result.error || 'Failed to send message');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Send error:', error);
|
||||
this.showSendError('Network error');
|
||||
} finally {
|
||||
this.messageInput.disabled = false;
|
||||
this.sendButton.disabled = false;
|
||||
this.messageInput.focus();
|
||||
}
|
||||
}
|
||||
|
||||
showSendError(error) {
|
||||
// Create error toast
|
||||
const toast = document.createElement('div');
|
||||
toast.className = 'error-toast';
|
||||
toast.textContent = error;
|
||||
document.body.appendChild(toast);
|
||||
|
||||
// Remove after 3 seconds
|
||||
setTimeout(() => {
|
||||
toast.classList.add('fade-out');
|
||||
setTimeout(() => toast.remove(), 300);
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
async checkAuthStatus() {
|
||||
const statusEl = document.getElementById('auth-status-text');
|
||||
const statusContainer = document.getElementById('auth-status');
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/auth/status');
|
||||
const data = await response.json();
|
||||
|
||||
const twitchAuth = data.twitch_authenticated;
|
||||
const youtubeAuth = data.youtube_authenticated;
|
||||
|
||||
if (twitchAuth && youtubeAuth) {
|
||||
statusEl.textContent = 'Both authenticated';
|
||||
statusContainer.className = 'authenticated';
|
||||
} else if (twitchAuth) {
|
||||
statusEl.textContent = 'Twitch only';
|
||||
statusContainer.className = 'authenticated';
|
||||
} else if (youtubeAuth) {
|
||||
statusEl.textContent = 'YouTube only';
|
||||
statusContainer.className = 'authenticated';
|
||||
} else {
|
||||
statusEl.textContent = 'Not authenticated';
|
||||
statusContainer.className = 'not-authenticated';
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to check auth status:', error);
|
||||
statusEl.textContent = 'Unknown';
|
||||
statusContainer.className = '';
|
||||
}
|
||||
}
|
||||
|
||||
async reconnectChat() {
|
||||
const btn = document.getElementById('reconnect-btn');
|
||||
const statusEl = document.getElementById('auth-status-text');
|
||||
|
||||
btn.disabled = true;
|
||||
btn.classList.add('spinning');
|
||||
statusEl.textContent = 'Reconnecting...';
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/chat/reconnect', {
|
||||
method: 'POST',
|
||||
});
|
||||
const data = await response.json();
|
||||
|
||||
if (data.success) {
|
||||
this.showToast('Chat reconnected!', 'success');
|
||||
// Re-check auth status
|
||||
await this.checkAuthStatus();
|
||||
} else {
|
||||
this.showToast(data.error || 'Failed to reconnect', 'error');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Reconnect error:', error);
|
||||
this.showToast('Network error', 'error');
|
||||
} finally {
|
||||
btn.disabled = false;
|
||||
btn.classList.remove('spinning');
|
||||
await this.checkAuthStatus();
|
||||
}
|
||||
}
|
||||
|
||||
showToast(message, type = 'info') {
|
||||
const toast = document.createElement('div');
|
||||
toast.className = `toast ${type}`;
|
||||
toast.textContent = message;
|
||||
document.body.appendChild(toast);
|
||||
|
||||
setTimeout(() => {
|
||||
toast.classList.add('fade-out');
|
||||
setTimeout(() => toast.remove(), 300);
|
||||
}, 3000);
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize when DOM is ready
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
new ChatDockWidget();
|
||||
});
|
||||
54
app/assets/web/widgets/chatdock/index.html
Normal file
54
app/assets/web/widgets/chatdock/index.html
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Chat Dock</title>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="chat-dock">
|
||||
<div id="chat-header">
|
||||
<div class="platform-tabs">
|
||||
<button id="tab-all" class="tab active" data-platform="all">All</button>
|
||||
<button id="tab-twitch" class="tab" data-platform="twitch">
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor"><path d="M11.571 4.714h1.715v5.143H11.57zm4.715 0H18v5.143h-1.714zM6 0L1.714 4.286v15.428h5.143V24l4.286-4.286h3.428L22.286 12V0zm14.571 11.143l-3.428 3.428h-3.429l-3 3v-3H6.857V1.714h13.714Z"/></svg>
|
||||
Twitch
|
||||
</button>
|
||||
<button id="tab-youtube" class="tab" data-platform="youtube">
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor"><path d="M23.498 6.186a3.016 3.016 0 0 0-2.122-2.136C19.505 3.545 12 3.545 12 3.545s-7.505 0-9.377.505A3.017 3.017 0 0 0 .502 6.186C0 8.07 0 12 0 12s0 3.93.502 5.814a3.016 3.016 0 0 0 2.122 2.136c1.871.505 9.376.505 9.376.505s7.505 0 9.377-.505a3.015 3.015 0 0 0 2.122-2.136C24 15.93 24 12 24 12s0-3.93-.502-5.814zM9.545 15.568V8.432L15.818 12l-6.273 3.568z"/></svg>
|
||||
YouTube
|
||||
</button>
|
||||
</div>
|
||||
<div id="connection-status">
|
||||
<span class="status-dot"></span>
|
||||
<span class="status-text">Connecting...</span>
|
||||
</div>
|
||||
</div>
|
||||
<div id="chat-messages"></div>
|
||||
<div id="chat-input-area">
|
||||
<div id="input-header">
|
||||
<div id="send-platform-indicator">
|
||||
<span id="send-platform-icon"></span>
|
||||
<span id="send-platform-name">Twitch</span>
|
||||
</div>
|
||||
<div id="auth-status">
|
||||
<span id="auth-status-text">Checking...</span>
|
||||
<button id="reconnect-btn" title="Reconnect chat (reload tokens)">
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor"><path d="M17.65 6.35A7.958 7.958 0 0012 4c-4.42 0-7.99 3.58-7.99 8s3.57 8 7.99 8c3.73 0 6.84-2.55 7.73-6h-2.08A5.99 5.99 0 0112 18c-3.31 0-6-2.69-6-6s2.69-6 6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z"/></svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div id="input-row">
|
||||
<input type="text" id="message-input" placeholder="Send a message..." maxlength="500" autocomplete="off">
|
||||
<button id="send-button" title="Send message">
|
||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M2.01 21L23 12 2.01 3 2 10l15 2-15 2z"/></svg>
|
||||
</button>
|
||||
</div>
|
||||
<div id="char-counter"><span id="char-count">0</span>/500</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
621
app/assets/web/widgets/chatdock/style.css
Normal file
621
app/assets/web/widgets/chatdock/style.css
Normal file
|
|
@ -0,0 +1,621 @@
|
|||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
:root {
|
||||
--bg-primary: #18181b;
|
||||
--bg-secondary: #1f1f23;
|
||||
--bg-tertiary: #26262c;
|
||||
--bg-hover: #323239;
|
||||
--text-primary: #efeff1;
|
||||
--text-secondary: #adadb8;
|
||||
--text-muted: #71717a;
|
||||
--border-color: #3d3d42;
|
||||
--accent-twitch: #9146ff;
|
||||
--accent-youtube: #ff0000;
|
||||
--success: #00c853;
|
||||
--error: #ff4444;
|
||||
--warning: #ffab00;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
background: var(--bg-primary);
|
||||
color: var(--text-primary);
|
||||
height: 100vh;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* Light Theme */
|
||||
body.theme-light {
|
||||
--bg-primary: #f5f5f5;
|
||||
--bg-secondary: #ffffff;
|
||||
--bg-tertiary: #e8e8e8;
|
||||
--bg-hover: #d4d4d4;
|
||||
--text-primary: #1a1a1a;
|
||||
--text-secondary: #4a4a4a;
|
||||
--text-muted: #888888;
|
||||
--border-color: #d0d0d0;
|
||||
}
|
||||
|
||||
body.theme-light .chat-message {
|
||||
background: rgba(255, 255, 255, 0.9);
|
||||
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
|
||||
}
|
||||
|
||||
body.theme-light .username {
|
||||
text-shadow: none;
|
||||
}
|
||||
|
||||
/* Font size options */
|
||||
body.font-small {
|
||||
--chat-font-size: 12px;
|
||||
--chat-username-size: 12px;
|
||||
--chat-badge-size: 14px;
|
||||
--chat-emote-size: 24px;
|
||||
}
|
||||
|
||||
body.font-medium {
|
||||
--chat-font-size: 14px;
|
||||
--chat-username-size: 14px;
|
||||
--chat-badge-size: 16px;
|
||||
--chat-emote-size: 32px;
|
||||
}
|
||||
|
||||
body.font-large {
|
||||
--chat-font-size: 18px;
|
||||
--chat-username-size: 18px;
|
||||
--chat-badge-size: 20px;
|
||||
--chat-emote-size: 44px;
|
||||
}
|
||||
|
||||
body.font-xlarge {
|
||||
--chat-font-size: 24px;
|
||||
--chat-username-size: 24px;
|
||||
--chat-badge-size: 26px;
|
||||
--chat-emote-size: 56px;
|
||||
}
|
||||
|
||||
/* Hide timestamp option */
|
||||
body.hide-time .timestamp {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#chat-dock {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
/* Header with tabs */
|
||||
#chat-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 8px 12px;
|
||||
background: var(--bg-secondary);
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.platform-tabs {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.tab {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 6px 12px;
|
||||
background: transparent;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
color: var(--text-secondary);
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: all 0.15s ease;
|
||||
}
|
||||
|
||||
.tab:hover {
|
||||
background: var(--bg-hover);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.tab.active {
|
||||
background: var(--bg-tertiary);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.tab svg {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
}
|
||||
|
||||
#tab-twitch.active {
|
||||
color: var(--accent-twitch);
|
||||
}
|
||||
|
||||
#tab-youtube.active {
|
||||
color: var(--accent-youtube);
|
||||
}
|
||||
|
||||
/* Connection status */
|
||||
#connection-status {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 12px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.status-dot {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
background: var(--text-muted);
|
||||
}
|
||||
|
||||
.status-dot.connected {
|
||||
background: var(--success);
|
||||
box-shadow: 0 0 6px var(--success);
|
||||
}
|
||||
|
||||
.status-dot.connecting {
|
||||
background: var(--warning);
|
||||
animation: pulse 1s infinite;
|
||||
}
|
||||
|
||||
.status-dot.disconnected,
|
||||
.status-dot.error {
|
||||
background: var(--error);
|
||||
}
|
||||
|
||||
@keyframes pulse {
|
||||
0%, 100% { opacity: 1; }
|
||||
50% { opacity: 0.5; }
|
||||
}
|
||||
|
||||
/* Chat messages area */
|
||||
#chat-messages {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
padding: 8px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
/* Direction UP: Messages anchor to bottom */
|
||||
body.direction-up #chat-messages {
|
||||
flex-direction: column-reverse;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
body.direction-up .chat-message {
|
||||
animation: slideUp 0.2s ease-out;
|
||||
}
|
||||
|
||||
@keyframes slideUp {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(20px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
/* Custom scrollbar */
|
||||
#chat-messages::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
|
||||
#chat-messages::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
#chat-messages::-webkit-scrollbar-thumb {
|
||||
background: var(--bg-hover);
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
#chat-messages::-webkit-scrollbar-thumb:hover {
|
||||
background: var(--border-color);
|
||||
}
|
||||
|
||||
/* Chat message */
|
||||
.chat-message {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 8px;
|
||||
padding: 6px 8px;
|
||||
background: var(--bg-secondary);
|
||||
border-radius: 6px;
|
||||
border-left: 3px solid transparent;
|
||||
animation: slideIn 0.2s ease-out;
|
||||
}
|
||||
|
||||
@keyframes slideIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(10px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
.chat-message.twitch {
|
||||
border-left-color: var(--accent-twitch);
|
||||
}
|
||||
|
||||
.chat-message.youtube {
|
||||
border-left-color: var(--accent-youtube);
|
||||
}
|
||||
|
||||
.chat-message.action {
|
||||
font-style: italic;
|
||||
background: rgba(100, 100, 100, 0.2);
|
||||
}
|
||||
|
||||
/* Platform icon */
|
||||
.platform-icon {
|
||||
flex-shrink: 0;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
.platform-icon svg {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
/* Message content */
|
||||
.message-content {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.user-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.user-badges {
|
||||
display: flex;
|
||||
gap: 3px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.badge {
|
||||
width: var(--chat-badge-size, 18px);
|
||||
height: var(--chat-badge-size, 18px);
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 10px;
|
||||
font-weight: bold;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.badge img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.username {
|
||||
font-weight: 600;
|
||||
font-size: var(--chat-username-size, 14px);
|
||||
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
|
||||
body.theme-light .username {
|
||||
text-shadow: none;
|
||||
}
|
||||
|
||||
.timestamp {
|
||||
font-size: calc(var(--chat-font-size, 14px) * 0.8);
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.message-text {
|
||||
font-size: var(--chat-font-size, 14px);
|
||||
line-height: 1.4;
|
||||
word-wrap: break-word;
|
||||
overflow-wrap: break-word;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
/* Emotes */
|
||||
.emote {
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
margin: 0 2px;
|
||||
height: var(--chat-emote-size, 28px);
|
||||
width: auto;
|
||||
max-width: calc(var(--chat-emote-size, 28px) * 3);
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
.emote.animated {
|
||||
image-rendering: auto;
|
||||
}
|
||||
|
||||
/* Input area */
|
||||
#chat-input-area {
|
||||
padding: 8px 12px 12px;
|
||||
background: var(--bg-secondary);
|
||||
border-top: 1px solid var(--border-color);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
#input-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
#auth-status {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 11px;
|
||||
color: var(--text-muted);
|
||||
padding: 4px 8px;
|
||||
background: var(--bg-tertiary);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
#auth-status.authenticated {
|
||||
color: var(--success);
|
||||
}
|
||||
|
||||
#auth-status.not-authenticated {
|
||||
color: var(--error);
|
||||
}
|
||||
|
||||
#auth-status-text {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
#reconnect-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
background: transparent;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
color: var(--text-secondary);
|
||||
cursor: pointer;
|
||||
transition: all 0.15s ease;
|
||||
}
|
||||
|
||||
#reconnect-btn:hover {
|
||||
background: var(--bg-hover);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
#reconnect-btn:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
#reconnect-btn.spinning svg {
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
from { transform: rotate(0deg); }
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
#send-platform-indicator {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 4px 10px;
|
||||
background: var(--bg-tertiary);
|
||||
border-radius: 4px;
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
color: var(--text-secondary);
|
||||
cursor: pointer;
|
||||
transition: all 0.15s ease;
|
||||
}
|
||||
|
||||
#send-platform-indicator:hover {
|
||||
background: var(--bg-hover);
|
||||
}
|
||||
|
||||
#send-platform-indicator.twitch {
|
||||
border: 1px solid var(--accent-twitch);
|
||||
color: var(--accent-twitch);
|
||||
}
|
||||
|
||||
#send-platform-indicator.youtube {
|
||||
border: 1px solid var(--accent-youtube);
|
||||
color: var(--accent-youtube);
|
||||
}
|
||||
|
||||
#send-platform-indicator.all {
|
||||
border: 1px solid var(--text-secondary);
|
||||
background: linear-gradient(135deg, rgba(145, 70, 255, 0.2), rgba(255, 0, 0, 0.2));
|
||||
}
|
||||
|
||||
.dual-icons {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.dual-icons svg {
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
}
|
||||
|
||||
#send-platform-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
#send-platform-icon svg {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
}
|
||||
|
||||
#input-row {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
#message-input {
|
||||
flex: 1;
|
||||
padding: 10px 14px;
|
||||
background: var(--bg-tertiary);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 6px;
|
||||
color: var(--text-primary);
|
||||
font-size: 14px;
|
||||
outline: none;
|
||||
transition: border-color 0.15s ease;
|
||||
}
|
||||
|
||||
#message-input::placeholder {
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
#message-input:focus {
|
||||
border-color: var(--accent-twitch);
|
||||
}
|
||||
|
||||
#message-input:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
#send-button {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 42px;
|
||||
height: 42px;
|
||||
background: var(--accent-twitch);
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
color: white;
|
||||
cursor: pointer;
|
||||
transition: all 0.15s ease;
|
||||
}
|
||||
|
||||
#send-button:hover {
|
||||
background: #7c3aed;
|
||||
transform: scale(1.05);
|
||||
}
|
||||
|
||||
#send-button:active {
|
||||
transform: scale(0.95);
|
||||
}
|
||||
|
||||
#send-button:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
transform: none;
|
||||
}
|
||||
|
||||
#send-button svg {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
}
|
||||
|
||||
#char-counter {
|
||||
margin-top: 4px;
|
||||
font-size: 11px;
|
||||
color: var(--text-muted);
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
/* Toasts */
|
||||
.error-toast,
|
||||
.toast {
|
||||
position: fixed;
|
||||
bottom: 80px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
padding: 10px 20px;
|
||||
background: var(--bg-tertiary);
|
||||
color: var(--text-primary);
|
||||
border-radius: 6px;
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
|
||||
z-index: 1000;
|
||||
animation: toastIn 0.3s ease;
|
||||
}
|
||||
|
||||
.error-toast,
|
||||
.toast.error {
|
||||
background: var(--error);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.toast.success {
|
||||
background: var(--success);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.error-toast.fade-out,
|
||||
.toast.fade-out {
|
||||
animation: toastOut 0.3s ease forwards;
|
||||
}
|
||||
|
||||
@keyframes toastIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateX(-50%) translateY(20px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateX(-50%) translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes toastOut {
|
||||
from {
|
||||
opacity: 1;
|
||||
transform: translateX(-50%) translateY(0);
|
||||
}
|
||||
to {
|
||||
opacity: 0;
|
||||
transform: translateX(-50%) translateY(20px);
|
||||
}
|
||||
}
|
||||
|
||||
/* Empty state */
|
||||
.status-message {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100%;
|
||||
color: var(--text-muted);
|
||||
font-size: 14px;
|
||||
text-align: center;
|
||||
padding: 20px;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue