From 79965ea3a8425e38e8ec0e88fa5d2798f471540c Mon Sep 17 00:00:00 2001
From: tobiichi3227 <86729076+tobiichi3227@users.noreply.github.com>
Date: Mon, 5 May 2025 14:50:01 +0800
Subject: [PATCH] Fix(fortune): unable to display result if already drawn for
the day (#73)
---
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);
+ }
}
}