From 230f08fab8ba2c303618b0cdfb910d0d4537fc80 Mon Sep 17 00:00:00 2001 From: erik Date: Thu, 26 Feb 2026 09:14:56 +0000 Subject: [PATCH] Replace magic numbers with named constants Add POLL_RARES_MS, POLL_KILLS_MS, POLL_HEALTH_MS, NOTIFICATION_DURATION_MS, GLOW_DURATION_MS, MAX_HEATMAP_POINTS, and HEATMAP_HOURS constants to replace hardcoded values throughout script.js for better maintainability. Co-Authored-By: Claude Opus 4.6 --- static/script.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/static/script.js b/static/script.js index 2bb2948b..265ba76c 100644 --- a/static/script.js +++ b/static/script.js @@ -302,6 +302,13 @@ const inventoryWindows = {}; const MAX_Z = 20; const FOCUS_ZOOM = 3; // zoom level when you click a name const POLL_MS = 2000; +const POLL_RARES_MS = 300000; // 5 minutes +const POLL_KILLS_MS = 300000; // 5 minutes +const POLL_HEALTH_MS = 30000; // 30 seconds +const NOTIFICATION_DURATION_MS = 6000; // Rare notification display time +const GLOW_DURATION_MS = 5000; // Player glow after rare find +const MAX_HEATMAP_POINTS = 50000; +const HEATMAP_HOURS = 24; // UtilityBelt's more accurate coordinate bounds const MAP_BOUNDS = { west: -102.1, @@ -557,7 +564,7 @@ function initHeatMap() { async function fetchHeatmapData() { try { - const response = await fetch(`${API_BASE}/spawns/heatmap?hours=24&limit=50000`); + const response = await fetch(`${API_BASE}/spawns/heatmap?hours=${HEATMAP_HOURS}&limit=${MAX_HEATMAP_POINTS}`); if (!response.ok) { throw new Error(`Heat map API error: ${response.status}`); } @@ -1448,12 +1455,9 @@ function startPolling() { pollTotalKills(); // Initial fetch pollServerHealth(); // Initial server health check pollID = setInterval(pollLive, POLL_MS); - // Poll total rares every 5 minutes (300,000 ms) - setInterval(pollTotalRares, 300000); - // Poll total kills every 5 minutes (300,000 ms) - setInterval(pollTotalKills, 300000); - // Poll server health every 30 seconds (30,000 ms) - setInterval(pollServerHealth, 30000); + setInterval(pollTotalRares, POLL_RARES_MS); + setInterval(pollTotalKills, POLL_KILLS_MS); + setInterval(pollServerHealth, POLL_HEALTH_MS); } img.onload = () => { @@ -2063,14 +2067,14 @@ function processNotificationQueue() { container.appendChild(notifEl); - // Remove notification after 6 seconds and process next + // Remove notification after display duration and process next setTimeout(() => { notifEl.style.animation = 'notification-slide-out 0.5s ease-in forwards'; setTimeout(() => { notifEl.remove(); processNotificationQueue(); }, 500); - }, 6000); + }, NOTIFICATION_DURATION_MS); } // Add slide out animation @@ -2146,10 +2150,10 @@ function highlightRareFinder(characterName) { const nameSpan = item.querySelector('.player-name'); if (nameSpan && nameSpan.textContent.includes(characterName)) { item.classList.add('rare-finder-glow'); - // Remove glow after 5 seconds + // Remove glow after duration setTimeout(() => { item.classList.remove('rare-finder-glow'); - }, 5000); + }, GLOW_DURATION_MS); } }); }