描述
通过在脚本中设置textList后,每次点击桌面小组件,会执行本脚本随机选择其中一句启发做展示。
脚本
// 启发语录列表
const textList=[
'选我所爱,爱我所选。',
'此生理想、近期规划、今日功课。',
'流水不争先,争的是滔滔不绝。',
'既往不恋,当下不杂,未来不迎。',
];
/*-------上面是配置区域-------*/
// 创建小组件
const widget = new ListWidget();
// 添加文本
const textItem=textList[Math.floor((Math.random()*textList.length))];
let text;
// 设置语录样式
text = widget.addText(textItem);
text.textColor = new Color("#ffffff");
text.font= new Font('Georgia-BoldItalic',26)
text.minimumScaleFactor=0.5;
textItem.length>10?text.leftAlignText():text.centerAlignText();
// 添加渐变色背景
const gradient = new LinearGradient();
gradient.locations = [0, 1];
gradient.colors = [new Color("#333333"), new Color("#111111")];
widget.backgroundGradient = gradient;
// 设置部件
if (config.runsInWidget) {
Script.setWidget(widget)
} else {
// widget.presentMedium()
}