Clarifying stat
This commit is contained in:
parent
64ded17562
commit
73d5b77723
1 changed files with 37 additions and 26 deletions
|
|
@ -2,27 +2,27 @@
|
||||||
// This script updates the CRT screen with a mix of fake logs and real visitor stats
|
// This script updates the CRT screen with a mix of fake logs and real visitor stats
|
||||||
|
|
||||||
function initCRTLogs() {
|
function initCRTLogs() {
|
||||||
const crtScreen = document.getElementById('crt-logs');
|
const crtScreen = document.getElementById("crt-logs");
|
||||||
|
|
||||||
if (!crtScreen) {
|
if (!crtScreen) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const fakeLogs = [
|
const fakeLogs = [
|
||||||
'[WARN] High load detected - time for coffee break',
|
"[WARN] High load detected - time for coffee break",
|
||||||
'[ERROR] 404: Motivation not found',
|
"[ERROR] 404: Motivation not found",
|
||||||
'[WARN] Firewall detected actual fire.',
|
"[WARN] Firewall detected actual fire.",
|
||||||
'[ERROR] Keyboard not found. Press F1 to continue.',
|
"[ERROR] Keyboard not found. Press F1 to continue.",
|
||||||
];
|
];
|
||||||
|
|
||||||
function formatDate(dateStr) {
|
function formatDate(dateStr) {
|
||||||
const date = new Date(dateStr);
|
const date = new Date(dateStr);
|
||||||
return date.toLocaleString('en-US', {
|
return date.toLocaleString("en-US", {
|
||||||
month: 'short',
|
month: "short",
|
||||||
day: 'numeric',
|
day: "numeric",
|
||||||
hour: '2-digit',
|
hour: "2-digit",
|
||||||
minute: '2-digit',
|
minute: "2-digit",
|
||||||
hour12: false
|
hour12: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -30,7 +30,7 @@ function initCRTLogs() {
|
||||||
const logs = [];
|
const logs = [];
|
||||||
|
|
||||||
// Add initial command
|
// Add initial command
|
||||||
logs.push('> tail -f /var/log');
|
logs.push("> tail -f /var/log");
|
||||||
|
|
||||||
// Mix fake logs with real stats
|
// Mix fake logs with real stats
|
||||||
const totalLogs = 10;
|
const totalLogs = 10;
|
||||||
|
|
@ -42,9 +42,13 @@ function initCRTLogs() {
|
||||||
if (statsPositions.includes(i) && stats) {
|
if (statsPositions.includes(i) && stats) {
|
||||||
// Insert real stats
|
// Insert real stats
|
||||||
if (i === 3) {
|
if (i === 3) {
|
||||||
logs.push(`[STATS] Total visitors: ${stats.totalHits.toLocaleString()}`);
|
logs.push(
|
||||||
|
`[STATS] Total visitors: ${stats.totalHits.toLocaleString()}`,
|
||||||
|
);
|
||||||
} else if (i === 6) {
|
} else if (i === 6) {
|
||||||
logs.push(`[STATS] Unique visitors: ${stats.uniqueVisitors.toLocaleString()}`);
|
logs.push(
|
||||||
|
`[STATS] Unique vistors 24 hrs: ${stats.uniqueVisitors.toLocaleString()}`,
|
||||||
|
);
|
||||||
} else if (i === 9 && stats.lastUpdated) {
|
} else if (i === 9 && stats.lastUpdated) {
|
||||||
logs.push(`[STATS] Last updated: ${formatDate(stats.lastUpdated)}`);
|
logs.push(`[STATS] Last updated: ${formatDate(stats.lastUpdated)}`);
|
||||||
}
|
}
|
||||||
|
|
@ -56,20 +60,27 @@ function initCRTLogs() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Animate logs appearing one by one
|
// Animate logs appearing one by one
|
||||||
crtScreen.innerHTML = '> tail -f /var/log<br>\n<span class="cursor-blink">_</span>';
|
crtScreen.innerHTML =
|
||||||
|
'> tail -f /var/log<br>\n<span class="cursor-blink">_</span>';
|
||||||
|
|
||||||
let currentIndex = 0;
|
let currentIndex = 0;
|
||||||
const lineDelay = 150; // milliseconds between each line
|
const lineDelay = 150; // milliseconds between each line
|
||||||
|
|
||||||
function addNextLine() {
|
function addNextLine() {
|
||||||
if (currentIndex < logs.length - 1) { // -1 to skip the initial command we already added
|
if (currentIndex < logs.length - 1) {
|
||||||
|
// -1 to skip the initial command we already added
|
||||||
const displayedLogs = logs.slice(1, currentIndex + 2); // Skip initial command, add lines progressively
|
const displayedLogs = logs.slice(1, currentIndex + 2); // Skip initial command, add lines progressively
|
||||||
crtScreen.innerHTML = logs[0] + '<br>\n' + displayedLogs.join('<br>\n') + '<br>\n<span class="cursor-blink">_</span>';
|
crtScreen.innerHTML =
|
||||||
|
logs[0] +
|
||||||
|
"<br>\n" +
|
||||||
|
displayedLogs.join("<br>\n") +
|
||||||
|
'<br>\n<span class="cursor-blink">_</span>';
|
||||||
currentIndex++;
|
currentIndex++;
|
||||||
setTimeout(addNextLine, lineDelay);
|
setTimeout(addNextLine, lineDelay);
|
||||||
} else {
|
} else {
|
||||||
// Final update with cursor
|
// Final update with cursor
|
||||||
crtScreen.innerHTML = logs.join('<br>\n') + '<br>\n<span class="cursor-blink">_</span>';
|
crtScreen.innerHTML =
|
||||||
|
logs.join("<br>\n") + '<br>\n<span class="cursor-blink">_</span>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,19 +88,19 @@ function initCRTLogs() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetchAnalyticsStats() {
|
function fetchAnalyticsStats() {
|
||||||
fetch('https://api.ritual.sh/analytics/stats')
|
fetch("https://api.ritual.sh/analytics/stats")
|
||||||
.then(response => {
|
.then((response) => {
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error('Failed to fetch stats');
|
throw new Error("Failed to fetch stats");
|
||||||
}
|
}
|
||||||
return response.json();
|
return response.json();
|
||||||
})
|
})
|
||||||
.then(stats => {
|
.then((stats) => {
|
||||||
updateCRTScreen(stats);
|
updateCRTScreen(stats);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch((err) => {
|
||||||
// Silently fail and show fake logs only
|
// Silently fail and show fake logs only
|
||||||
console.debug('Failed to load analytics stats:', err);
|
console.debug("Failed to load analytics stats:", err);
|
||||||
updateCRTScreen(null);
|
updateCRTScreen(null);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -102,8 +113,8 @@ function initCRTLogs() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for DOM to be ready
|
// Wait for DOM to be ready
|
||||||
if (document.readyState === 'loading') {
|
if (document.readyState === "loading") {
|
||||||
document.addEventListener('DOMContentLoaded', initCRTLogs);
|
document.addEventListener("DOMContentLoaded", initCRTLogs);
|
||||||
} else {
|
} else {
|
||||||
// DOM already loaded
|
// DOM already loaded
|
||||||
initCRTLogs();
|
initCRTLogs();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue