惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 聂微东
GbyAI
GbyAI
G
Google Developers Blog
大猫的无限游戏
大猫的无限游戏
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - 叶小钗
A
About on SuperTechFans
M
MIT News - Artificial intelligence
宝玉的分享
宝玉的分享
雷峰网
雷峰网
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Martin Fowler
Martin Fowler
Google DeepMind News
Google DeepMind News
博客园 - Franky
B
Blog RSS Feed
Y
Y Combinator Blog
Stack Overflow Blog
Stack Overflow Blog
MongoDB | Blog
MongoDB | Blog
Last Week in AI
Last Week in AI
T
The Blog of Author Tim Ferriss
The GitHub Blog
The GitHub Blog
S
SegmentFault 最新的问题
罗磊的独立博客
Apple Machine Learning Research
Apple Machine Learning Research

博客园 - 饭特稠

10 年前端经验喂了狗 浪浪山老前端的2025 useAttrs 是响应式的吗(by 豆包) 实时互动教育版的自定义 UI 如何开发 2024,在路上 当蓝牙键盘连不上电脑:一次意外的debug之旅 前端技术选型时有用的网站 好用的zsh插件,打造好用的命令行 2023年终总结:怀孕,装修,还贷和其他 分享一个URL正则 如何使webpack编译 node_modules 中的 npm 包 小程序中实现图片旋转后保存 Custom Elements 和 Shadow DOM了解一下? CSS 原生嵌套来了 聊聊CSS 缓动函数的新成员linear() chatgpt: 在ts中如何声明一个全局类型 Workbox -- 为serviceWorker量身定做的工具 cache API简介 重新学车 魔幻2022
使用 scriptable 实现每日诗词小组件
饭特稠 · 2023-10-31 · via 博客园 - 饭特稠

什么是 scriptable

scriptable可以让我们用 js 就可以创建出 ios 中的桌面小组件,而不需要掌握 ios 开发。由于最近深感自己文化水平低,所以想借助 scriptable实现一个每日诗词小组件,这样可以提高一下自己的文化水平。

效果

代码

scriptable支持多种 api,比如发起请求,插入图片,布局。。。详细文档可以在 https://docs.scriptable.app 查阅

let url = "https://v2.jinrishici.com/one.json"
let req = new Request(url);
let json = await req.loadJSON();

// log(json)

let poem=json.data.origin.content[0]

let dotflag = /。|,|!|?/g
let dot=poem.match(dotflag)

poem=(poem.split(dotflag))
log(poem)


let str3=json.data.origin.author
let str4=json.data.origin.title


console.log(json.data.origin)

let widget = new ListWidget()

let lineColor=new LinearGradient()
// 自定义背景颜色
// widget.backgroundColor=new Color("#DC143C")

// 背景图片
let bgImg="https://d2w9rnfcy7mm78.cloudfront.net/8867234/original_63cd43c88048a9ff6279c0340faea9db.jpg?1601084036?bc=0"
const i = await new Request(bgImg);
const img = await i.loadImage();
widget.backgroundImage=img

for (let str of poem) {
  let strWidget=widget.addText(str)
  strWidget.font=new Font("KaiTi", 16)
  strWidget.textColor=new Color("#ffffff")
}

  
  widget.spacing=14
//   作者信息
  let author=widget.addText("-"+str3+"《"+str4+"》")
  author.textColor=new Color("#ffffff")
  author.rightAlignText()
  
  widget.presentMedium()


Script.setWidget(widget)
Script.complete()

one more thing

https://github.com/Nicolasking007/Scriptable