-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlockscreen-rss-widget_no_rotation.js
More file actions
61 lines (45 loc) · 1.57 KB
/
lockscreen-rss-widget_no_rotation.js
File metadata and controls
61 lines (45 loc) · 1.57 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
// Scriptable Lockscreen RSS widget (without rotation feature)
// Version: v1.1.1
// Author: @leon47331
const url = "RSS-FEED-URL";
const srcName = "SITE-NAME"
async function getRSSFeed() {
let req = new Request(url);
let feed = await req.loadString();
let items = [];
let regex = /<item>[\s\S]*?<title>(?:<!\[CDATA\[)?(.*?)(?:\]\]>)?<\/title>[\s\S]*?<link>(.*?)<\/link>[\s\S]*?<\/item>/g;
let match;
while ((match = regex.exec(feed)) !== null) {
let title = match[1];
let link = match[2];
title = title.replace(/"/g, "\"");
title = title.replace(/„/g, "„").replace(/“/g, "“");
title = title.replace(/–/g, "–");
items.push({ title, link });
}
return items;
}
let widget = new ListWidget();
async function createWidget() {
let rssItems = await getRSSFeed();
if (rssItems.length > 0) {
let latestItem = rssItems[0];
let title = latestItem.title;
let link = latestItem.link;
let stack = widget.addStack();
stack.layoutVertically();
let titleText = widget.addText(srcName);
titleText.font = Font.boldSystemFont(13);
titleText.textColor = new Color("#adacac");
widget.addSpacer(1);
let newsText = widget.addText(title);
newsText.font = Font.semiboldMonospacedSystemFont(12);
widget.url = link
} else {
widget.addText("No new articles available");
widget.url = "scriptable://" // FIXME: Placeholder
}
Script.setWidget(widget);
Script.complete();
}
await createWidget();