Last active
September 4, 2022 17:04
-
-
Save anurag-roy/094a0a154a8c4b52bc50531aaf00ef27 to your computer and use it in GitHub Desktop.
"Pokémon of the Day" Widget for Scriptable
This file contains 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 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(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
References: PokeAPI