From 35de17265ddbc7602ea8a4fdaea36ba30d37cb24 Mon Sep 17 00:00:00 2001 From: tobiichi3227 Date: Mon, 5 May 2025 14:08:19 +0800 Subject: [PATCH] Fix(fortune): unable to display result if already drawn for the day --- fortune_generator/js/fortune.js | 39 +++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/fortune_generator/js/fortune.js b/fortune_generator/js/fortune.js index 1532d59..be4b28b 100644 --- a/fortune_generator/js/fortune.js +++ b/fortune_generator/js/fortune.js @@ -353,12 +353,6 @@ async function init_page() { } } - 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++) { if (eventIndexList[eventIndex] != -1) { @@ -371,15 +365,6 @@ async function init_page() { } } - // show special event if today is a special day - if (special) { - const special_event_today = - `今日是${ - special_events[special_events_index].event - }`; - $("#special-day").html(special_event_today); - } - const last_date_str = localStorage.getItem("last_date"); if (last_date_str !== null && last_date_str !== undefined) { const now_date = new Date(); @@ -391,9 +376,31 @@ async function init_page() { now_date.getDate() === last_date.getDate() ) { fortune_generated = true; - Update(); } } + + if (fortune_generated) { + Update(); + if (special) { + special_events_index = parseInt(localStorage.getItem("last_special_index")); + } + } else { + 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]; + localStorage.setItem("last_special_index", special_events_index); + } + } + + // show special event if today is a special day + if (special) { + const special_event_today = + `今日是${ + special_events[special_events_index].event + }`; + $("#special-day").html(special_event_today); + } } }