Skip to content

Instantly share code, notes, and snippets.

@stordahl
Last active November 16, 2020 16:48
Show Gist options
  • Save stordahl/d5f2d2dba07dbeb25bce124d2e21d967 to your computer and use it in GitHub Desktop.
Save stordahl/d5f2d2dba07dbeb25bce124d2e21d967 to your computer and use it in GitHub Desktop.
Simple Github Data Scriptable Widget for iOS14
const data = await getGithub()
const widget = createWidget()
Script.setWidget(widget)
Script.complete()
  
function createWidget(){
const w = new ListWidget()
w.backgroundColor = new Color('#1f1f1f')
w.useDefaultPadding()
const stack = w.addStack()
stack.layoutHorizontally()
stack.useDefaultPadding()
let image = stack.addImage(data.img)
let spacer = stack.addSpacer(15)
const substack = stack.addStack()
substack.layoutVertically()
substack.spacing = 5
substack.setPadding(1, 1, 1, 1)
substack.addSpacer(5)
image.cornerRadius = 37
const Line1 = substack.addText(`${data.res.name}`)
const Line2 = substack.addText(`Followers: ${data.res.followers}`)
const Line3 = substack.addText(`Repos: ${data.res.public_repos}`)
const Line4 = substack.addText(`${data.res.location}`)
return w;
}
async function getGithub(){
  const user = args.widgetParameter
  const url = `https://api.github.com/users/${user}`
  let r = new Request(url)
  const res = await r.loadJSON()
  console.log(res)
  const imgUrl = res.avatar_url
  const imgReq = new Request(imgUrl)
  const img = await imgReq.loadImage()
  return { res, img }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment