Random Roblox API widget for iOS

Yesterday I made a widget for iOS in Scriptable,


It’s really cool and it shows me all these cool old Roblox features that I never heard of.

Source code
let api = await randomAPI()
let widget = await createWidget(api)
if (config.runsInWidget) {
  
  Script.setWidget(widget)
} else {
  
  widget.presentMedium()
}

Script.complete()

async function createWidget(api) {
  let appIcon = await loadAppIcon()
  let title = "Random Roblox API"
  let widget = new ListWidget()
  // Add background gradient
  let gradient = new LinearGradient()
  gradient.locations = [0, 1]
  gradient.colors = [
    new Color("141414"),
    new Color("13233F")
  ]
  widget.backgroundGradient = gradient
  // Show app icon and title
  let titleStack = widget.addStack()
  let appIconElement = titleStack.addImage(appIcon)
  appIconElement.imageSize = new Size(15, 15)
  appIconElement.cornerRadius = 4
  titleStack.addSpacer(4)
  let titleElement = titleStack.addText(title)
  titleElement.textColor = Color.white()
  titleElement.textOpacity = 0.7
  titleElement.font = Font.mediumSystemFont(13)
  widget.addSpacer(12)
  // Show API
  console.log(api)
  let nameElement = widget.addText(api.name)
  nameElement.textColor = Color.white()
  nameElement.font = Font.boldSystemFont(18)
  widget.addSpacer(2)
  let descriptionElement = widget.addText(api.description)
  descriptionElement.minimumScaleFactor = 0.5
  descriptionElement.textColor = Color.white()
  descriptionElement.font = Font.systemFont(18)
  
  if (!config.runsWithSiri) {
    widget.addSpacer(8)
    // Add button to open documentation
    let linkSymbol = SFSymbol.named("arrow.up.forward")
    let footerStack = widget.addStack()
    let linkStack = footerStack.addStack()
    linkStack.centerAlignContent()
    linkStack.url = api.url
    let linkElement = linkStack.addText("Read more")
    linkElement.font = Font.mediumSystemFont(13)
    linkElement.textColor = Color.blue()
    linkStack.addSpacer(3)
    let linkSymbolElement = linkStack.addImage(linkSymbol.image)
    linkSymbolElement.imageSize = new Size(11, 11)
    linkSymbolElement.tintColor = Color.blue()
    footerStack.addSpacer()
    // Add link to documentation
    let docsSymbol = SFSymbol.named("book")
    let docsElement = footerStack.addImage(docsSymbol.image)
    docsElement.imageSize = new Size(20, 20)
    docsElement.tintColor = Color.white()
    docsElement.imageOpacity = 0.5
    docsElement.url = "https://developer.roblox.com"
  }
  return widget
}

async function randomAPI() {
  let docs = await loadDocs()
  let num = Math.round(Math.random() * docs.length)
  let apiName = docs[num]["Name"]
  let api = docs[num]
  var urlsub = ""
  if (api["type"] == "Class") {
     urlsub = "class"
  }else if (api["type"] == "Enum") {
    urlsub = "enum"
  }else{
    return randomAPI()
  }
  console.log(api["type"])
  return {
    name: apiName,
    description: "",
    url: "https://robloxapi.github.io/ref/"+urlsub+"/"+apiName+".html"
  }
}

async function loadDocs() {
  let url = "https://anaminus.github.io/rbx/json/api/latest.json"
  let req = new Request(url)
  return await req.loadJSON()
}

async function loadAppIcon() {
  let url = "https://devforum-uploads.s3.dualstack.us-east-2.amazonaws.com/uploads/original/4X/5/2/0/520b3f78b55eb1587d54eae0021a9ed3d4e625ee.png"
  let req = new Request(url)
  return req.loadImage()
}

1 Like