Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async function importWidget() {
- function makeAlert(message,options) {
- const a = new Alert()
- a.message = message
- for (const option of options) { a.addAction(option) }
- return a
- }
- let fm = FileManager.local()
- fm = fm.isFileStoredIniCloud(module.filename) ? FileManager.iCloud() : fm
- const path = fm.joinPath(fm.documentsDirectory(), "Weather Cal code.js")
- const wc = fm.fileExists(path) ? fm.readString(path) : false
- const version = wc ? parseInt(wc.slice(wc.lastIndexOf("//") + 2).trim()) : false
- if (wc && (!version || version < 3)) { return await makeAlert("Please update Weather Cal before importing a widget.",["OK"]).present() }
- if ((await makeAlert("Do you want your widget to be named " + Script.name() + "?",["Yes, looks good","No, let me change it"]).present()) == 1) { return }
- fm.writeString(fm.joinPath(fm.libraryDirectory(), "weather-cal-preferences-" + Script.name()), '{"widget":{"name":"Overall settings","locale":"","units":"imperial","preview":"large","padding":"5","widgetPadding":{"top":"","left":"","bottom":"","right":""},"tintIcons":false},"localization":{"name":"Localization and text customization","morningGreeting":"Good morning.","afternoonGreeting":"Good afternoon.","eveningGreeting":"Good evening.","nightGreeting":"Good night.","nextHourLabel":"Next hour","tomorrowLabel":"Tomorrow","noEventMessage":"Enjoy the rest of your day.","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":"ffffff","font":"regular"},"smallDate":{"size":"17","color":"","font":"semibold"},"largeDate1":{"size":"30","color":"","font":"light"},"largeDate2":{"size":"30","color":"","font":"light"},"greeting":{"size":"30","color":"","font":"semibold"},"eventLabel":{"size":"14","color":"","font":"semibold"},"eventTitle":{"size":"14","color":"","font":"semibold"},"eventLocation":{"size":"14","color":"","font":""},"eventTime":{"size":"14","color":"ffffffcc","font":""},"noEvents":{"size":"30","color":"","font":"semibold"},"reminderTitle":{"size":"14","color":"","font":""},"reminderTime":{"size":"14","color":"ffffffcc","font":""},"noReminders":{"size":"30","color":"","font":"semibold"},"largeTemp":{"size":"34","color":"","font":"light"},"smallTemp":{"size":"14","color":"","font":""},"tinyTemp":{"size":"12","color":"","font":""},"customText":{"size":"14","color":"","font":""},"battery":{"size":"14","color":"","font":"medium"},"sunrise":{"size":"14","color":"","font":"medium"},"covid":{"size":"14","color":"","font":"medium"},"week":{"size":"14","color":"","font":"light"}},"date":{"name":"Date","dynamicDateSize":true,"staticDateSize":"small","smallDateFormat":"EEEE, MMMM d","largeDateLineOne":"EEEE,","largeDateLineTwo":"MMMM d"},"events":{"name":"Events","numberOfEvents":"3","minutesAfter":"5","showAllDay":false,"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":"3","showHoursFormat":"ha","horizontalForecast":true,"showDays":"3","showDaysFormat":"E","showToday":false,"urlCurrent":"","urlFuture":"","urlForecast":""},"covid":{"name":"COVID data","country":"USA","url":"https://covid19.who.int"}}')
- fm.writeString(fm.joinPath(fm.libraryDirectory(), "weather-cal-" + Script.name()), '{"type":"auto"}')
- let code = await new Request('https://raw.githubusercontent.com/mzeryck/Weather-Cal/main/weather-cal.js').loadString()
- let arr = code.split('`')
- arr[1] = `
- row
- column
- space
- date
- column(80)
- current
- row
- column
- space(15)
- sunrise
- battery
- events
- column(120)
- space(15)
- hourly
- row
- column
- space
- daily
- `
- alert = makeAlert("Close this script and re-run it to finish setup.",["OK"])
- fm.writeString(module.filename, arr.join('`'))
- await alert.present()
- }
- await importWidget()
- Script.complete()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement