-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathRSS.js
118 lines (114 loc) · 2.52 KB
/
RSS.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* Author: evilbutcher
* Github: https://github.com/evilbutcher
* 感谢Nicked大佬的不用微博脚本,让本菜鸡得以有模版参考🙏
*/
const $ = require("Config");
const family = $widget.family;
var rsslink = "https://github.com/evilbutcher/Scriptables/commits/master.atom";
try {
$.thisnum = $.rssnum();
$.rancolor = $.rssrancolor();
$.rsslink = $.rsslink();
console.log("将使用配置文件内RSS配置");
} catch (e) {
console.log("将使用脚本内RSS配置");
}
const res = await getinfo();
var titles = [];
if (res.status == "ok") {
for (var i = 0; i < res.items.length; i++) {
titles = titles.concat({
type: "text",
props: {
text: res.items[i].title,
font: $font(15),
offset: $point(7, 0),
lineLimit: 1
}
});
}
console.log(titles);
$widget.setTimeline(ctx => {
return {
type: "zstack",
props: {
alignment: $widget.alignment.center
},
views: [
{
type: "vstack",
props: {
spacing: 5,
alignment: $widget.horizontalAlignment.leading
},
views: [getGrid(family, titles)]
}
]
};
});
}
async function getinfo() {
const rssRequest = {
url:
"https://api.rss2json.com/v1/api.json?rss_url=" +
encodeURIComponent(rsslink)
};
const res = await $http.get(rssRequest);
console.log(res);
return res.data;
}
//by Nicked
function getGrid(family, data) {
if (family == 1)
return {
type: "vgrid",
props: {
columns: Array(2).fill({
flexible: {
minimum: 10,
maximum: Infinity
}
})
},
views: [
{
type: "vstack",
props: {
spacing: 8,
alignment: $widget.horizontalAlignment.leading,
offset: $point(2, 7),
frame: {
width: 150
}
},
views: data.slice(0, 5)
},
{
type: "vstack",
props: {
spacing: 8,
alignment: $widget.horizontalAlignment.leading,
offset: $point(-15, 7),
frame: {
width: 145
}
},
views: data.slice(5, 10)
}
]
};
else
return {
type: "vstack",
props: {
spacing: 8,
alignment: $widget.horizontalAlignment.leading,
offset: $point(0, 7),
frame: {
width: 150
}
},
views: data.slice(0, 5)
};
}