Last active
November 16, 2020 16:48
-
-
Save stordahl/d5f2d2dba07dbeb25bce124d2e21d967 to your computer and use it in GitHub Desktop.
Simple Github Data Scriptable Widget for iOS14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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