Update anime-sama/anime-sama.js

This commit is contained in:
aka paul
2026-01-30 16:52:00 +00:00
parent 7d4d3f90e9
commit 6661660310
+43 -29
View File
@@ -1,45 +1,63 @@
async function getActiveDomain() {
async function getDomainsList() {
try {
const response = await fetchv2("https://anime-sama.pw/");
const html = await response.text();
const domainRegex = /<td class="domain-name">([^<]+)<\/td>[\s\S]*?<p class="hidden md:block">Actif<\/p>/;
const match = domainRegex.exec(html);
if (match) {
return match[1].trim();
} else {
return "anime-sama.tv";
const domainRegex = /{ name: '([^']+)' }/g;
const domains = [];
let match;
while ((match = domainRegex.exec(html)) !== null) {
domains.push(match[1]);
}
return domains.length > 0 ? domains : ["anime-sama.tv"];
} catch (err) {
console.error("Failed to fetch active domain:", err);
// Fallback
return "anime-sama.tv";
return ["anime-sama.tv"];
}
}
async function searchResults(keyword) {
const results = [];
const activeDomain = await getActiveDomain();
const headers = {
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"X-Requested-With": "XMLHttpRequest",
"referer": `https://${activeDomain}/`
};
const domains = await getDomainsList();
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 {
const headers = {
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"X-Requested-With": "XMLHttpRequest",
"referer": `https://${domain}/`
};
const response = await fetchv2(
`https://${activeDomain}/template-php/defaut/fetch.php`,
`https://${domain}/template-php/defaut/fetch.php`,
headers,
"POST",
`query=${encodeURIComponent(keyword)}`
);
const html = await response.text();
const results = [];
let match;
regex.lastIndex = 0;
while ((match = regex.exec(html)) !== null) {
results.push({
title: match[3].trim(),
@@ -47,14 +65,10 @@ async function searchResults(keyword) {
href: match[1].trim()
});
}
return JSON.stringify(results);
return results;
} catch (err) {
return JSON.stringify([{
title: "Error",
image: "Error",
href: "Error"
}]);
return [];
}
}