Anime Search - Working - Updated

Open anime-search in Script Kit

Updated Johns amazing script to work with the new v4 Api, and using widget instead of the deprecated showImage method.

Props to John for making all of this possible!

Original script

import "@johnlindquist/kit"
// Menu: Search Anime
// Description: Use the jikan.moe API to search anime
// Author: John Lindquist, Updated by Ambushfall
let anime = await arg("Anime:")
let response = await get(
`https://api.jikan.moe/v4/anime?q=${anime}`
)
let { images, title } = response.data.data[0]
let { jpg } = images
let { image_url, small_image_url, large_image_url } = jpg
const html = `<a :href="url">
<img :src="url" />
<div class="card__name">
<span>${title}</span>
</div>
</a>`;
let wg = await widget(html, {
state: {
url: large_image_url
}
})
wg.onResized(async () => {
wg.fit()
})
// win32 on-click not working so this does nothing really.
// TODO: When on click starts working change state to the next result
// wg.onClick((event) => event.targetId === "x" ? wg.close() : inspect(event.targetId));