async function getActiveDomain() { try { const response = await fetchv2("https://anime-sama.pw/"); const html = await response.text(); const domainRegex = /
Actif<\/p>/;
const match = domainRegex.exec(html);
if (match) {
return match[1].trim();
} else {
return "anime-sama.tv";
}
} catch (err) {
console.error("Failed to fetch active domain:", err);
// Fallback
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 regex = /]+href="([^"]+)"[\s\S]*? (.*?)<\/p>/is;
const match = regex.exec(html);
const description = match ? match[1].trim() : "N/A";
return JSON.stringify([{
description: description,
aliases: "N/A",
airdate: "N/A"
}]);
} catch (err) {
return JSON.stringify([{
description: "Error",
aliases: "Error",
airdate: "Error"
}]);
}
}
async function extractEpisodes(url) {
const results = [];
try {
const response = await fetchv2(url);
const html = await response.text();
const seasonRegex = /panneauAnime\("([^"]+)",\s*"([^"]+)"\);/g;
let match;
const seasonUrls = [];
while ((match = seasonRegex.exec(html)) !== null) {
const seasonHref = match[2].trim();
const fullSeasonUrl = url + '/' + seasonHref;
seasonUrls.push(fullSeasonUrl);
}
const seasonPromises = seasonUrls.map(seasonUrl => fetchv2(seasonUrl));
const seasonResponses = await Promise.all(seasonPromises);
for (let i = 0; i < seasonResponses.length; i++) {
const seasonResponse = seasonResponses[i];
const seasonHtml = await seasonResponse.text();
const seasonUrl = seasonUrls[i];
const episodeScriptRegex = /]+src="([^"]+)"[\s\S]*?
]*>(.*?)<\/h3>/gi;
try {
const response = await fetchv2(
`https://${activeDomain}/template-php/defaut/fetch.php`,
headers,
"POST",
`query=${encodeURIComponent(keyword)}`
);
const html = await response.text();
let match;
while ((match = regex.exec(html)) !== null) {
results.push({
title: match[3].trim(),
image: match[2].trim(),
href: match[1].trim()
});
}
return JSON.stringify(results);
} catch (err) {
return JSON.stringify([{
title: "Error",
image: "Error",
href: "Error"
}]);
}
}
async function extractDetails(url) {
try {
const response = await fetchv2(url);
const html = await response.text();
const regex = /