async: 7 stages of grief

This commit is contained in:
ThaUnknown 2020-08-29 23:36:59 +02:00
parent 020639fc91
commit 4efdf3e2ab
2 changed files with 22 additions and 24 deletions

View file

@ -243,17 +243,19 @@ async function nyaaSearch(media, episode) {
episode = `0${episode}`
}
let titles = Object.values(media.title).concat(media.synonyms).filter(name => name != null),
table = document.querySelector("tbody.tsearch"),
results
table = document.querySelector("table.results"),
results = document.createElement("tbody")
for (let title of titles) {
if (results == undefined) {
console.log(results == "")
if (results.innerHTML == "") {
let url = new URL(`https://nyaa.si/?page=rss&c=1_2&f=2&s=seeders&o=desc&q=${title}" ${episode} "`)
results = await rssFetch(url)
console.log(results)
}
};
if (results == undefined) {
if (results.innerHTML == "") {
halfmoon.initStickyAlert({
content: `Couldn't find torrent for ${!!media.title.english ? media.title.english : media.title.romaji}! Try specifying a torrent manually.`,
title: "Search Failed",
@ -261,32 +263,30 @@ async function nyaaSearch(media, episode) {
fillType: ""
});
} else {
table.textContent = "";
console.log(results)
table.appendChild(results)
halfmoon.toggleModal("tsearch")
}
}
async function rssFetch(url) {
var frag
let template = document.createElement("tbody")
await fetch(url).then((res) => {
res.text().then((xmlTxt) => {
try {
let doc = DOMPARSER(xmlTxt, "text/xml")
if (doc.querySelectorAll("item").length != 0) {
frag = document.createDocumentFragment()
doc.querySelectorAll("item").forEach((item, index) => {
let i = item.querySelector.bind(item),
template = document.createElement("tr")
template.innerHTML = `
<th>${(index + 1)}</th>
<td>${i("title").textContent}</td>
<td>${i("size").textContent}</td>
<td>${i("seeders").textContent}</td>
<td>${i("leechers").textContent}</td>
<td>${i("downloads").textContent}</td>
<td onclick="addTorrent('${i('infoHash').textContent}')" class="pointer">Play</td>
`
frag.appendChild(template)
let i = item.querySelector.bind(item)
template.innerHTML += `
<tr>
<th>${(index + 1)}</th>
<td>${i("title").textContent}</td>
<td>${i("size").textContent}</td>
<td>${i("seeders").textContent}</td>
<td>${i("leechers").textContent}</td>
<td>${i("downloads").textContent}</td>
<td onclick="addTorrent('${i('infoHash').textContent}')" class="pointer">Play</td>
</tr>`
})
}
} catch (e) {
@ -294,8 +294,8 @@ async function rssFetch(url) {
}
})
}).catch(() => console.error("Error in fetching the RSS feed"))
console.log(frag)
return frag
console.log(template)
return template
}
alRequest()

View file

@ -23,7 +23,7 @@
<button class="close pointer" data-dismiss="modal" type="button" aria-label="Close">
<span>&times;</span>
</button>
<table class="table">
<table class="table results">
<thead>
<tr>
<th scope="col">#</th>
@ -35,8 +35,6 @@
<th scope="col">Play</th>
</tr>
</thead>
<tbody class="tsearch">
</tbody>
</table>
</div>
</div>