// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: deep-blue; icon-glyph: book;
// This script shows a random Scriptable API in a widget. The
script is meant to be used with a widget configured on the Home
Screen.
// You can run the script in the app to preview the widget or
you can go to the Home Screen, add a new Scriptable widget and
configure the widget to run this script.
// You can also try creating a shortcut that runs this script.
Running the shortcut will show widget.
let api = await randomAPI()
let widget = await createWidget(api)
if ([Link]) {
// The script runs inside a widget, so we pass our instance
of ListWidget to be shown inside the widget on the Home Screen.
[Link](widget)
} else {
// The script runs inside the app, so we preview the widget.
[Link]()
}
// Calling [Link]() signals to Scriptable that the
script have finished running.
// This can speed up the execution, in particular when running
the script from Shortcuts or using Siri.
[Link]()
async function createWidget(api) {
let appIcon = await loadAppIcon()
let title = "Random Scriptable API"
let widget = new ListWidget()
// Add background gradient
let gradient = new LinearGradient()
[Link] = [0, 1]
[Link] = [
new Color("141414"),
new Color("13233F")
]
[Link] = gradient
// Show app icon and title
let titleStack = [Link]()
let appIconElement = [Link](appIcon)
[Link] = new Size(15, 15)
[Link] = 4
[Link](4)
let titleElement = [Link](title)
[Link] = [Link]()
[Link] = 0.7
[Link] = [Link](13)
[Link](12)
// Show API
let nameElement = [Link]([Link])
[Link] = [Link]()
[Link] = [Link](18)
[Link](2)
let descriptionElement = [Link]([Link])
[Link] = 0.5
[Link] = [Link]()
[Link] = [Link](18)
// UI presented in Siri ans Shortcuta is non-interactive, so
we only show the footer when not running the script from Siri.
if (![Link]) {
[Link](8)
// Add button to open documentation
let linkSymbol = [Link]("[Link]")
let footerStack = [Link]()
let linkStack = [Link]()
[Link]()
[Link] = [Link]
let linkElement = [Link]("Read more")
[Link] = [Link](13)
[Link] = [Link]()
[Link](3)
let linkSymbolElement =
[Link]([Link])
[Link] = new Size(11, 11)
[Link] = [Link]()
[Link]()
// Add link to documentation
let docsSymbol = [Link]("book")
let docsElement = [Link]([Link])
[Link] = new Size(20, 20)
[Link] = [Link]()
[Link] = 0.5
[Link] = "[Link]
}
return widget
}
async function randomAPI() {
let docs = await loadDocs()
let apiNames = [Link](docs)
let num = [Link]([Link]() * [Link])
let apiName = apiNames[num]
let api = docs[apiName]
return {
name: apiName,
description: api["!doc"],
url: api["!url"]
}
}
async function loadDocs() {
let url = "[Link]
let req = new Request(url)
return await [Link]()
}
async function loadAppIcon() {
let url = "[Link]
Purple124/v4/21/1e/13/211e13de-2e74-4221-f7db-d6d2c53b4323/
AppIcon-1x_U007emarketing-[Link]/[Link]"
let req = new Request(url)
return [Link]()
}