diff --git a/app/animeHandler.js b/app/animeHandler.js index 112129a..7984e04 100644 --- a/app/animeHandler.js +++ b/app/animeHandler.js @@ -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 = ` - ${(index + 1)} - ${i("title").textContent} - ${i("size").textContent} - ${i("seeders").textContent} - ${i("leechers").textContent} - ${i("downloads").textContent} - Play - ` - frag.appendChild(template) + let i = item.querySelector.bind(item) + template.innerHTML += ` + + ${(index + 1)} + ${i("title").textContent} + ${i("size").textContent} + ${i("seeders").textContent} + ${i("leechers").textContent} + ${i("downloads").textContent} + Play + ` }) } } 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() diff --git a/app/app.html b/app/app.html index 0500c42..13fea32 100644 --- a/app/app.html +++ b/app/app.html @@ -23,7 +23,7 @@ - +
@@ -35,8 +35,6 @@ - -
#Play