Open search-cheatsheets in Script Kit

/*
# Open cheatsheet page in [cheatsheets.zip](https://www.cheatsheets.zip/)
*/
// Name: Open cheatsheet page in cheatsheets.zip
// Author: Ricardo Gonçalves Bassete
import '@johnlindquist/kit'
import { Choice } from '@johnlindquist/kit'
import * as cheerio from 'cheerio'
const baseURL = 'https://cheatsheets.zip'
const { data } = await get(baseURL)
const $ = cheerio.load(data)
const alreadyAdded = []
const items: Choice<string>[] = $('a')
.get()
.filter(a => $(a).attr('href').startsWith('/'))
.filter(a => $(a).attr('href') != '/')
.filter(a => {
const href = $(a).attr('href')
if (alreadyAdded.includes(href)) {
return false
} else {
alreadyAdded.push(href)
return true
}
})
.map(a => {
return {
value: `${baseURL}/${$(a).attr('href')}`,
name: $(a).find('p').text(),
}
})
const target = await arg('Select cheatsheet', items)
open(target)