-
Notifications
You must be signed in to change notification settings - Fork 156
/
RSS.js
130 lines (118 loc) · 3.15 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
119
120
121
122
123
124
125
126
127
128
129
130
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: deep-green; icon-glyph: rss;
/*
* Author: evilbutcher
* Github: https://github.com/evilbutcher
* 本脚本使用了@Gideon_Senku的Env.scriptable,感谢!
*/
const goupdate = true; //默认关闭,需要更新时请手动打开
const $ = importModule("Env");
var num = 6; //自定义显示数量
var rancolor = true; //true为开启随机颜色
// 填写RSS订阅链接,默认为仓库的最近Commit
// Fill in the RSS subscription link, the default is the latest Commit of the Repo
var rsslink = "https://github.com/GideonSenku/Scriptable/commits/master.atom";
try {
const con = importModule("Config");
num = con.rssnum();
rancolor = con.rssrancolor();
rsslink = con.rsslink();
console.log("将使用配置文件内RSS配置");
} catch (e) {
console.log("将使用脚本内RSS配置");
}
const res = await getinfo();
let widget = createWidget(res);
Script.setWidget(widget);
Script.complete();
function createWidget(res) {
if (res.status == "ok") {
var titlerss = res.feed.title;
var group = res.items;
items = [];
for (var i = 0; i < num; i++) {
var item = group[i].title;
items.push(item);
}
console.log(items);
const w = new ListWidget();
const bgColor = new LinearGradient();
bgColor.colors = [new Color("#1c1c1c"), new Color("#29323c")];
bgColor.locations = [0.0, 1.0];
w.backgroundGradient = bgColor;
w.addSpacer();
w.spacing = 5;
const firstLine = w.addText(`📻${titlerss}`);
firstLine.font = new Font('SF Mono', 15);
firstLine.textColor = Color.white();
firstLine.textOpacity = 0.7;
for (var i = 0; i < items.length; i++) {
addTextToListWidget(`• ${items[i]}`, w);
}
w.addSpacer();
w.spacing = 5;
w.presentMedium();
return w;
}
}
async function getinfo() {
const rssRequest = {
url:
"https://api.rss2json.com/v1/api.json?rss_url=" +
encodeURIComponent(rsslink),
};
const res = await $.get(rssRequest);
log(res);
return res;
}
function addTextToListWidget(text, listWidget) {
let item = listWidget.addText(text);
if (rancolor == true) {
item.textColor = new Color(color16());
} else {
item.textColor = Color.white();
}
item.font = new Font('SF Mono', 12);
}
function color16() {
var r = Math.floor(Math.random() * 256);
if (r + 50 < 255) {
r = r + 50;
}
if (r > 230 && r < 255) {
r = r - 50;
}
var g = Math.floor(Math.random() * 256);
if (g + 50 < 255) {
g = g + 50;
}
if (g > 230 && g < 255) {
g = g - 50;
}
var b = Math.floor(Math.random() * 256);
if (b + 50 < 255) {
b = b + 50;
}
if (b > 230 && b < 255) {
b = b - 50;
}
var color = "#" + r.toString(16) + g.toString(16) + b.toString(16);
return color;
}
//更新代码
function update() {
log("🔔更新脚本开始!");
scripts.forEach(async (script) => {
await $.getFile(script);
});
log("🔔更新脚本结束!");
}
const scripts = [
{
moduleName: "RSS",
url:
"https://raw.githubusercontent.com/evilbutcher/Scriptables/master/RSS.js",
},
];
if (goupdate == true) update();