mirror of
https://github.com/ThaUnknown/miru.git
synced 2026-04-21 11:52:02 +00:00
seach progress, shit's still fucked
This commit is contained in:
parent
0136ef9024
commit
020639fc91
1 changed files with 14 additions and 19 deletions
|
|
@ -238,46 +238,42 @@ const DOMPARSER = new DOMParser().parseFromString.bind(new DOMParser()),
|
||||||
searchTitle = document.querySelector("#title"),
|
searchTitle = document.querySelector("#title"),
|
||||||
searchEpisode = document.querySelector("#ep")
|
searchEpisode = document.querySelector("#ep")
|
||||||
|
|
||||||
|
async function nyaaSearch(media, episode) {
|
||||||
function nyaaSearch(media, episode) {
|
|
||||||
if (episode.length < 2) {
|
if (episode.length < 2) {
|
||||||
episode = `0${episode}`
|
episode = `0${episode}`
|
||||||
}
|
}
|
||||||
let titles = Object.values(media.title).concat(media.synonyms).filter(name => name != null),
|
let titles = Object.values(media.title).concat(media.synonyms).filter(name => name != null),
|
||||||
table = document.querySelector("tbody.tsearch"),
|
table = document.querySelector("tbody.tsearch"),
|
||||||
results = document.createDocumentFragment()
|
results
|
||||||
|
|
||||||
titles.forEach(title => {
|
for (let title of titles) {
|
||||||
console.log(results.childNodes)
|
if (results == undefined) {
|
||||||
console.log(results.childNodes.length)
|
|
||||||
if (results.children.length == 0) {
|
|
||||||
let url = new URL(`https://nyaa.si/?page=rss&c=1_2&f=2&s=seeders&o=desc&q=${title}" ${episode} "`)
|
let url = new URL(`https://nyaa.si/?page=rss&c=1_2&f=2&s=seeders&o=desc&q=${title}" ${episode} "`)
|
||||||
rssFetch(url, (frag) => {
|
results = await rssFetch(url)
|
||||||
results = frag
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
if (results.children.length == 0) {
|
};
|
||||||
|
if (results == undefined) {
|
||||||
halfmoon.initStickyAlert({
|
halfmoon.initStickyAlert({
|
||||||
content: `Couldn't find torrent for ${!!media.title.english ? media.title.english : media.title.romaji}! Try specifying a torrent manually.`,
|
content: `Couldn't find torrent for ${!!media.title.english ? media.title.english : media.title.romaji}! Try specifying a torrent manually.`,
|
||||||
title: "Search Failed",
|
title: "Search Failed",
|
||||||
alertType: "alert-danger",
|
alertType: "alert-danger",
|
||||||
fillType: ""
|
fillType: ""
|
||||||
});
|
});
|
||||||
console.log("F")
|
|
||||||
} else {
|
} else {
|
||||||
table.textContent = "";
|
table.textContent = "";
|
||||||
table.appendChild(results)
|
table.appendChild(results)
|
||||||
halfmoon.toggleModal("tsearch")
|
halfmoon.toggleModal("tsearch")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function rssFetch(url, callback) {
|
async function rssFetch(url) {
|
||||||
let frag = document.createDocumentFragment()
|
var frag
|
||||||
fetch(url).then((res) => {
|
await fetch(url).then((res) => {
|
||||||
res.text().then((xmlTxt) => {
|
res.text().then((xmlTxt) => {
|
||||||
try {
|
try {
|
||||||
let doc = DOMPARSER(xmlTxt, "text/xml")
|
let doc = DOMPARSER(xmlTxt, "text/xml")
|
||||||
if (doc.querySelectorAll("item").length != 0) {
|
if (doc.querySelectorAll("item").length != 0) {
|
||||||
|
frag = document.createDocumentFragment()
|
||||||
doc.querySelectorAll("item").forEach((item, index) => {
|
doc.querySelectorAll("item").forEach((item, index) => {
|
||||||
let i = item.querySelector.bind(item),
|
let i = item.querySelector.bind(item),
|
||||||
template = document.createElement("tr")
|
template = document.createElement("tr")
|
||||||
|
|
@ -298,9 +294,8 @@ function rssFetch(url, callback) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}).catch(() => console.error("Error in fetching the RSS feed"))
|
}).catch(() => console.error("Error in fetching the RSS feed"))
|
||||||
if (callback) {
|
console.log(frag)
|
||||||
callback(frag)
|
return frag
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
alRequest()
|
alRequest()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue