-
-
Save alexkuang0/a933a543324195a10ace72bda2b9d282 to your computer and use it in GitHub Desktop.
| const UID = args.widgetParameter | |
| if (!/^\d+$/.test(UID)) throw new Error('请提供正确的 UID') | |
| let widget = createWidget(await getData(UID)) | |
| if (!config.runsInWidget) { | |
| await widget.presentSmall() | |
| } | |
| Script.setWidget(widget) | |
| Script.complete() | |
| async function getData(uid) { | |
| const result = { | |
| uid, | |
| avatar: null, | |
| follower: null, | |
| nickname: '未知用户' | |
| } | |
| try { | |
| const r1 = new Request(`https://api.bilibili.com/x/relation/stat?vmid=${uid}`) | |
| const res1 = await r1.loadJSON() | |
| const r2 = new Request(`https://api.bilibili.com/x/space/acc/info?mid=${uid}`) | |
| const res2 = await r2.loadJSON() | |
| if (res1.data && res1.data.follower && res2.data && res2.data.name && res2.data.face) { | |
| result.follower = res1.data.follower | |
| result.nickname = res2.data.name | |
| result.avatar = await (new Request(res2.data.face)).loadImage() | |
| } else { | |
| throw new Error('no sufficient data.') | |
| } | |
| } catch (e) { | |
| console.log(e.message) | |
| const isCloud = module.filename.includes('Documents/iCloud~') | |
| const fileMgr = FileManager[isCloud ? 'iCloud' : 'local']() | |
| const placeholderPath = fileMgr.documentsDirectory() + '/biliFollower-avatarPlaceholder.jpeg' | |
| result.avatar = Image.fromFile(placeholderPath) | |
| } | |
| return result | |
| } | |
| function formatFollower(num) { | |
| if (typeof num !== 'number') return 'N/A' | |
| if (num >= 10000) return (num / 10000).toFixed(1) + 'w' | |
| return num.toString() | |
| } | |
| function createWidget(options) { | |
| const w = new ListWidget() | |
| const { avatar, nickname, uid, follower } = options | |
| // background gradient | |
| const gr1 = new LinearGradient() | |
| gr1.locations = [0, 1] | |
| gr1.colors = [ | |
| new Color('#F68EBC'), | |
| new Color('#F45A8D'), | |
| ] | |
| w.backgroundGradient = gr1 | |
| w.url = `https://space.bilibili.com/${uid}` | |
| // top spacer | |
| w.addSpacer() | |
| // stack | |
| const st = w.addStack() | |
| // avatar image | |
| const ava = st.addImage(avatar) | |
| ava.imageSize = new Size(20, 20) | |
| ava.cornerRadius = 10 | |
| ava.borderWidth = 3 | |
| ava.borderColor = new Color('#FFF') | |
| st.addSpacer(5) | |
| // nickname | |
| const cap = st.addText(nickname) | |
| cap.font = Font.heavySystemFont(14) | |
| cap.textColor = new Color('#FFF') | |
| cap.lineLimit = 1 | |
| cap.minimumScaleFactor = 0.8 | |
| w.addSpacer(2) | |
| // follower | |
| const fo = w.addText(formatFollower(follower)) | |
| fo.font = Font.thinSystemFont(45) | |
| fo.textColor = new Color('#FFF') | |
| fo.lineLimit = 1 | |
| fo.minimumScaleFactor = 0.5 | |
| // bottom spacer | |
| w.addSpacer() | |
| return w | |
| } | |
能考虑加入每天粉丝增量和粉丝数量曲线图吗
能考虑加入每天粉丝增量和粉丝数量曲线图吗
@janedut 已加入显示每日粉丝增量功能,详见上一条更新日志。写得匆忙,如有 bug 请反馈。
p.s. 曲线图功能不打算加入, Scriptable 提供的 API 和数据存储功能都很有限,实现图表过于复杂。
Hi @alexkuang0,
Benny here, from Widget Hub. You had uploaded your widget to Widget Hub. Unfortunately, the image URL does not work and the description of the widget was not correct. I have corrected the issue now and would unlock the widget now.
Regards Benny
@ThisIsBenny Thank you Benny. It's probably someone else who uploaded the widget cuz I don't remember doing that. Do you have a link to it?
Oh ok... I didn‘t check the User and I have assume that the user is the author. If you like, i can remove it: https://widget-hub.app/widget/6040901ec1909a00094fa314/bilibili-followers
@ThisIsBenny I just registered as a developer on Widget Hub with my GitHub account. If a transfer of ownership is possible please do; if not I can upload one myself. Btw thank you for your great work!
Transferring the ownership isn‘t possible. In will remove the Script which was uploaded without permission
能考虑加入每天粉丝增量和粉丝数量曲线图吗
@janedut 已加入显示每日粉丝增量功能,详见上一条更新日志。写得匆忙,如有 bug 请反馈。
p.s. 曲线图功能不打算加入, Scriptable 提供的 API 和数据存储功能都很有限,实现图表过于复杂。
进过测试,粉丝增量统计从添加脚本时刻开始计算,能不能改成晚上12点呢
@janedut 已更新,现在默认晚上 12 点更新
本 Gist 已经停止维护,请前往 Gitee 代码仓库 查看后续更新。
This gist is not maintained here anymore, please go to my Gitee repo for future updates.
Instructions 使用说明
🧰 Install 安装
请选用以下任一方法:
🛠 Configuration 配置
(‼️ 重要变更) 在小部件设置的 Parameter 中输入你的哔哩哔哩 UID 即可。
🎬 Video Instructions 视频说明
https://www.bilibili.com/video/BV1654y1178Z
Changelog 更新日志
0.1.009/26/20200.1.110/04/20200.1.210/12/20200.2.003/02/20210.2.103/06/2021UPDATE_TIME,可自行设置每日何时更新(默认:晚上 0 点)+/-与数字间没有空格0.3.003/11/2021