-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwidget_journal-prompt.js
More file actions
64 lines (50 loc) · 1.76 KB
/
widget_journal-prompt.js
File metadata and controls
64 lines (50 loc) · 1.76 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// 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 CONFIG = {
FONT: { NAME: "IowanOldStyle-BoldItalic", SIZE: 20 },
MINIMUM_SCALE_FACTOR: 0.1,
TEXT_OPACITY: 1,
TEXT_COLOR: Color.white(),
};
const Utils = importModule("Utils");
const Cache = importModule("Cache");
let cache = new Cache(Script.name());
let randomJournalPrompt = await cache.getOrFetch(fetchRandomJournalPrompt);
let widget = await createWidget(randomJournalPrompt);
config.runsInWidget ? Script.setWidget(widget) : widget.presentMedium();
Script.complete();
// ================
// Helper functions
// ================
async function fetchRandomJournalPrompt() {
let fileContent = await await Utils.getFileContent(
"huaminghuangtw",
"Evergreen-Lists",
"💭 Journal Prompt/💭 Journal Prompt.json"
);
let reminders = JSON.parse(fileContent).reminders;
let randomJournalPrompt = Utils.convertMarkdownToPlainText(
Utils.getRandomItem(
Utils.getRandomItem(
reminders.filter(
(r) =>
r.subtasks.length > 0 &&
! r.title.includes("Prioritization")
)
).subtasks
).name
);
return randomJournalPrompt;
}
async function createWidget(randomJournalPrompt) {
let widget = new ListWidget();
let text = widget.addText(Utils.truncateText(randomJournalPrompt));
text.centerAlignText();
text.font = new Font(CONFIG.FONT.NAME, CONFIG.FONT.SIZE);
text.minimumScaleFactor = CONFIG.MINIMUM_SCALE_FACTOR;
text.textOpacity = CONFIG.TEXT_OPACITY;
text.textColor = CONFIG.TEXT_COLOR;
return widget;
}