Created
November 3, 2020 12:09
-
-
Save gangjun06/f6c1dc0099ae028ece1a4ed37c187889 to your computer and use it in GitHub Desktop.
Search Anime with ios scriptable and shortcuts
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 data = await Search(args.shortcutParameter) | |
await DisplaySelect(data.results) | |
const DetailHtml= (data) => (` | |
<html> | |
<head> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=3.0"> | |
<title>Anime Detail</title> | |
</head> | |
<body> | |
<ul> | |
<img alt="cover" src="${data.img}"/> | |
<li>제목: ${data.name}</li> | |
<li>방영시기: ${data.animation_info.air_year_quarter}</li> | |
<li>평점: ${data.avg_rating.toFixed(1)}</li> | |
<li>등급: ${data.content_rating}</li> | |
<li>줄거리: ${data.content}</li> | |
</ul> | |
<div> | |
<a href="https://laftel.net/item/${data.id}">라프텔</a> | |
<a href="https://namu.wiki/Search?q=${data.name}">나무위키</a> | |
</div> | |
</body> | |
</html> | |
`) | |
async function Search(keyword){ | |
const url = "https://laftel.net/api/search/v1/keyword/?keyword="+keyword | |
const req = new Request(url) | |
req.headers = { laftel: "TeJava" } | |
const data = await req.loadJSON() | |
return data | |
} | |
async function DisplaySelect(data){ | |
const table = new UITable() | |
data.forEach((item, index) => { | |
const row = new UITableRow() | |
const imageCell = UITableCell.imageAtURL(item.img) | |
imageCell.widthWeight = 1 | |
const textCell = UITableCell.text(item.name, item.genres.join(", ")) | |
textCell.widthWeight = 5 | |
row.addCell(imageCell) | |
row.addCell(textCell) | |
row.addText() | |
row.onSelect = (number) => SelectCallback(item.id) | |
table.addRow(row) | |
}) | |
table.present(false) | |
} | |
async function SelectCallback(id){ | |
const data = await FindDetail(id) | |
const webView = new WebView() | |
const html = DetailHtml(data) | |
await webView.loadHTML(html, "/") | |
webView.present(false) | |
} | |
async function FindDetail(id){ | |
const req = new Request(`https://laftel.net/api/v1.0/items/${id}/detail`) | |
req.headers = { laftel: "TeJava" } | |
const data = await req.loadJSON() | |
return data | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment