Skip to content

Instantly share code, notes, and snippets.

@anurag-roy
Last active September 4, 2022 17:04
Show Gist options
  • Save anurag-roy/094a0a154a8c4b52bc50531aaf00ef27 to your computer and use it in GitHub Desktop.
Save anurag-roy/094a0a154a8c4b52bc50531aaf00ef27 to your computer and use it in GitHub Desktop.
"Pokémon of the Day" Widget for Scriptable
const pool = 151; // use the pool of your choice: 151 for Gen-1, etc.
const showName = false; // determines if the name of the Pokemon should be displayed or not
// Get data
const apiRequest = new Request(
`https://pokeapi.deno.dev/pokemon/potd?pool=${pool}`
);
const pokemon = await apiRequest.loadJSON();
const imageRequest = new Request(pokemon.imageUrl);
const image = await imageRequest.loadImage();
// Create widget
const widget = new ListWidget();
widget.backgroundColor = new Color(pokemon.color);
const widgetImage = widget.addImage(image);
widgetImage.centerAlignImage();
if (showName) {
const pokemonName = widget.addText(pokemon.name);
pokemonName.textColor = Color.white();
pokemonName.font = Font.systemFont(12);
pokemonName.centerAlignText();
}
widget.url = `https://pokemon.com/us/pokedex/${pokemon.id}`;
widget.setPadding(5, 5, 5, 5);
// Present widget
if (config.runsInWidget) {
Script.setWidget(widget);
Script.complete();
} else {
widget.presentSmall();
}
@anurag-roy
Copy link
Author

References: PokeAPI

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