added anime entries from extensions
This commit is contained in:
@@ -10,9 +10,25 @@ tag.src = "https://www.youtube.com/iframe_api";
|
||||
var firstScriptTag = document.getElementsByTagName('script')[0];
|
||||
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
|
||||
|
||||
let extensionName;
|
||||
|
||||
async function loadAnime() {
|
||||
try {
|
||||
const res = await fetch(`/api/anime/${animeId}`);
|
||||
const path = window.location.pathname;
|
||||
const parts = path.split("/").filter(Boolean);
|
||||
let animeId;
|
||||
|
||||
if (parts.length === 3) {
|
||||
extensionName = parts[1];
|
||||
animeId = parts[2];
|
||||
} else {
|
||||
animeId = parts[1];
|
||||
}
|
||||
|
||||
const fetchUrl = extensionName
|
||||
? `/api/anime/${animeId.slice(0,40)}?ext=${extensionName}`
|
||||
: `/api/anime/${animeId}`;
|
||||
const res = await fetch(fetchUrl);
|
||||
const data = await res.json();
|
||||
|
||||
if(data.error) {
|
||||
@@ -35,6 +51,13 @@ async function loadAnime() {
|
||||
document.getElementById('genres').innerText = data.genres?.length > 0 ? data.genres.slice(0, 3).join(' • ') : '';
|
||||
document.getElementById('format').innerText = data.format || 'TV';
|
||||
document.getElementById('status').innerText = data.status || 'Unknown';
|
||||
const extensionPill = document.getElementById('extension-pill');
|
||||
if (extensionName && extensionPill) {
|
||||
extensionPill.textContent = `${extensionName.charAt(0).toUpperCase() + extensionName.slice(1).toLowerCase()}`;
|
||||
extensionPill.style.display = 'inline-flex';
|
||||
} else if (extensionPill) {
|
||||
extensionPill.style.display = 'none';
|
||||
}
|
||||
|
||||
let seasonText = '';
|
||||
if (data.season && data.seasonYear) {
|
||||
@@ -180,7 +203,9 @@ function createEpisodeButton(num, container) {
|
||||
const btn = document.createElement('div');
|
||||
btn.className = 'episode-btn';
|
||||
btn.innerText = `Ep ${num}`;
|
||||
btn.onclick = () => window.location.href = `/watch/${animeId}/${num}`;
|
||||
btn.onclick = () =>
|
||||
window.location.href = `/watch/${animeId}/${num}` + (extensionName ? `?${extensionName}` : "");
|
||||
|
||||
container.appendChild(btn);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ searchInput.addEventListener('input', (e) => {
|
||||
return;
|
||||
}
|
||||
searchTimeout = setTimeout(() => {
|
||||
fetchLocalSearch(query);
|
||||
fetchSearh(query);
|
||||
}, 300);
|
||||
});
|
||||
|
||||
@@ -23,14 +23,25 @@ document.addEventListener('click', (e) => {
|
||||
}
|
||||
});
|
||||
|
||||
async function fetchLocalSearch(query) {
|
||||
async function fetchSearh(query) {
|
||||
try {
|
||||
const res = await fetch(`/api/search/local?q=${encodeURIComponent(query)}`);
|
||||
const res = await fetch(`/api/search?q=${encodeURIComponent(query.slice(0, 30))}`);
|
||||
const data = await res.json();
|
||||
renderSearchResults(data.results);
|
||||
} catch (err) { console.error("Search Error:", err); }
|
||||
}
|
||||
|
||||
function createSlug(text) {
|
||||
if (!text) return '';
|
||||
return text
|
||||
.replace(/([a-z])([A-Z])/g, '$1 $2') // separa CamelCase
|
||||
.replace(/([a-z])(\d)/g, '$1 $2') // separa letras de números
|
||||
.toLowerCase()
|
||||
.trim()
|
||||
.replace(/[^a-z0-9\s-]/g, '')
|
||||
.replace(/[\s-]+/g, '-');
|
||||
}
|
||||
|
||||
function renderSearchResults(results) {
|
||||
searchResults.innerHTML = '';
|
||||
if (results.length === 0) {
|
||||
@@ -43,9 +54,24 @@ function renderSearchResults(results) {
|
||||
const year = anime.seasonYear || '';
|
||||
const format = anime.format || 'TV';
|
||||
|
||||
let href;
|
||||
|
||||
if (anime.isExtensionResult) {
|
||||
const titleSlug = createSlug(title);
|
||||
console.log(title);
|
||||
href = `/anime/${anime.extensionName}/${titleSlug}`;
|
||||
} else {
|
||||
href = `/anime/${anime.id}`;
|
||||
}
|
||||
|
||||
const extName = anime.extensionName?.charAt(0).toUpperCase() + anime.extensionName?.slice(1);
|
||||
const extPill = anime.isExtensionResult
|
||||
? `<span>• ${extName}</span>`
|
||||
: '';
|
||||
|
||||
const item = document.createElement('a');
|
||||
item.className = 'search-item';
|
||||
item.href = `/anime/${anime.id}`;
|
||||
item.href = href;
|
||||
item.innerHTML = `
|
||||
<img src="${img}" class="search-poster" alt="${title}">
|
||||
<div class="search-info">
|
||||
@@ -54,6 +80,7 @@ function renderSearchResults(results) {
|
||||
<span class="rating-pill">${rating}</span>
|
||||
<span>• ${year}</span>
|
||||
<span>• ${format}</span>
|
||||
${extPill}
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
@@ -7,7 +7,16 @@ let currentExtension = '';
|
||||
let plyrInstance;
|
||||
let hlsInstance;
|
||||
|
||||
document.getElementById('back-link').href = `/anime/${animeId}`;
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const firstKey = params.keys().next().value;
|
||||
let extName;
|
||||
if (firstKey) extName = firstKey;
|
||||
|
||||
const href = extName
|
||||
? `/anime/${extName}/${animeId}`
|
||||
: `/anime/${animeId}`;
|
||||
|
||||
document.getElementById('back-link').href = href;
|
||||
document.getElementById('episode-label').innerText = `Episode ${currentEpisode}`;
|
||||
|
||||
async function loadMetadata() {
|
||||
@@ -29,18 +38,26 @@ async function loadExtensions() {
|
||||
const select = document.getElementById('extension-select');
|
||||
|
||||
if (data.extensions && data.extensions.length > 0) {
|
||||
data.extensions.forEach(extName => {
|
||||
data.extensions.forEach(ext => {
|
||||
const opt = document.createElement('option');
|
||||
opt.value = extName;
|
||||
opt.innerText = extName;
|
||||
opt.value = opt.innerText = ext;
|
||||
select.appendChild(opt);
|
||||
});
|
||||
|
||||
if (data.extensions.includes(extName ?? "")) {
|
||||
select.value = extName;
|
||||
currentExtension = extName;
|
||||
onExtensionChange();
|
||||
}
|
||||
} else {
|
||||
select.innerHTML = '<option>No Extensions</option>';
|
||||
select.disabled = true;
|
||||
setLoading("No extensions found in WaifuBoards folder.");
|
||||
}
|
||||
} catch(e) { console.error("Extension Error:", e); }
|
||||
|
||||
} catch(e) {
|
||||
console.error("Extension Error:", e);
|
||||
}
|
||||
}
|
||||
|
||||
async function onExtensionChange() {
|
||||
@@ -114,7 +131,7 @@ async function loadStream() {
|
||||
setLoading(`Searching & Resolving Stream (${audioMode})...`);
|
||||
|
||||
try {
|
||||
const url = `/api/watch/stream?animeId=${animeId}&episode=${currentEpisode}&server=${server}&category=${audioMode}&ext=${currentExtension}`;
|
||||
const url = `/api/watch/stream?animeId=${animeId.slice(0, 30)}&episode=${currentEpisode}&server=${server}&category=${audioMode}&ext=${currentExtension}`;
|
||||
const res = await fetch(url);
|
||||
const data = await res.json();
|
||||
|
||||
@@ -199,11 +216,15 @@ function setLoading(msg) {
|
||||
text.innerText = msg;
|
||||
}
|
||||
|
||||
const extParam = extName ? `?${extName}` : "";
|
||||
document.getElementById('prev-btn').onclick = () => {
|
||||
if(currentEpisode > 1) window.location.href = `/watch/${animeId}/${currentEpisode - 1}`;
|
||||
if (currentEpisode > 1) {
|
||||
window.location.href = `/watch/${animeId}/${currentEpisode - 1}${extParam}`;
|
||||
}
|
||||
};
|
||||
|
||||
document.getElementById('next-btn').onclick = () => {
|
||||
window.location.href = `/watch/${animeId}/${currentEpisode + 1}`;
|
||||
window.location.href = `/watch/${animeId}/${currentEpisode + 1}${extParam}`;
|
||||
};
|
||||
if(currentEpisode <= 1) document.getElementById('prev-btn').disabled = true;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user