描述

通过在脚本中设置textList后,每次点击桌面小组件,会执行本脚本随机选择其中一句启发做展示。

脚本

  1. // 启发语录列表
  2. const textList=[
  3. '选我所爱,爱我所选。',
  4. '此生理想、近期规划、今日功课。',
  5. '流水不争先,争的是滔滔不绝。',
  6. '既往不恋,当下不杂,未来不迎。',
  7. ];
  8. /*-------上面是配置区域-------*/
  9. // 创建小组件
  10. const widget = new ListWidget();
  11. // 添加文本
  12. const textItem=textList[Math.floor((Math.random()*textList.length))];
  13. let text;
  14. // 设置语录样式
  15. text = widget.addText(textItem);
  16. text.textColor = new Color("#ffffff");
  17. text.font= new Font('Georgia-BoldItalic',26)
  18. text.minimumScaleFactor=0.5;
  19. textItem.length>10?text.leftAlignText():text.centerAlignText();
  20. // 添加渐变色背景
  21. const gradient = new LinearGradient();
  22. gradient.locations = [0, 1];
  23. gradient.colors = [new Color("#333333"), new Color("#111111")];
  24. widget.backgroundGradient = gradient;
  25. // 设置部件
  26. if (config.runsInWidget) {
  27. Script.setWidget(widget)
  28. } else {
  29. // widget.presentMedium()
  30. }