-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreate Notification.js
53 lines (43 loc) · 1.43 KB
/
Create Notification.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
52
53
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: deep-gray; icon-glyph: smile;
const inputs = args.shortcutParameter;
const notification = new Notification();
notification.identifier = inputs.id
? inputs.id
: inputs.title
? inputs.title
: "";
if (inputs.threadId) notification.threadIdentifier = inputs.threadId;
notification.title = inputs.title
.split("\n")
.map((line) => line.trim())
.filter((line) => line !== "")
.join("\n");
const textDivider = "──────────────";
notification.subtitle = inputs.subtitle
? `${textDivider}\n${inputs.subtitle
.split("\n")
.map((line) => line.trim())
.filter((line) => line !== "")
.join("\n")}\n${textDivider}`
: textDivider;
if (inputs.body)
notification.body = inputs.body
.split("\n")
.map((line) => line.trim())
.filter((line) => line !== "")
.join("\n");
if (inputs.openURL) notification.openURL = inputs.openURL;
if (inputs.triggerDate)
notification.setTriggerDate(new Date(inputs.triggerDate));
const actions = inputs.actions
? JSON.parse(`[${inputs.actions.replace(/\n/g, ",")}]`)
: inputs.openURL
? [{ title: "🔗 Open URL", url: inputs.openURL }]
: [];
actions.forEach((action) => {
notification.addAction(action.title, action.url);
});
notification.schedule();
Script.complete();