-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwidget_100-blocks-a-day.js
More file actions
60 lines (48 loc) 路 1.62 KB
/
Copy pathwidget_100-blocks-a-day.js
File metadata and controls
60 lines (48 loc) 路 1.62 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
// 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
const CONFIG = {
startTime: "04:30",
endTime: "20:30",
totalBlocks: 55,
};
async function createWidget() {
let widget = new ListWidget();
widget.backgroundColor = Color.black();
widget.useDefaultPadding();
let now = new Date();
let [startTime, endTime] = [CONFIG.startTime, CONFIG.endTime].map((time) => {
let [hours, minutes] = time.split(":").map(Number);
return new Date(
now.getFullYear(),
now.getMonth(),
now.getDate(),
hours,
minutes
);
});
// 1 minute = 60 seconds = 60000 milliseconds
let currentMinutes = (now - startTime) / 60000;
let totalAwakeMinutes = (endTime - startTime) / 60000;
if (currentMinutes < 0 || currentMinutes > totalAwakeMinutes) {
widget.addText("");
return widget;
}
let blockDuration = totalAwakeMinutes / CONFIG.totalBlocks;
let currentBlockIndex = Math.floor(currentMinutes / blockDuration);
let blocks = [];
for (let i = 0; i < CONFIG.totalBlocks; i++) {
if (i === currentBlockIndex) {
blocks.push("馃┓");
} else {
blocks.push("鈼硷笍");
}
}
let text = widget.addText(blocks.join(" "));
text.centerAlignText();
return widget;
}
let widget = await createWidget();
config.runsInWidget ? Script.setWidget(widget) : widget.presentMedium();
Script.complete();