一个小白关于ios软件Scriptable的编程的疑惑
最近ios 14 更新了。小组件的应用,使苹果卓里卓气了。于是最近去找了个脚本。研究了下并不会
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: orange; icon-glyph: quote-right;
// Change these to your usernames!
const user = "spencer"
const jike = "4DDA0425-FB41-4188-89E4-952CA15E3C5E"
const telegram = "realSpencerWoo"
const github = "spencerwooo"
const sspai = "spencerwoo"
——以上应该是定义了几个常量——
const data = await fetchData()
const widget = createWidget(data)
Script.setWidget(widget)
Script.complete()
function createWidget(data) {
console.log(data)
const w = new ListWidget()
const bgColor = new LinearGradient()
bgColor.colors =
bgColor.locations =
w.backgroundGradient = bgColor
w.setPadding(12, 15, 15, 12)
w.spacing = 6
——这里应该是设置字体的颜色部分——
const time = new Date()
const dfTime = new DateFormatter()
dfTime.locale = "en"
dfTime.useMediumDateStyle()
dfTime.useNoTimeStyle()
const firstLine = w.addText(`[] ${user} ~$ now`)
firstLine.textColor = Color.white()
firstLine.textOpacity = 0.7
firstLine.font = new Font("Menlo", 11)
——这里应该是定义时间——
const timeLine = w.addText(`[🖥] ${dfTime.string(time)}`)
timeLine.textColor = Color.white()
timeLine.font = new Font("Menlo", 11)
const batteryLine = w.addText(`[] ${renderBattery()}`)
batteryLine.textColor = new Color("#6ef2ae")
batteryLine.font = new Font("Menlo", 11)
const jikeLine = w.addText(`[🤖] Jike: ${data.jikeFollower}`)
jikeLine.textColor = new Color("#ffcc66")
jikeLine.font = new Font("Menlo", 11)
const telegramLine = w.addText(`[️️] Telegram: ${data.telegram}`)
telegramLine.textColor = new Color("#7dbbae")
telegramLine.font = new Font("Menlo", 11)
const githubLine = w.addText(`[] GitHub: ${data.github}`)
githubLine.textColor = new Color("#ff9468")
githubLine.font = new Font("Menlo", 11)
const sspaiLine = w.addText(`[🐡] SSPAI: ${data.sspai}`)
sspaiLine.textColor = new Color("#ffa7d3")
sspaiLine.font = new Font("Menlo", 11)
return w
——这里应该是定义颜色和要显示的数据对应值——
}
async function fetchData() {
const url = `https://api.spencerwoo.com/subst ... eFollower&queryKey=${jike}`
+ `&source=telegram&queryKey=${telegram}`
+ `&source=github&queryKey=${github}`
+ `&source=sspai&queryKey=${sspai}`
const request = new Request(url)
const res = await request.loadJSON()
return res.data.subsInEachSource
}
——这里是利用API 查询需要的粉丝数或者点赞数——
function renderBattery() {
const batteryLevel = Device.batteryLevel()
const juice = "#".repeat(Math.floor(batteryLevel * 8))
const used = ".".repeat(8 - juice.length)
const batteryAscii = `[${juice}${used}] ${Math.round(batteryLevel * 100)}%`
return batteryAscii
}
——这一栏是显示电池电量——
我只理解了这些代码的大概目的。但是我想进行DIY 修改成我自己的就无从下手了。
试着把API换成我的,但是貌似我替换的是B站的API ,不是电报,关键词不一样。(参考的是这个教程:https://www.bilibili.com/read/cv3178336/)还有这个教程(https://www.tenlonstudio.com/3365.html)
搞到这一步我就懵逼无法进行下一步了。小白不懂。。。
尴尬。
求懂的大佬指一个方向、 别搞ios了 在搞就彻底卓化了
页:
[1]