Skip to content

Commit 8aa76fb

Browse files
committed
Update MyCountdowns.js
1 parent a09c8bc commit 8aa76fb

2 files changed

Lines changed: 332 additions & 79 deletions

File tree

Countdown Widget/MyCountdowns.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
// icon-color: brown; icon-glyph: calendar-check;
21
// Variables used by Scriptable.
32
// These must be at the very top of the file. Do not edit.
3+
// icon-color: deep-green; icon-glyph: clock;
44

55
// === CONFIG ===
6-
const SHEET_API_URL = ""; // YOUR API URL here
6+
const SHEET_API_URL = "https://script.google.com/macros/s/..../exec"; // YOUR API URL here
77
const colorPalette = ["#CB2443", "#8e44ad", "#2980b9", "#F79F39", "#CEA834", "#7b9a50"];
88

99
// === Fetch Data from Google Sheets Web App (instead of local JSON) ===
@@ -72,14 +72,19 @@ await fm.downloadFileFromiCloud(fontPath);
7272
const roboto = (size) => new Font(fontPath, size);
7373

7474
// === Load Repeat Icon ===
75-
const repeatPath = fm.joinPath(fm.joinPath(fm.documentsDirectory(), ".assets"), "repeat_icon.png");
75+
const repeatPath = fm.joinPath(fm.joinPath(fm.documentsDirectory(), ".source"), "repeat_icon.png");
7676
await fm.downloadFileFromiCloud(repeatPath);
7777
const repeatIcon = fm.readImage(repeatPath);
7878

7979

8080
// === Parameter Handling for Small Widget ===
8181
const param = args.widgetParameter ? args.widgetParameter.trim().toLowerCase() : null;
82-
let selectedEvent = events[0]; // default: soonest event
82+
// Find the most recent upcoming event (soonest event)
83+
let selectedEvent = events.reduce((closest, event) => {
84+
const daysToEvent = daysUntil(event.date);
85+
const daysToClosest = daysUntil(closest.date);
86+
return daysToEvent < daysToClosest ? event : closest;
87+
}, events[0]);
8388
let showAgeMode = false; // default off
8489
let page = 1; // default page
8590

0 commit comments

Comments
 (0)