Advertisement
Guest User

Untitled

a guest
Oct 1st, 2024
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.48 KB | Source Code | 0 0
  1. const date = new Date();
  2. async function createWidget() {
  3.   const widget = new ListWidget();
  4.  
  5.   let backgroundImg = await new Request("https://i.imgur.com/9oDsSxt.jpeg").loadImage();
  6.  
  7.   widget.backgroundImage = backgroundImg
  8.  
  9. // Blank text to align the "hello" image properly. I wasn't able to do it without this weird workaround.
  10.   let txt = widget.addText(" ");
  11.  
  12.   widget.addSpacer(2);
  13.  
  14.   let helloImg = await new Request("https://i.imgur.com/7g7YbVB.png").loadImage();
  15.  
  16.   let stack = widget.addStack();
  17.   stack.size = new Size(300,50);
  18.   theImg = stack.addImage(helloImg);
  19.   stack.centerAlignContent();
  20.  
  21.  
  22. // Format the date
  23.   let df = new DateFormatter()
  24. df.dateFormat = "EEEE, MMMM d"
  25.  
  26.   widget.addSpacer();
  27.  
  28.  
  29.   let dateText = widget.addText(df.string(date));
  30.   dateText.font = Font.regularSystemFont(18);
  31.   dateText.textColor = Color.white();
  32.   dateText.centerAlignText();
  33.  
  34.   widget.addSpacer();
  35.  
  36.   return widget;
  37. } //createWidget
  38.  
  39.  
  40. //---[ main ]-------------------------------------
  41. if (config.runsInWidget) {
  42.   let widget = await createWidget()
  43.   Script.setWidget(widget)
  44.     Script.complete()
  45. } else {
  46.   let widget = await createWidget()
  47.   await widget.presentMedium()
  48.  
  49. }
  50.  
  51.  
  52. //------------------------------------------------
  53. function newLinearGradient(hexcolors, locations) {
  54.   let gradient = new LinearGradient()
  55.   gradient.locations = locations
  56.   gradient.colors = hexcolors
  57.                      .map(color=>new Color(color))
  58.   return gradient
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement