Advertisement
Guest User

Special Days Widget

a guest
Apr 10th, 2021
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. //This is meant for a small widget
  2. //You can change the bellow
  3. //Enter hex colours in double quotes for the colours. The light colour will be active if light mode is on and the dark colour will be active if dark mode is on.
  4. //Enter numbers for the sizes and space bellow
  5. //Enter true or false for showTitle
  6.  
  7. let backgroundColourLight = "#fff"
  8. let backgroundColourDark = "#000"
  9.  
  10. let titleSize = 15
  11. let titleColourLight = "#000"
  12. let titleColourDark = "#fff"
  13. let spaceingBelowTitle = 5
  14. let showTitle = true
  15.  
  16. let daySize = 15
  17. let dayColourLight = "#000"
  18. let dayColourDark = "#fff"
  19. spaceingBelowDay = 3
  20.  
  21. //Do not Change Below
  22. //Sets correct colours
  23. let backgroundColour = Color.dynamic(new Color(backgroundColourLight),new Color(backgroundColourDark))
  24. let titleColour = Color.dynamic(new Color(titleColourLight),new Color(titleColourDark))
  25. let dayColour = Color.dynamic(new Color(dayColourLight),new Color(dayColourDark))
  26.  
  27. //Sets up stuff
  28. let url = "https://www.daysoftheyear.com/"
  29. let req = new Request(url)
  30. let html = await req.loadString()
  31. let currentDate = new Date
  32. currentDate = currentDate.toDateString()
  33.  
  34. //Makes widget
  35. let widget = new ListWidget()
  36. widget.backgroundColor = backgroundColour
  37. let date = new Date()
  38. date.setHours(date.getHours() + 3)
  39. widget.refreshAfterDate = date
  40.  
  41. //Adds title
  42. if (showTitle) {
  43. let title = widget.addText("Today Is...")
  44. title.font = Font.mediumRoundedSystemFont(titleSize)
  45. title.textColor = titleColour
  46. title.centerAlignText()
  47. widget.addSpacer(spaceingBelowTitle)
  48. }
  49.  
  50. //Gets special days
  51. for(var i = 1; i < 6; i++) {
  52. //Finds date and formats it
  53. let date = html.split('<div class="date_day">')[i]
  54. date = date.split('</div>')[0]
  55. date = date.split("st,").join("")
  56. date = date.split("th,").join("")
  57. date = date.split("nd,").join("")
  58. date = date.split("rd,").join("")
  59. let day = html.split('class="js-link-target">')[i]
  60. //Finds special day
  61. day = day.split("</a>")[0]
  62. date = new Date(date)
  63. date = date.toDateString()
  64.  
  65. //Adds special day if it is today
  66. if (date === currentDate) {
  67. //puts in '
  68. day = day.split("&#8217;").join("'")
  69. day = widget.addText(day)
  70. day.font = Font.mediumRoundedSystemFont(daySize)
  71. day.textColor = dayColour
  72. day.minimumScaleFactor = .5
  73. day.lineLimit = 1
  74. widget.addSpacer(spaceingBelowDay)
  75. }
  76. }
  77.  
  78. //Compleats the script
  79. widget.presentSmall()
  80. Script.setWidget(widget)
  81. Script.complete()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement