Skip to content

Instantly share code, notes, and snippets.

@mslepko

mslepko/updown_widget.js

Last active May 16, 2021
Embed
What would you like to do?
iOS Scriptable uptown.io Widget
const api_domain = "https://updown.io/api/"
const api_key = "INSERT_YOUR_API_KEY_HERE"
let w = new ListWidget() // Create the widget
w.backgroundColor = Color.clear() // add transparent background
//w.url= "https://url.com" // an url to open on click
async function getChecks() {
const response = new Request(api_domain + '/checks?api-key=' + api_key);
const checks = await response.loadJSON();
for(let item in checks){
let status = 'UP 😍'
let text_colour = Color.dynamic(Color.black(), Color.white())
if (checks[item].down) {
status = 'DOWN 😢'
text_colour = Color.red()
}
let page = checks[item].alias ? checks[item].alias : checks[item].url
let text = `${page} is ${status}`
t = w.addText(text) // Add the value to the widget
t.textColor = text_colour
t.font = new Font("SanFranciscoDisplay-Regular ", 24)
t.centerAlignText()
s = w.addSpacer(8)
}
return true
}
await getChecks()
Script.setWidget(w)
Script.complete()
@mslepko

This comment has been minimized.

Copy link
Owner Author

@mslepko mslepko commented Dec 30, 2020

site_up
site_down

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment