Guest User

Untitled

a guest
Dec 15th, 2020
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.20 KB | None | 0 0
  1. /*
  2.  
  3.  
  4.  
  5. Tap the Share icon in the top right.
  6. Then tap "Copy" to copy all of this code.
  7. Now you can paste into a new script.
  8.  
  9.  
  10.  
  11. */
  12. async function importWidget() {
  13.  
  14. function makeAlert(message,options) {
  15. const a = new Alert()
  16. a.message = message
  17. for (const option of options) { a.addAction(option) }
  18. return a
  19. }
  20.  
  21. let fm = FileManager.local()
  22. fm = fm.isFileStoredIniCloud(module.filename) ? FileManager.iCloud() : fm
  23.  
  24. const path = fm.joinPath(fm.documentsDirectory(), "Weather Cal code.js")
  25. const wc = fm.fileExists(path) ? fm.readString(path) : false
  26. const version = wc ? parseInt(wc.slice(wc.lastIndexOf("//") + 2).trim()) : false
  27.  
  28. if (wc && (!version || version < 4)) { return await makeAlert("Please update Weather Cal before importing a widget.",["OK"]).present() }
  29.  
  30. if ((await makeAlert("Do you want your widget to be named " + Script.name() + "?",["Yes, looks good","No, let me change it"]).present()) == 1) { return }
  31.  
  32. fm.writeString(fm.joinPath(fm.libraryDirectory(), "weather-cal-preferences-" + Script.name()), '{"widget":{"name":"Overall settings","locale":"","units":"imperial","preview":"large","padding":"3","widgetPadding":{"top":"0","left":"0","bottom":"2","right":"0"},"tintIcons":true},"localization":{"name":"Localization and text customization","morningGreeting":"eyes forward, heart open.","afternoonGreeting":"remember why you started.","eveningGreeting":"let it be.","nightGreeting":"follow your own stars.","nextHourLabel":"Next hour","tomorrowLabel":"Tomorrow","noEventMessage":"no more events for today...","noRemindersMessage":"tasks complete...","durationMinute":"m","durationHour":"h","covid":"{cases} cases, {deaths} deaths, {recovered} recoveries","week":"Week"},"font":{"name":"Text sizes, colors, and fonts","defaultText":{"size":"14","color":"D3D3D3","font":"HelveticaNeue"},"smallDate":{"size":"30","color":"D3D3D3","font":"HelveticaNeue"},"largeDate1":{"size":"36","color":"D3D3D3","font":"HelveticaNeue-Thin"},"largeDate2":{"size":"22","color":"D3D3D3","font":"HelveticaNeue"},"greeting":{"size":"15","color":"ad6a6c","font":"Chalkduster"},"eventLabel":{"size":"14","color":"ad6a6c","font":"HelveticaNeue"},"eventTitle":{"size":"12","color":"D3D3D3","font":"HelveticaNeue"},"eventLocation":{"size":"11","color":"D3D3D3","font":"HelveticaNeue"},"eventTime":{"size":"11","color":"ad6a6c","font":"HelveticaNeue"},"noEvents":{"size":"14","color":"ad6a6c","font":"HelveticaNeue"},"reminderTitle":{"size":"12","color":"D3D3D3","font":"HelveticaNeue"},"reminderTime":{"size":"11","color":"ad6a6c","font":"HelveticaNeue"},"noReminders":{"size":"14","color":"ad6a6c","font":"HelveticaNeue"},"largeTemp":{"size":"34","color":"D3D3D3","font":"HelveticaNeue"},"smallTemp":{"size":"12","color":"D3D3D3","font":"HelveticaNeue"},"tinyTemp":{"size":"12","color":"D3D3D3","font":"HelveticaNeue"},"customText":{"size":"14","color":"D3D3D3","font":"HelveticaNeue"},"battery":{"size":"14","color":"D3D3D3","font":"HelveticaNeue"},"sunrise":{"size":"12","color":"D3D3D3","font":"HelveticaNeue"},"covid":{"size":"14 ","color":"D3D3D3","font":"HelveticaNeue"},"week":{"size":"12","color":"D3D3D3","font":"HelveticaNeue"}},"date":{"name":"Date","dynamicDateSize":false,"staticDateSize":"large","smallDateFormat":"EEEE, MM.dd","largeDateLineOne":"EEEE","largeDateLineTwo":"MMMM d"},"events":{"name":"Events","numberOfEvents":"6","minutesAfter":"5","showAllDay":true,"numberOfDays":"1","labelFormat":"EEEE, MMMM d","showTomorrow":"20","showEventLength":"duration","showLocation":false,"selectCalendars":"","showCalendarColor":"rectangle left","noEventBehavior":"message","url":""},"reminders":{"name":"Reminders","numberOfReminders":"3","useRelativeDueDate":false,"showWithoutDueDate":false,"showOverdue":false,"todayOnly":false,"selectLists":"","showListColor":"rectangle left","noRemindersBehavior":"none","url":""},"sunrise":{"name":"Sunrise and sunset","showWithin":"","separateElements":false},"weather":{"name":"Weather","showLocation":false,"horizontalCondition":false,"showCondition":false,"showHighLow":true,"showRain":false,"tomorrowShownAtHour":"20","spacing":"0","horizontalHours":false,"showHours":"2","showHoursFormat":"ha","horizontalForecast":true,"showDays":"3","showDaysFormat":"E","showToday":false,"urlCurrent":"","urlFuture":"","urlForecast":""},"covid":{"name":"COVID data","country":"USA","url":"https://covid19.who.int"},"symbol":{"name":"Symbols","size":"18","padding":{"top":"","left":"","bottom":"","right":""},"tintColor":"D3D3D3"}}')
  33. fm.writeString(fm.joinPath(fm.libraryDirectory(), "weather-cal-" + Script.name()), '{"type":"image"}')
  34.  
  35. let code = await new Request('https://raw.githubusercontent.com/mzeryck/Weather-Cal/main/weather-cal.js').loadString()
  36. let arr = code.split('`')
  37. arr[1] = `
  38.  
  39. row,
  40. column,
  41. left,
  42. date,
  43. greeting,
  44. column(90),
  45. right,
  46. current,
  47.  
  48. row,
  49. column,
  50. left,
  51. daily,
  52.  
  53. column(100)
  54. right,
  55. hourly,
  56. sunrise,
  57.  
  58. row,
  59. column,
  60. space,
  61. right,
  62. reminders,
  63. left,
  64. events,
  65.  
  66. `
  67.  
  68. alert = makeAlert("Close this script and re-run it to finish setup.",["OK"])
  69. fm.writeString(module.filename, arr.join('`'))
  70. await alert.present()
  71. }
  72. await importWidget()
  73. Script.complete()
Advertisement
Add Comment
Please, Sign In to add comment