1
0
forked from 50n50/sources

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
+38 -24
View File
@@ -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 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 = { const headers = {
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"X-Requested-With": "XMLHttpRequest", "X-Requested-With": "XMLHttpRequest",
"referer": `https://${activeDomain}/` "referer": `https://${domain}/`
}; };
const regex = /<a[^>]+href="([^"]+)"[\s\S]*?<img[^>]+src="([^"]+)"[\s\S]*?<h3[^>]*>(.*?)<\/h3>/gi;
try {
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"
}]);
} }
} }