Update anime-sama/anime-sama.js
This commit is contained in:
+41
-27
@@ -1,45 +1,63 @@
|
|||||||
async function getActiveDomain() {
|
async function getDomainsList() {
|
||||||
try {
|
try {
|
||||||
const response = await fetchv2("https://anime-sama.pw/");
|
const response = await fetchv2("https://anime-sama.pw/");
|
||||||
const html = await response.text();
|
const html = await response.text();
|
||||||
|
|
||||||
const domainRegex = /<td class="domain-name">([^<]+)<\/td>[\s\S]*?<p class="hidden md:block">Actif<\/p>/;
|
const domainRegex = /{ name: '([^']+)' }/g;
|
||||||
const match = domainRegex.exec(html);
|
const domains = [];
|
||||||
|
let match;
|
||||||
if (match) {
|
while ((match = domainRegex.exec(html)) !== null) {
|
||||||
return match[1].trim();
|
domains.push(match[1]);
|
||||||
} else {
|
|
||||||
return "anime-sama.tv";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return domains.length > 0 ? domains : ["anime-sama.tv"];
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Failed to fetch active domain:", err);
|
return ["anime-sama.tv"];
|
||||||
// Fallback
|
|
||||||
return "anime-sama.tv";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function searchResults(keyword) {
|
async function searchResults(keyword) {
|
||||||
const results = [];
|
const domains = await getDomainsList();
|
||||||
const activeDomain = await getActiveDomain();
|
|
||||||
|
|
||||||
const headers = {
|
|
||||||
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
|
|
||||||
"X-Requested-With": "XMLHttpRequest",
|
|
||||||
"referer": `https://${activeDomain}/`
|
|
||||||
};
|
|
||||||
|
|
||||||
const regex = /<a[^>]+href="([^"]+)"[\s\S]*?<img[^>]+src="([^"]+)"[\s\S]*?<h3[^>]*>(.*?)<\/h3>/gi;
|
const regex = /<a[^>]+href="([^"]+)"[\s\S]*?<img[^>]+src="([^"]+)"[\s\S]*?<h3[^>]*>(.*?)<\/h3>/gi;
|
||||||
|
|
||||||
|
const firstDomain = domains[0];
|
||||||
|
const firstResult = await trySearch(firstDomain, keyword, regex);
|
||||||
|
if (firstResult && firstResult.length > 0) {
|
||||||
|
return JSON.stringify(firstResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
const otherDomains = domains.slice(1);
|
||||||
|
const promises = otherDomains.map(domain => trySearch(domain, keyword, regex));
|
||||||
|
const results = await Promise.all(promises);
|
||||||
|
|
||||||
|
for (let result of results) {
|
||||||
|
if (result && result.length > 0) {
|
||||||
|
return JSON.stringify(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return JSON.stringify([]);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function trySearch(domain, keyword, regex) {
|
||||||
try {
|
try {
|
||||||
|
const headers = {
|
||||||
|
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
|
||||||
|
"X-Requested-With": "XMLHttpRequest",
|
||||||
|
"referer": `https://${domain}/`
|
||||||
|
};
|
||||||
|
|
||||||
const response = await fetchv2(
|
const response = await fetchv2(
|
||||||
`https://${activeDomain}/template-php/defaut/fetch.php`,
|
`https://${domain}/template-php/defaut/fetch.php`,
|
||||||
headers,
|
headers,
|
||||||
"POST",
|
"POST",
|
||||||
`query=${encodeURIComponent(keyword)}`
|
`query=${encodeURIComponent(keyword)}`
|
||||||
);
|
);
|
||||||
const html = await response.text();
|
const html = await response.text();
|
||||||
|
|
||||||
|
const results = [];
|
||||||
let match;
|
let match;
|
||||||
|
regex.lastIndex = 0;
|
||||||
while ((match = regex.exec(html)) !== null) {
|
while ((match = regex.exec(html)) !== null) {
|
||||||
results.push({
|
results.push({
|
||||||
title: match[3].trim(),
|
title: match[3].trim(),
|
||||||
@@ -48,13 +66,9 @@ async function searchResults(keyword) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return JSON.stringify(results);
|
return results;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return JSON.stringify([{
|
return [];
|
||||||
title: "Error",
|
|
||||||
image: "Error",
|
|
||||||
href: "Error"
|
|
||||||
}]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user