From c80c879af161deeeb817344db45f789ef2d8a9a0 Mon Sep 17 00:00:00 2001 From: tobiichi3227 <86729076+tobiichi3227@users.noreply.github.com> Date: Sun, 9 Mar 2025 17:00:44 +0800 Subject: [PATCH] Fix(fortune): special_events_index is undefined when there are no special events today (#67) --- fortune_generator/js/fortune.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/fortune_generator/js/fortune.js b/fortune_generator/js/fortune.js index 5d10b3e..1532d59 100644 --- a/fortune_generator/js/fortune.js +++ b/fortune_generator/js/fortune.js @@ -353,9 +353,11 @@ async function init_page() { } } - special_events_index = ip.split(".").map(num => parseInt(num)).reduce((acc, cur) => acc + cur); - special_events_index %= current_day_special_events.length; - special_events_index = current_day_special_events[special_events_index]; + if (current_day_special_events.length) { + special_events_index = ip.split(".").map(num => parseInt(num)).reduce((acc, cur) => acc + cur); + special_events_index %= current_day_special_events.length; + special_events_index = current_day_special_events[special_events_index]; + } // if there is upcoming event then show for (let eventIndex = 0; eventIndex < showSpecialEventCount; eventIndex++) {