done
This commit is contained in:
220
public/admin.html
Normal file
220
public/admin.html
Normal file
@@ -0,0 +1,220 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Admin - Global Counter</title>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Outfit:wght@300;500;700&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<style>
|
||||
.admin-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr;
|
||||
gap: 2rem;
|
||||
width: 100%;
|
||||
max-width: 900px;
|
||||
}
|
||||
|
||||
@media(min-width: 768px) {
|
||||
.admin-grid {
|
||||
grid-template-columns: 1fr 2fr;
|
||||
}
|
||||
}
|
||||
|
||||
.stat-card {
|
||||
background: white;
|
||||
padding: 2rem;
|
||||
border-radius: 20px;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.recent-activity {
|
||||
background: white;
|
||||
padding: 2rem;
|
||||
border-radius: 20px;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
|
||||
max-height: 500px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.activity-header {
|
||||
font-size: 1.2rem;
|
||||
font-weight: 700;
|
||||
margin-bottom: 1rem;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.log-item {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 1rem;
|
||||
padding: 1rem 0;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
animation: fadeIn 0.3s ease;
|
||||
}
|
||||
|
||||
.log-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.avatar {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 50%;
|
||||
background: #eee;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-weight: 700;
|
||||
color: #888;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
|
||||
.log-content {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.log-name {
|
||||
font-weight: 600;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.log-time {
|
||||
font-size: 0.8rem;
|
||||
color: #999;
|
||||
margin-left: 0.5rem;
|
||||
}
|
||||
|
||||
.log-quote {
|
||||
font-size: 0.95rem;
|
||||
color: #555;
|
||||
margin-top: 0.2rem;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
@keyframes fadeIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(10px);
|
||||
}
|
||||
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="app-container" style="max-width: 1000px;">
|
||||
<header>
|
||||
<div class="logo">🔒 Admin Dashboard</div>
|
||||
<a href="/" class="admin-link">Back to Counter</a>
|
||||
</header>
|
||||
|
||||
<main class="admin-grid">
|
||||
<!-- Stats -->
|
||||
<div class="stat-card">
|
||||
<h1 id="admin-count">...</h1>
|
||||
<p class="label">Total Clicks</p>
|
||||
</div>
|
||||
|
||||
<!-- Logs -->
|
||||
<div class="recent-activity">
|
||||
<div class="activity-header">Recent Activity</div>
|
||||
<div id="logs-container">
|
||||
<p style="text-align: center; color: #999;">Waiting for data...</p>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<script src="/socket.io/socket.io.js"></script>
|
||||
<script>
|
||||
const socket = io();
|
||||
const logsContainer = document.getElementById('logs-container');
|
||||
const adminCount = document.getElementById('admin-count');
|
||||
|
||||
socket.on('connect', () => {
|
||||
socket.emit('join_admin');
|
||||
});
|
||||
|
||||
socket.on('update', (data) => {
|
||||
adminCount.innerText = data.count;
|
||||
});
|
||||
|
||||
socket.on('admin_data', (data) => {
|
||||
renderLogs(data.logs);
|
||||
});
|
||||
|
||||
socket.on('new_log', (log) => {
|
||||
prependLog(log);
|
||||
});
|
||||
|
||||
function renderLogs(logs) {
|
||||
logsContainer.innerHTML = '';
|
||||
logs.forEach(log => {
|
||||
logsContainer.appendChild(createLogElement(log));
|
||||
});
|
||||
}
|
||||
|
||||
function prependLog(log) {
|
||||
const firstChild = logsContainer.firstChild;
|
||||
const logEl = createLogElement(log);
|
||||
if (logsContainer.children.length === 0 || logsContainer.innerHTML.includes('Waiting')) {
|
||||
logsContainer.innerHTML = '';
|
||||
logsContainer.appendChild(logEl);
|
||||
} else {
|
||||
logsContainer.insertBefore(logEl, logsContainer.firstChild);
|
||||
}
|
||||
}
|
||||
|
||||
function createLogElement(log) {
|
||||
const div = document.createElement('div');
|
||||
div.className = 'log-item';
|
||||
|
||||
const initial = log.name ? log.name.charAt(0).toUpperCase() : '?';
|
||||
const timeAgo = new Date(log.timestamp).toLocaleTimeString();
|
||||
|
||||
div.innerHTML = `
|
||||
<div class="avatar" style="background-color: ${stringToColor(log.name)}20; color: ${stringToColor(log.name)}">${initial}</div>
|
||||
<div class="log-content">
|
||||
<div>
|
||||
<span class="log-name">${escapeHtml(log.name)}</span>
|
||||
<span class="log-time">${timeAgo}</span>
|
||||
</div>
|
||||
${log.quote ? `<div class="log-quote">"${escapeHtml(log.quote)}"</div>` : ''}
|
||||
</div>
|
||||
`;
|
||||
return div;
|
||||
}
|
||||
|
||||
function escapeHtml(text) {
|
||||
if (!text) return "";
|
||||
return text
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """)
|
||||
.replace(/'/g, "'");
|
||||
}
|
||||
|
||||
function stringToColor(str) {
|
||||
let hash = 0;
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
hash = str.charCodeAt(i) + ((hash << 5) - hash);
|
||||
}
|
||||
const c = (hash & 0x00FFFFFF).toString(16).toUpperCase();
|
||||
return '#' + "00000".substring(0, 6 - c.length) + c;
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user