Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Tap the Share icon in the top right.
- Then tap "Copy" to copy all of this code.
- Now you can paste into a new script.
- */
- 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 < 4)) { 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":"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"}}')
- fm.writeString(fm.joinPath(fm.libraryDirectory(), "weather-cal-" + Script.name()), '{"type":"image"}')
- 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,
- left,
- date,
- greeting,
- column(90),
- right,
- current,
- row,
- column,
- left,
- daily,
- column(100)
- right,
- hourly,
- sunrise,
- row,
- column,
- space,
- right,
- reminders,
- left,
- events,
- `
- 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