Files
RedditBot/public/index.html
T
2026-01-05 00:17:06 +00:00

759 lines
19 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Reddit Bot Dashboard</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
min-height: 100vh;
color: #e4e4e4;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 30px;
padding-bottom: 20px;
border-bottom: 1px solid #333;
}
h1 {
font-size: 28px;
color: #ff6b6b;
}
.status-badge {
padding: 8px 16px;
border-radius: 20px;
font-size: 14px;
font-weight: 600;
}
.status-running {
background: #2ecc71;
color: #fff;
}
.status-dry-run {
background: #f39c12;
color: #fff;
}
.status-stopped {
background: #e74c3c;
color: #fff;
}
.control-btn {
padding: 10px 24px;
border-radius: 8px;
font-size: 14px;
font-weight: 600;
border: none;
cursor: pointer;
transition: all 0.2s ease;
margin-left: 12px;
}
.control-btn.start {
background: linear-gradient(135deg, #2ecc71 0%, #27ae60 100%);
color: #fff;
}
.control-btn.start:hover {
background: linear-gradient(135deg, #27ae60 0%, #229954 100%);
transform: translateY(-1px);
}
.control-btn.stop {
background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
color: #fff;
}
.control-btn.stop:hover {
background: linear-gradient(135deg, #c0392b 0%, #a93226 100%);
transform: translateY(-1px);
}
.header-controls {
display: flex;
align-items: center;
gap: 8px;
}
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 20px;
margin-bottom: 30px;
}
.stat-card {
background: rgba(255, 255, 255, 0.05);
border-radius: 12px;
padding: 20px;
border: 1px solid rgba(255, 255, 255, 0.1);
}
.stat-card h3 {
font-size: 12px;
text-transform: uppercase;
color: #888;
margin-bottom: 8px;
}
.stat-card .value {
font-size: 32px;
font-weight: 700;
color: #fff;
}
.stat-card .subtext {
font-size: 12px;
color: #666;
margin-top: 4px;
}
.stat-card.highlight {
background: linear-gradient(135deg, #ff6b6b 0%, #ee5a5a 100%);
}
.stat-card.highlight h3,
.stat-card.highlight .subtext {
color: rgba(255, 255, 255, 0.8);
}
.panels {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
}
@media (max-width: 900px) {
.panels {
grid-template-columns: 1fr;
}
}
.panel {
background: rgba(255, 255, 255, 0.05);
border-radius: 12px;
border: 1px solid rgba(255, 255, 255, 0.1);
overflow: hidden;
}
.panel-header {
padding: 16px 20px;
background: rgba(0, 0, 0, 0.2);
font-weight: 600;
font-size: 14px;
text-transform: uppercase;
color: #aaa;
}
.panel-content {
padding: 0;
max-height: 400px;
overflow-y: auto;
}
.activity-item {
padding: 12px 20px;
border-bottom: 1px solid rgba(255, 255, 255, 0.05);
display: flex;
gap: 12px;
align-items: flex-start;
}
.activity-item:last-child {
border-bottom: none;
}
.activity-icon {
width: 32px;
height: 32px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 14px;
flex-shrink: 0;
}
.activity-icon.sent {
background: #2ecc71;
}
.activity-icon.skipped {
background: #95a5a6;
}
.activity-icon.response {
background: #9b59b6;
}
.activity-icon.error {
background: #e74c3c;
}
.activity-content {
flex: 1;
min-width: 0;
}
.activity-message {
font-size: 14px;
color: #ddd;
word-wrap: break-word;
}
.activity-time {
font-size: 11px;
color: #666;
margin-top: 4px;
}
.message-item {
padding: 16px 20px;
border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.message-item:last-child {
border-bottom: none;
}
.message-recipient {
font-weight: 600;
color: #ff6b6b;
font-size: 13px;
margin-bottom: 6px;
}
.message-text {
font-size: 14px;
color: #bbb;
line-height: 1.5;
}
.message-meta {
font-size: 11px;
color: #666;
margin-top: 8px;
display: flex;
gap: 12px;
}
.response-badge {
background: #9b59b6;
color: #fff;
padding: 2px 8px;
border-radius: 10px;
font-size: 10px;
}
.config-section {
margin-top: 30px;
}
.config-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 16px;
}
.config-item {
background: rgba(255, 255, 255, 0.05);
border-radius: 8px;
padding: 16px;
border: 1px solid rgba(255, 255, 255, 0.1);
}
.config-item h4 {
font-size: 12px;
color: #888;
text-transform: uppercase;
margin-bottom: 8px;
}
.config-item .value {
color: #fff;
font-size: 14px;
}
.tag {
display: inline-block;
background: rgba(255, 107, 107, 0.2);
color: #ff6b6b;
padding: 4px 10px;
border-radius: 12px;
font-size: 12px;
margin: 2px;
}
.empty-state {
padding: 40px;
text-align: center;
color: #666;
}
.chat-item {
padding: 14px 20px;
border-bottom: 1px solid rgba(255, 255, 255, 0.05);
display: flex;
gap: 12px;
align-items: flex-start;
}
.chat-item:last-child {
border-bottom: none;
}
.chat-item.unread {
background: rgba(155, 89, 182, 0.1);
}
.chat-avatar {
width: 40px;
height: 40px;
border-radius: 50%;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
display: flex;
align-items: center;
justify-content: center;
font-size: 16px;
font-weight: 600;
color: #fff;
flex-shrink: 0;
}
.chat-content {
flex: 1;
min-width: 0;
}
.chat-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 4px;
}
.chat-username {
font-weight: 600;
color: #ff6b6b;
font-size: 13px;
}
.chat-time {
font-size: 11px;
color: #666;
}
.chat-snippet {
font-size: 13px;
color: #999;
line-height: 1.4;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.chat-direction {
font-size: 10px;
color: #666;
margin-top: 4px;
}
.chat-direction.from-us {
color: #2ecc71;
}
.chat-direction.from-them {
color: #9b59b6;
}
.unread-badge {
background: #9b59b6;
color: #fff;
padding: 2px 8px;
border-radius: 10px;
font-size: 10px;
margin-left: 8px;
}
.refresh-btn {
background: rgba(255, 255, 255, 0.1);
border: 1px solid rgba(255, 255, 255, 0.2);
color: #aaa;
padding: 6px 12px;
border-radius: 6px;
font-size: 12px;
cursor: pointer;
transition: all 0.2s ease;
margin-left: auto;
}
.refresh-btn:hover {
background: rgba(255, 255, 255, 0.15);
color: #fff;
}
.panel-header-row {
display: flex;
align-items: center;
padding: 16px 20px;
background: rgba(0, 0, 0, 0.2);
}
.panel-header-row .panel-title {
font-weight: 600;
font-size: 14px;
text-transform: uppercase;
color: #aaa;
}
::-webkit-scrollbar {
width: 8px;
}
::-webkit-scrollbar-track {
background: rgba(0, 0, 0, 0.2);
}
::-webkit-scrollbar-thumb {
background: #444;
border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
background: #555;
}
</style>
</head>
<body>
<div class="container">
<header>
<h1>Reddit Bot Dashboard</h1>
<div class="header-controls">
<span class="status-badge status-running" id="running-badge" style="display: none;">Running</span>
<span class="status-badge status-stopped" id="stopped-badge">Stopped</span>
<span class="status-badge status-dry-run" id="dryrun-badge" style="display: none;">Dry Run</span>
<button class="control-btn start" id="control-btn" onclick="toggleBot()">Start Bot</button>
</div>
</header>
<div class="stats-grid">
<div class="stat-card highlight">
<h3>Messages Sent</h3>
<div class="value" id="stat-sent">0</div>
<div class="subtext"><span id="stat-hour">0</span> / <span id="stat-max-hour">8</span> this hour</div>
</div>
<div class="stat-card">
<h3>Responses</h3>
<div class="value" id="stat-responses">0</div>
<div class="subtext"><span id="stat-rate">0</span>% response rate</div>
</div>
<div class="stat-card">
<h3>Posts Processed</h3>
<div class="value" id="stat-processed">0</div>
<div class="subtext">Total analyzed</div>
</div>
<div class="stat-card">
<h3>Success Examples</h3>
<div class="value" id="stat-examples">0</div>
<div class="subtext">Learning from responses</div>
</div>
</div>
<div class="panels">
<div class="panel">
<div class="panel-header">Recent Activity</div>
<div class="panel-content" id="activity-list">
<div class="empty-state">No activity yet</div>
</div>
</div>
<div class="panel">
<div class="panel-header">Recent Messages</div>
<div class="panel-content" id="messages-list">
<div class="empty-state">No messages sent yet</div>
</div>
</div>
</div>
<div class="panels" style="margin-top: 20px;">
<div class="panel" style="grid-column: span 2;">
<div class="panel-header-row">
<span class="panel-title">Active Chats (Last 48 Hours)</span>
<button class="refresh-btn" onclick="fetchChats()" id="refresh-chats-btn">🔄 Refresh</button>
</div>
<div class="panel-content" id="chats-list" style="max-height: 500px;">
<div class="empty-state">Loading chats...</div>
</div>
</div>
</div>
<div class="config-section">
<div class="config-grid">
<div class="config-item">
<h4>Monitoring Subreddits</h4>
<div class="value" id="config-subreddits"></div>
</div>
<div class="config-item">
<h4>Target Genders</h4>
<div class="value" id="config-genders"></div>
</div>
</div>
</div>
</div>
<script>
function formatTime(timestamp) {
const date = new Date(timestamp);
const now = new Date();
const diff = now - date;
if (diff < 60000) return 'Just now';
if (diff < 3600000) return Math.floor(diff / 60000) + 'm ago';
if (diff < 86400000) return Math.floor(diff / 3600000) + 'h ago';
return date.toLocaleDateString();
}
function getActivityIcon(type) {
const icons = {
sent: '✉️',
skipped: '⏭️',
response: '💬',
error: '❌'
};
return icons[type] || '📌';
}
async function fetchStats() {
try {
const res = await fetch('/api/stats');
const stats = await res.json();
document.getElementById('stat-sent').textContent = stats.totalMessagesSent;
document.getElementById('stat-hour').textContent = stats.messagesThisHour;
document.getElementById('stat-max-hour').textContent = stats.maxMessagesPerHour;
document.getElementById('stat-responses').textContent = stats.totalResponses;
document.getElementById('stat-rate').textContent = stats.responseRate;
document.getElementById('stat-processed').textContent = stats.totalProcessed;
document.getElementById('dryrun-badge').style.display = stats.dryRunMode ? 'inline' : 'none';
// Update running state
const runningBadge = document.getElementById('running-badge');
const stoppedBadge = document.getElementById('stopped-badge');
const controlBtn = document.getElementById('control-btn');
if (stats.isRunning) {
runningBadge.style.display = 'inline';
stoppedBadge.style.display = 'none';
controlBtn.textContent = 'Stop Bot';
controlBtn.className = 'control-btn stop';
} else {
runningBadge.style.display = 'none';
stoppedBadge.style.display = 'inline';
controlBtn.textContent = 'Start Bot';
controlBtn.className = 'control-btn start';
}
document.getElementById('config-subreddits').innerHTML = stats.subreddits
.map(s => `<span class="tag">r/${s}</span>`).join('');
document.getElementById('config-genders').innerHTML = stats.targetGenders
.map(g => `<span class="tag">${g}</span>`).join('');
} catch (err) {
console.error('Failed to fetch stats:', err);
}
}
async function fetchActivity() {
try {
const res = await fetch('/api/activity');
const activity = await res.json();
const container = document.getElementById('activity-list');
if (activity.length === 0) {
container.innerHTML = '<div class="empty-state">No activity yet</div>';
return;
}
container.innerHTML = activity.map(item => `
<div class="activity-item">
<div class="activity-icon ${item.type}">${getActivityIcon(item.type)}</div>
<div class="activity-content">
<div class="activity-message">${escapeHtml(item.message)}</div>
<div class="activity-time">${formatTime(item.timestamp)}</div>
</div>
</div>
`).join('');
} catch (err) {
console.error('Failed to fetch activity:', err);
}
}
async function fetchMessages() {
try {
const res = await fetch('/api/messages');
const messages = await res.json();
const container = document.getElementById('messages-list');
if (messages.length === 0) {
container.innerHTML = '<div class="empty-state">No messages sent yet</div>';
return;
}
container.innerHTML = messages.map(msg => {
// Construct Reddit URL
// If we have subreddit, make a nice link. If not, fallback to shortlink.
const postUrl = msg.subreddit
? `https://www.reddit.com/r/${escapeHtml(msg.subreddit)}/comments/${escapeHtml(msg.postId)}`
: `https://redd.it/${escapeHtml(msg.postId)}`;
const sourceLabel = msg.subreddit ? `r/${escapeHtml(msg.subreddit)}` : 'Post';
return `
<div class="message-item">
<div class="message-recipient">
u/${escapeHtml(msg.recipient)}
${msg.gotResponse ? '<span class="response-badge">Got Response!</span>' : ''}
<a href="${postUrl}" target="_blank" style="float: right; color: #888; font-size: 11px; text-decoration: none; border: 1px solid #444; padding: 2px 6px; border-radius: 4px;">
${sourceLabel} ↗
</a>
</div>
<div class="message-text">${escapeHtml(msg.message)}</div>
<div class="message-meta">
<span>${formatTime(msg.sentAt)}</span>
</div>
</div>
`}).join('');
} catch (err) {
console.error('Failed to fetch messages:', err);
}
}
async function fetchSuccessful() {
try {
const res = await fetch('/api/successful');
const successful = await res.json();
document.getElementById('stat-examples').textContent = successful.length;
} catch (err) {
console.error('Failed to fetch successful:', err);
}
}
function escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
async function toggleBot() {
const controlBtn = document.getElementById('control-btn');
const isCurrentlyRunning = controlBtn.classList.contains('stop');
try {
const endpoint = isCurrentlyRunning ? '/api/stop' : '/api/start';
const res = await fetch(endpoint, { method: 'POST' });
const result = await res.json();
if (result.success) {
// Immediately refresh stats to update UI
fetchStats();
}
} catch (err) {
console.error('Failed to toggle bot:', err);
}
}
async function fetchChats() {
const container = document.getElementById('chats-list');
const refreshBtn = document.getElementById('refresh-chats-btn');
try {
if (refreshBtn) {
refreshBtn.disabled = true;
refreshBtn.textContent = '⏳ Loading...';
}
const res = await fetch('/api/chats');
const chats = await res.json();
if (chats.length === 0) {
container.innerHTML = '<div class="empty-state">No active chats in the last 48 hours</div>';
return;
}
container.innerHTML = chats.map(chat => {
const chatUrl = chat.url || 'https://chat.reddit.com';
return `
<div class="chat-item ${chat.unread ? 'unread' : ''}">
<div class="chat-avatar">${chat.username.charAt(0).toUpperCase()}</div>
<div class="chat-content">
<div class="chat-header">
<a href="${chatUrl}" target="_blank" class="chat-username" style="text-decoration: none; cursor: pointer;">
u/${escapeHtml(chat.username)} ↗
${chat.unread ? '<span class="unread-badge">Unread</span>' : ''}
</a>
<span class="chat-time">${formatTime(chat.lastMessageTime)}</span>
</div>
<div class="chat-snippet">${escapeHtml(chat.lastMessageSnippet || '(No message preview)')}</div>
<div class="chat-direction ${chat.isFromUs ? 'from-us' : 'from-them'}">
${chat.isFromUs ? '↗ You sent' : '↙ They replied'}
</div>
</div>
</div>
`}).join('');
} catch (err) {
console.error('Failed to fetch chats:', err);
container.innerHTML = '<div class="empty-state">Failed to load chats</div>';
} finally {
if (refreshBtn) {
refreshBtn.disabled = false;
refreshBtn.textContent = '🔄 Refresh';
}
}
}
// Initial fetch
fetchStats();
fetchActivity();
fetchMessages();
fetchSuccessful();
fetchChats();
// Poll for updates (chats not polled - use manual refresh)
setInterval(() => {
fetchStats();
fetchActivity();
fetchMessages();
fetchSuccessful();
}, 5000);
</script>
</body>
</html>