-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidget_dear-today-me.js
51 lines (39 loc) · 1.58 KB
/
widget_dear-today-me.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
50
51
// 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/Dear-Today-Me
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/Dear-Today-Me/main/Dear-Today-Me.md").loadString();
} catch {
let fm = FileManager.iCloud();
fileContent = fm.readString(fm.joinPath(fm.bookmarkedPath("Second-Brain"), "Dear-Today-Me/Dear-Today-Me.md"));
}
let allParagraphs = fileContent.split("\n\n");
// Skip salutation and closing lines
let selectedParagraphs = allParagraphs.slice(1, allParagraphs.length - 2);
let randomParagraph = utils.getRandomItem(selectedParagraphs);
let plainTextFromMarkdown = utils.convertMarkdownToPlainText(randomParagraph);
let text = widget.addText(plainTextFromMarkdown);
text.centerAlignText();
text.textColor = Color.white();
// http://iosfonts.com
text.font = new Font("IowanOldStyle-BoldItalic", 16);
text.minimumScaleFactor = 0.1;
text.textOpacity = 1;
widget.url = `shortcuts://run-shortcut?` +
`name=${encodeURI("_Text2Speech")}&` +
`input=${encodeURI(
JSON.stringify(
{
text: plainTextFromMarkdown,
language: "EN"
}
)
)}`;
config.runsInWidget ? Script.setWidget(widget) : widget.presentMedium();
Script.complete();