forked from 50n50/sources
Update animelib/animelib.js
This commit is contained in:
+26
-5
@@ -1,21 +1,32 @@
|
||||
async function searchResults(keyword) {
|
||||
const results = [];
|
||||
try {
|
||||
const response = await fetchv2("https://hapi.hentaicdn.org/api/anime?fields[]=rate_avg&fields[]=rate&fields[]=releaseDate&q=" + keyword);
|
||||
const response = await fetchv2(
|
||||
"https://hapi.hentaicdn.org/api/anime?fields[]=rate_avg&fields[]=rate&fields[]=releaseDate&q=" + keyword
|
||||
);
|
||||
const json = await response.json();
|
||||
|
||||
if (json && Array.isArray(json.data)) {
|
||||
for (const item of json.data) {
|
||||
const title = item.eng_name || item.name || "Unknown";
|
||||
const image = item.cover?.default || item.cover?.thumbnail || "";
|
||||
|
||||
results.push({
|
||||
title: item.eng_name || item.name || "Unknown",
|
||||
image: "https://passthrough-worker.simplepostrequest.workers.dev/?simple=" + image + "&referer=https://animelib.org/",
|
||||
href: item.slug_url || item.slug || item.id
|
||||
title,
|
||||
image: "https://passthrough-worker.simplepostrequest.workers.dev/?simple=" +
|
||||
image +
|
||||
"&referer=https://animelib.org/",
|
||||
href: item.slug_url || item.slug || item.id,
|
||||
_score: scoreTitle(title, keyword)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return JSON.stringify(results);
|
||||
results.sort((a, b) => a._score - b._score);
|
||||
|
||||
return JSON.stringify(
|
||||
results.map(({ _score, ...rest }) => rest)
|
||||
);
|
||||
} catch (err) {
|
||||
return JSON.stringify([{
|
||||
title: err.message,
|
||||
@@ -25,6 +36,16 @@ async function searchResults(keyword) {
|
||||
}
|
||||
}
|
||||
|
||||
function scoreTitle(title, keyword) {
|
||||
const t = title.toLowerCase();
|
||||
const k = keyword.toLowerCase();
|
||||
|
||||
if (t === k) return 0;
|
||||
if (t.startsWith(k)) return 1;
|
||||
if (t.includes(k)) return 2;
|
||||
return 3;
|
||||
}
|
||||
|
||||
async function extractDetails(slug) {
|
||||
try {
|
||||
const response = await fetchv2(
|
||||
|
||||
Reference in New Issue
Block a user