From f9f0f9c1a4c6bd2207ff884a63c6fd2fbda04f33 Mon Sep 17 00:00:00 2001 From: tobiichi3227 <86729076+tobiichi3227@users.noreply.github.com> Date: Sun, 9 Mar 2025 16:43:39 +0800 Subject: [PATCH 1/2] Fix(fortune): Copy preview url without commit hash (#66) --- fortune_generator/js/fortune.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fortune_generator/js/fortune.js b/fortune_generator/js/fortune.js index b74af1b..5d10b3e 100644 --- a/fortune_generator/js/fortune.js +++ b/fortune_generator/js/fortune.js @@ -27,10 +27,10 @@ let special_events = []; let commit_hash = ""; // using async and await to prevent fetching the data too late... -async function fetch_data(commit_hash) { +async function fetch_data(requied_commit_hash) { let prefix = ""; - if (commit_hash) { - prefix = `https://raw.githubusercontent.com/LifeAdventurer/generators/${commit_hash}/fortune_generator/`; + if (requied_commit_hash) { + prefix = `https://raw.githubusercontent.com/LifeAdventurer/generators/${requied_commit_hash}/fortune_generator/`; } await fetch(`${prefix}./json/fortune.json`) .then((response) => response.json()) -- 2.49.1 From 281b7cd37b2a94875342335702667eda5a1ab51c Mon Sep 17 00:00:00 2001 From: tobiichi3227 <86729076+tobiichi3227@users.noreply.github.com> Date: Sun, 9 Mar 2025 16:56:51 +0800 Subject: [PATCH 2/2] Fix(Fortune): special_events_index is undefined when there are no special events today. --- 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 b74af1b..af6eb1b 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++) { -- 2.49.1