-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidget_100-blocks-a-day.js
37 lines (25 loc) · 1.1 KB
/
widget_100-blocks-a-day.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
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: gray; icon-glyph: smile-wink;
// 💡 Inspired by: https://waitbutwhy.com/2016/10/100-blocks-day.html
let widget = new ListWidget();
widget.backgroundColor = Color.black();
widget.useDefaultPadding();
let now = new Date();
let startTime = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 4);
let endTime = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 20, 30);
let totalBlocks = 45;
let currentMinutes = (now - startTime) / 60000;
let totalAwakeMinutes = (endTime - startTime) / 60000;
let blockDuration = totalAwakeMinutes / totalBlocks;
let currentBlockIndex = Math.floor(currentMinutes / blockDuration);
let blocks = [];
for (let i = 0; i < totalBlocks; i++) {
blocks.push(i === currentBlockIndex ? "🔲" : "🔳");
}
let text = widget.addText(blocks.join(" "));
text.centerAlignText();
widget.url = `shortcuts://run-shortcut?` +
`name=${encodeURI("Show Year Progress")}`;
config.runsInWidget ? Script.setWidget(widget) : widget.presentMedium();
Script.complete();