-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidget_journal-prompt.js
49 lines (39 loc) · 1.8 KB
/
widget_journal-prompt.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: gray; icon-glyph: smile-wink;
// 📁 https://github.com/huaminghuangtw/Evergreen-Lists
const utils = importModule("utils");
let widget = new ListWidget();
widget.backgroundColor = Color.black();
widget.useDefaultPadding();
let fileContent;
try {
fileContent = await new Request("https://raw.githubusercontent.com/huaminghuangtw/Evergreen-Lists/main/%F0%9F%92%AD%20Journal%20Prompt/%F0%9F%92%AD%20Journal%20Prompt.json").loadString();
} catch {
let fm = FileManager.iCloud();
let folderPath = fm.joinPath(fm.bookmarkedPath("Second-Brain"), "EvergreenLists");
let jsonFile = utils.getAllFilesByExtension(folderPath, "json").find(file => file.endsWith("💭 Journal Prompt.json"));
fileContent = fm.readString(jsonFile);
}
let reminders = JSON.parse(fileContent).reminders;
let randomJournalPrompt = utils.getRandomItem(
utils.getRandomItem(
reminders.filter(r =>
r.subtasks &&
r.subtasks.length > 0 &&
!r.flagged
)
).subtasks
).name;
let text = widget.addText(randomJournalPrompt);
text.centerAlignText();
text.textColor = Color.white();
// http://iosfonts.com
text.font = new Font("IowanOldStyle-BoldItalic", 20);
text.minimumScaleFactor = 0.1;
text.textOpacity = 1;
widget.url = `shortcuts://run-shortcut?` +
`name=${encodeURI("Search Reminders")}&` +
`input=${encodeURI(randomJournalPrompt)}`;
config.runsInWidget ? Script.setWidget(widget) : widget.presentMedium();
Script.complete();