-
Notifications
You must be signed in to change notification settings - Fork 156
/
Bilibili.js
124 lines (111 loc) · 2.89 KB
/
Bilibili.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
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: pink; icon-glyph: heartbeat;
/*
* Author: evilbutcher
* Github: https://github.com/evilbutcher
* 本脚本使用了@Gideon_Senku的Env.scriptable,感谢!
*/
const goupdate = true;
const $ = importModule("Env");
var rid = 0; //rid对应不同的B站榜单:0全站,1动画,3音乐,4游戏,5娱乐,36科技,119鬼畜,129舞蹈。
var num = 6; //自定义显示数量
var rancolor = true; //true为开启随机颜色
try {
var { bilibili, blnum, blrancolor } = importModule("Config");
rid = bilibili();
num = blnum();
rancolor = blrancolor();
console.log("将使用配置文件内B站配置");
} catch (e) {
console.log("将使用脚本内B站配置");
}
const res = await getinfo();
let widget = createWidget(res);
Script.setWidget(widget);
Script.complete();
function createWidget(res) {
var group = res.data;
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(`💗B站榜单`);
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.presentSmall();
return w;
}
async function getinfo() {
const blRequest = {
url: `https://app.bilibili.com/x/v2/rank/region?rid=${rid}`,
};
const res = await $.get(blRequest);
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: "Bilibili",
url:
"https://raw.githubusercontent.com/evilbutcher/Scriptables/master/Bilibili.js",
},
];
if (goupdate == true) update();