diff --git a/assets/js/crt-logs.js b/assets/js/crt-logs.js index e7a57ff..51983a9 100644 --- a/assets/js/crt-logs.js +++ b/assets/js/crt-logs.js @@ -2,27 +2,27 @@ // This script updates the CRT screen with a mix of fake logs and real visitor stats function initCRTLogs() { - const crtScreen = document.getElementById('crt-logs'); + const crtScreen = document.getElementById("crt-logs"); if (!crtScreen) { return; } const fakeLogs = [ - '[WARN] High load detected - time for coffee break', - '[ERROR] 404: Motivation not found', - '[WARN] Firewall detected actual fire.', - '[ERROR] Keyboard not found. Press F1 to continue.', + "[WARN] High load detected - time for coffee break", + "[ERROR] 404: Motivation not found", + "[WARN] Firewall detected actual fire.", + "[ERROR] Keyboard not found. Press F1 to continue.", ]; function formatDate(dateStr) { const date = new Date(dateStr); - return date.toLocaleString('en-US', { - month: 'short', - day: 'numeric', - hour: '2-digit', - minute: '2-digit', - hour12: false + return date.toLocaleString("en-US", { + month: "short", + day: "numeric", + hour: "2-digit", + minute: "2-digit", + hour12: false, }); } @@ -30,7 +30,7 @@ function initCRTLogs() { const logs = []; // Add initial command - logs.push('> tail -f /var/log'); + logs.push("> tail -f /var/log"); // Mix fake logs with real stats const totalLogs = 10; @@ -42,9 +42,13 @@ function initCRTLogs() { if (statsPositions.includes(i) && stats) { // Insert real stats if (i === 3) { - logs.push(`[STATS] Total visitors: ${stats.totalHits.toLocaleString()}`); + logs.push( + `[STATS] Total visitors: ${stats.totalHits.toLocaleString()}`, + ); } 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) { logs.push(`[STATS] Last updated: ${formatDate(stats.lastUpdated)}`); } @@ -56,20 +60,27 @@ function initCRTLogs() { } // Animate logs appearing one by one - crtScreen.innerHTML = '> tail -f /var/log
\n_'; + crtScreen.innerHTML = + '> tail -f /var/log
\n_'; let currentIndex = 0; const lineDelay = 150; // milliseconds between each line 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 - crtScreen.innerHTML = logs[0] + '
\n' + displayedLogs.join('
\n') + '
\n_'; + crtScreen.innerHTML = + logs[0] + + "
\n" + + displayedLogs.join("
\n") + + '
\n_'; currentIndex++; setTimeout(addNextLine, lineDelay); } else { // Final update with cursor - crtScreen.innerHTML = logs.join('
\n') + '
\n_'; + crtScreen.innerHTML = + logs.join("
\n") + '
\n_'; } } @@ -77,19 +88,19 @@ function initCRTLogs() { } function fetchAnalyticsStats() { - fetch('https://api.ritual.sh/analytics/stats') - .then(response => { + fetch("https://api.ritual.sh/analytics/stats") + .then((response) => { if (!response.ok) { - throw new Error('Failed to fetch stats'); + throw new Error("Failed to fetch stats"); } return response.json(); }) - .then(stats => { + .then((stats) => { updateCRTScreen(stats); }) - .catch(err => { + .catch((err) => { // 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); }); } @@ -102,8 +113,8 @@ function initCRTLogs() { } // Wait for DOM to be ready -if (document.readyState === 'loading') { - document.addEventListener('DOMContentLoaded', initCRTLogs); +if (document.readyState === "loading") { + document.addEventListener("DOMContentLoaded", initCRTLogs); } else { // DOM already loaded initCRTLogs();