fixed script & headless
This commit is contained in:
14
binding.gyp
14
binding.gyp
@@ -1,14 +0,0 @@
|
|||||||
{
|
|
||||||
"targets": [
|
|
||||||
{
|
|
||||||
"target_name": "anime_core",
|
|
||||||
"cflags!": [ "-fno-exceptions" ],
|
|
||||||
"cflags_cc!": [ "-fno-exceptions" ],
|
|
||||||
"sources": [ "./src/main.cpp" ],
|
|
||||||
"include_dirs": [
|
|
||||||
"<!@(node -p \"require('node-addon-api').include\")"
|
|
||||||
],
|
|
||||||
"defines": [ "NAPI_DISABLE_CPP_EXCEPTIONS" ]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,320 +1,194 @@
|
|||||||
const API_BASE = '/api';
|
let trendingAnimes = [];
|
||||||
let currentList = [];
|
let currentHeroIndex = 0;
|
||||||
let filteredList = [];
|
let player;
|
||||||
|
let heroInterval;
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', async () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
await loadList();
|
SearchManager.init('#search-input', '#search-results', 'anime');
|
||||||
setupEventListeners();
|
ContinueWatchingManager.load('my-status', 'watching', 'ANIME');
|
||||||
|
fetchContent();
|
||||||
|
setInterval(() => fetchContent(true), 60000);
|
||||||
});
|
});
|
||||||
|
|
||||||
function getEntryLink(item) {
|
document.addEventListener('click', (e) => {
|
||||||
const isAnime = item.entry_type?.toUpperCase() === 'ANIME';
|
if (!e.target.closest('.search-wrapper')) {
|
||||||
const baseRoute = isAnime ? '/anime' : '/book';
|
const searchResults = document.getElementById('search-results');
|
||||||
const source = item.source || 'anilist';
|
const searchInput = document.getElementById('search-input');
|
||||||
|
searchResults.classList.remove('active');
|
||||||
|
searchInput.style.borderRadius = '99px';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (source === 'anilist') {
|
function scrollCarousel(id, direction) {
|
||||||
return `${baseRoute}/${item.entry_id}`;
|
const container = document.getElementById(id);
|
||||||
} else {
|
if(container) {
|
||||||
return `${baseRoute}/${source}/${item.entry_id}`;
|
const scrollAmount = container.clientWidth * 0.75;
|
||||||
|
container.scrollBy({ left: direction * scrollAmount, behavior: 'smooth' });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function populateSourceFilter() {
|
var tag = document.createElement('script');
|
||||||
const select = document.getElementById('source-filter');
|
tag.src = "https://www.youtube.com/iframe_api";
|
||||||
if (!select) return;
|
var firstScriptTag = document.getElementsByTagName('script')[0];
|
||||||
|
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
|
||||||
|
|
||||||
select.innerHTML = `
|
function onYouTubeIframeAPIReady() {
|
||||||
<option value="all">All Sources</option>
|
player = new YT.Player('player', {
|
||||||
<option value="anilist">AniList</option>
|
height: '100%',
|
||||||
`;
|
width: '100%',
|
||||||
|
playerVars: {
|
||||||
try {
|
'autoplay': 1,
|
||||||
const response = await fetch(`${API_BASE}/extensions`);
|
'controls': 0,
|
||||||
if (response.ok) {
|
'mute': 1,
|
||||||
const data = await response.json();
|
'loop': 1,
|
||||||
const extensions = data.extensions || [];
|
'showinfo': 0,
|
||||||
|
'modestbranding': 1
|
||||||
extensions.forEach(extName => {
|
},
|
||||||
if (extName.toLowerCase() !== 'anilist' && extName.toLowerCase() !== 'local') {
|
events: {
|
||||||
const option = document.createElement('option');
|
'onReady': (e) => {
|
||||||
option.value = extName;
|
e.target.mute();
|
||||||
option.textContent = extName.charAt(0).toUpperCase() + extName.slice(1);
|
if(trendingAnimes.length) updateHeroVideo(trendingAnimes[currentHeroIndex]);
|
||||||
select.appendChild(option);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error loading extensions:', error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function setupEventListeners() {
|
|
||||||
|
|
||||||
document.querySelectorAll('.view-btn').forEach(btn => {
|
|
||||||
btn.addEventListener('click', () => {
|
|
||||||
document.querySelectorAll('.view-btn').forEach(b => b.classList.remove('active'));
|
|
||||||
btn.classList.add('active');
|
|
||||||
const view = btn.dataset.view;
|
|
||||||
const container = document.getElementById('list-container');
|
|
||||||
if (view === 'list') {
|
|
||||||
container.classList.add('list-view');
|
|
||||||
} else {
|
|
||||||
container.classList.remove('list-view');
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
document.getElementById('status-filter').addEventListener('change', applyFilters);
|
|
||||||
document.getElementById('source-filter').addEventListener('change', applyFilters);
|
|
||||||
document.getElementById('type-filter').addEventListener('change', applyFilters);
|
|
||||||
document.getElementById('sort-filter').addEventListener('change', applyFilters);
|
|
||||||
|
|
||||||
document.querySelector('.search-input').addEventListener('input', (e) => {
|
|
||||||
const query = e.target.value.toLowerCase();
|
|
||||||
if (query) {
|
|
||||||
filteredList = currentList.filter(item =>
|
|
||||||
item.title?.toLowerCase().includes(query)
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
filteredList = [...currentList];
|
|
||||||
}
|
|
||||||
applyFilters();
|
|
||||||
});
|
|
||||||
|
|
||||||
document.getElementById('modal-save-btn')?.addEventListener('click', async () => {
|
|
||||||
|
|
||||||
const entryToSave = window.ListModalManager.currentEntry || window.ListModalManager.currentData;
|
|
||||||
|
|
||||||
if (!entryToSave) return;
|
|
||||||
|
|
||||||
await window.ListModalManager.save(entryToSave.entry_id, entryToSave.source);
|
|
||||||
|
|
||||||
await loadList();
|
|
||||||
});
|
|
||||||
|
|
||||||
document.getElementById('modal-delete-btn')?.addEventListener('click', async () => {
|
|
||||||
const entryToDelete = window.ListModalManager.currentEntry || window.ListModalManager.currentData;
|
|
||||||
|
|
||||||
if (!entryToDelete) return;
|
|
||||||
|
|
||||||
await window.ListModalManager.delete(entryToDelete.entry_id, entryToDelete.source);
|
|
||||||
|
|
||||||
await loadList();
|
|
||||||
});
|
|
||||||
|
|
||||||
document.getElementById('add-list-modal')?.addEventListener('click', (e) => {
|
|
||||||
if (e.target.id === 'add-list-modal') {
|
|
||||||
window.ListModalManager.close();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadList() {
|
async function fetchContent(isUpdate = false) {
|
||||||
const loadingState = document.getElementById('loading-state');
|
|
||||||
const emptyState = document.getElementById('empty-state');
|
|
||||||
const container = document.getElementById('list-container');
|
|
||||||
|
|
||||||
await populateSourceFilter();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
loadingState.style.display = 'flex';
|
const trendingRes = await fetch('/api/trending');
|
||||||
emptyState.style.display = 'none';
|
const trendingData = await trendingRes.json();
|
||||||
container.innerHTML = '';
|
|
||||||
|
|
||||||
const response = await fetch(`${API_BASE}/list`, {
|
if (trendingData.results && trendingData.results.length > 0) {
|
||||||
headers: window.AuthUtils.getSimpleAuthHeaders()
|
trendingAnimes = trendingData.results;
|
||||||
});
|
if (!isUpdate) {
|
||||||
|
updateHeroUI(trendingAnimes[0]);
|
||||||
if (!response.ok) {
|
startHeroCycle();
|
||||||
throw new Error('Failed to load list');
|
}
|
||||||
|
renderList('trending', trendingAnimes);
|
||||||
|
} else if (!isUpdate) {
|
||||||
|
setTimeout(() => fetchContent(false), 2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await response.json();
|
const topRes = await fetch('/api/top-airing');
|
||||||
currentList = data.results || [];
|
const topData = await topRes.json();
|
||||||
filteredList = [...currentList];
|
if (topData.results && topData.results.length > 0) {
|
||||||
|
renderList('top-airing', topData.results);
|
||||||
loadingState.style.display = 'none';
|
|
||||||
|
|
||||||
if (currentList.length === 0) {
|
|
||||||
emptyState.style.display = 'flex';
|
|
||||||
} else {
|
|
||||||
updateStats();
|
|
||||||
applyFilters();
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error loading list:', error);
|
|
||||||
loadingState.style.display = 'none';
|
|
||||||
if (window.NotificationUtils) {
|
|
||||||
window.NotificationUtils.error('Failed to load your list. Please try again.');
|
|
||||||
} else {
|
|
||||||
alert('Failed to load your list. Please try again.');
|
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Fetch Error:", e);
|
||||||
|
if(!isUpdate) setTimeout(() => fetchContent(false), 5000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateStats() {
|
function startHeroCycle() {
|
||||||
const total = currentList.length;
|
if(heroInterval) clearInterval(heroInterval);
|
||||||
const watching = currentList.filter(item => item.status === 'WATCHING').length;
|
heroInterval = setInterval(() => {
|
||||||
const completed = currentList.filter(item => item.status === 'COMPLETED').length;
|
if(trendingAnimes.length > 0) {
|
||||||
const planning = currentList.filter(item => item.status === 'PLANNING').length;
|
currentHeroIndex = (currentHeroIndex + 1) % trendingAnimes.length;
|
||||||
|
updateHeroUI(trendingAnimes[currentHeroIndex]);
|
||||||
document.getElementById('total-count').textContent = total;
|
}
|
||||||
document.getElementById('watching-count').textContent = watching;
|
}, 10000);
|
||||||
document.getElementById('completed-count').textContent = completed;
|
|
||||||
document.getElementById('planned-count').textContent = planning;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function applyFilters() {
|
async function updateHeroUI(anime) {
|
||||||
const statusFilter = document.getElementById('status-filter').value;
|
if(!anime) return;
|
||||||
const sourceFilter = document.getElementById('source-filter').value;
|
|
||||||
const typeFilter = document.getElementById('type-filter').value;
|
|
||||||
const sortFilter = document.getElementById('sort-filter').value;
|
|
||||||
|
|
||||||
let filtered = [...filteredList];
|
const title = anime.title.english || anime.title.romaji || "Unknown Title";
|
||||||
|
const score = anime.averageScore ? anime.averageScore + '% Match' : 'N/A';
|
||||||
|
const year = anime.seasonYear || '';
|
||||||
|
const type = anime.format || 'TV';
|
||||||
|
const desc = anime.description || 'No description available.';
|
||||||
|
const poster = anime.coverImage ? anime.coverImage.extraLarge : '';
|
||||||
|
const banner = anime.bannerImage || poster;
|
||||||
|
|
||||||
if (statusFilter !== 'all') {
|
document.getElementById('hero-title').innerText = title;
|
||||||
filtered = filtered.filter(item => item.status === statusFilter);
|
document.getElementById('hero-desc').innerHTML = desc;
|
||||||
|
document.getElementById('hero-score').innerText = score;
|
||||||
|
document.getElementById('hero-year').innerText = year;
|
||||||
|
document.getElementById('hero-type').innerText = type;
|
||||||
|
document.getElementById('hero-poster').src = poster;
|
||||||
|
|
||||||
|
const watchBtn = document.getElementById('watch-btn');
|
||||||
|
if(watchBtn) watchBtn.onclick = () => window.location.href = `/anime/${anime.id}`;
|
||||||
|
|
||||||
|
const addToListBtn = document.querySelector('.hero-buttons .btn-blur');
|
||||||
|
if(addToListBtn) {
|
||||||
|
ListModalManager.currentData = anime;
|
||||||
|
const entryType = ListModalManager.getEntryType(anime);
|
||||||
|
|
||||||
|
await ListModalManager.checkIfInList(anime.id, 'anilist', entryType);
|
||||||
|
ListModalManager.updateButton();
|
||||||
|
|
||||||
|
addToListBtn.onclick = () => ListModalManager.open(anime, 'anilist');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sourceFilter !== 'all') {
|
const bgImg = document.getElementById('hero-bg-media');
|
||||||
filtered = filtered.filter(item => item.source === sourceFilter);
|
if(bgImg && bgImg.src !== banner) bgImg.src = banner;
|
||||||
}
|
|
||||||
|
|
||||||
if (typeFilter !== 'all') {
|
updateHeroVideo(anime);
|
||||||
filtered = filtered.filter(item => item.entry_type === typeFilter);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (sortFilter) {
|
document.getElementById('hero-loading-ui').style.display = 'none';
|
||||||
case 'title':
|
document.getElementById('hero-real-ui').style.display = 'block';
|
||||||
filtered.sort((a, b) => (a.title || '').localeCompare(b.title || ''));
|
|
||||||
break;
|
|
||||||
case 'score':
|
|
||||||
filtered.sort((a, b) => (b.score || 0) - (a.score || 0));
|
|
||||||
break;
|
|
||||||
case 'progress':
|
|
||||||
filtered.sort((a, b) => (b.progress || 0) - (a.progress || 0));
|
|
||||||
break;
|
|
||||||
case 'updated':
|
|
||||||
default:
|
|
||||||
filtered.sort((a, b) => new Date(b.updated_at) - new Date(a.updated_at));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
renderList(filtered);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderList(items) {
|
function updateHeroVideo(anime) {
|
||||||
const container = document.getElementById('list-container');
|
if (!player || !player.loadVideoById) return;
|
||||||
container.innerHTML = '';
|
const videoContainer = document.getElementById('player');
|
||||||
|
if (anime.trailer && anime.trailer.site === 'youtube' && anime.trailer.id) {
|
||||||
|
if(player.getVideoData && player.getVideoData().video_id !== anime.trailer.id) {
|
||||||
|
player.loadVideoById(anime.trailer.id);
|
||||||
|
player.mute();
|
||||||
|
}
|
||||||
|
videoContainer.style.opacity = "1";
|
||||||
|
} else {
|
||||||
|
videoContainer.style.opacity = "0";
|
||||||
|
player.stopVideo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (items.length === 0) {
|
function renderList(id, list) {
|
||||||
container.innerHTML = '<div class="empty-state"><p>No entries match your filters</p></div>';
|
const container = document.getElementById(id);
|
||||||
|
const firstId = list.length > 0 ? list[0].id : null;
|
||||||
|
const currentFirstId = container.firstElementChild?.dataset?.id;
|
||||||
|
if (currentFirstId && parseInt(currentFirstId) === firstId && container.children.length === list.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
items.forEach(item => {
|
container.innerHTML = '';
|
||||||
const element = createListItem(item);
|
list.forEach(anime => {
|
||||||
container.appendChild(element);
|
const title = anime.title.english || anime.title.romaji || "Unknown Title";
|
||||||
});
|
const cover = anime.coverImage ? anime.coverImage.large : '';
|
||||||
}
|
const ep = anime.nextAiringEpisode ? 'Ep ' + anime.nextAiringEpisode.episode : (anime.episodes ? anime.episodes + ' Eps' : 'TV');
|
||||||
|
const score = anime.averageScore || '--';
|
||||||
|
|
||||||
function createListItem(item) {
|
const el = document.createElement('div');
|
||||||
const div = document.createElement('div');
|
el.className = 'card';
|
||||||
div.className = 'list-item';
|
el.dataset.id = anime.id;
|
||||||
|
|
||||||
const itemLink = getEntryLink(item);
|
el.onclick = () => window.location.href = `/anime/${anime.id}`;
|
||||||
|
el.innerHTML = `
|
||||||
const posterUrl = item.poster || '/public/assets/placeholder.png';
|
<div class="card-img-wrap"><img src="${cover}" loading="lazy"></div>
|
||||||
const progress = item.progress || 0;
|
<div class="card-content">
|
||||||
|
<h3>${title}</h3>
|
||||||
const totalUnits = item.entry_type === 'ANIME' ?
|
<p>${score}% • ${ep}</p>
|
||||||
item.total_episodes || 0 :
|
|
||||||
item.total_chapters || 0;
|
|
||||||
|
|
||||||
const progressPercent = totalUnits > 0 ? (progress / totalUnits) * 100 : 0;
|
|
||||||
const score = item.score ? item.score.toFixed(1) : null;
|
|
||||||
const repeatCount = item.repeat_count || 0;
|
|
||||||
|
|
||||||
const entryType = (item.entry_type).toUpperCase();
|
|
||||||
let unitLabel = 'units';
|
|
||||||
if (entryType === 'ANIME') {
|
|
||||||
unitLabel = 'episodes';
|
|
||||||
} else if (entryType === 'MANGA') {
|
|
||||||
unitLabel = 'chapters';
|
|
||||||
} else if (entryType === 'NOVEL') {
|
|
||||||
unitLabel = 'chapters/volumes';
|
|
||||||
}
|
|
||||||
|
|
||||||
const statusLabels = {
|
|
||||||
'WATCHING': entryType === 'ANIME' ? 'Watching' : 'Reading',
|
|
||||||
'COMPLETED': 'Completed',
|
|
||||||
'PLANNING': 'Planning',
|
|
||||||
'PAUSED': 'Paused',
|
|
||||||
'DROPPED': 'Dropped'
|
|
||||||
};
|
|
||||||
|
|
||||||
const extraInfo = [];
|
|
||||||
if (repeatCount > 0) {
|
|
||||||
extraInfo.push(`<span class="meta-pill repeat-pill">🔁 ${repeatCount}</span>`);
|
|
||||||
}
|
|
||||||
if (item.is_private) {
|
|
||||||
extraInfo.push('<span class="meta-pill private-pill">🔒 Private</span>');
|
|
||||||
}
|
|
||||||
|
|
||||||
const entryDataString = JSON.stringify(item).replace(/'/g, ''');
|
|
||||||
|
|
||||||
div.innerHTML = `
|
|
||||||
<a href="${itemLink}" class="item-poster-link">
|
|
||||||
<img src="${posterUrl}" alt="${item.title || 'Entry'}" class="item-poster" onerror="this.src='/public/assets/placeholder.png'">
|
|
||||||
</a>
|
|
||||||
<div class="item-content">
|
|
||||||
<div>
|
|
||||||
<a href="${itemLink}" style="text-decoration:none; color:inherit;">
|
|
||||||
<h3 class="item-title">${item.title || 'Unknown Title'}</h3>
|
|
||||||
</a>
|
|
||||||
<div class="item-meta">
|
|
||||||
<span class="meta-pill status-pill">${statusLabels[item.status] || item.status}</span>
|
|
||||||
<span class="meta-pill type-pill">${entryType}</span>
|
|
||||||
<span class="meta-pill source-pill">${item.source.toUpperCase()}</span>
|
|
||||||
${extraInfo.join('')}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
|
||||||
<div class="progress-bar-container">
|
|
||||||
<div class="progress-bar" style="width: ${progressPercent}%"></div>
|
|
||||||
</div>
|
|
||||||
<div class="progress-text">
|
|
||||||
<span>${progress}${totalUnits > 0 ? ` / ${totalUnits}` : ''} ${unitLabel}</span> ${score ? `<span class="score-badge">⭐ ${score}</span>` : ''}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button class="edit-icon-btn" data-entry='${entryDataString}'>
|
|
||||||
<svg width="20" height="20" fill="none" stroke="currentColor" stroke-width="2.5" viewBox="0 0 24 24">
|
|
||||||
<path d="M15.232 5.232l3.536 3.536m-2.036-5.808a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.536L15.232 5.232z"/>
|
|
||||||
</svg>
|
|
||||||
</button>
|
|
||||||
`;
|
`;
|
||||||
|
container.appendChild(el);
|
||||||
const editBtn = div.querySelector('.edit-icon-btn');
|
|
||||||
editBtn.addEventListener('click', (e) => {
|
|
||||||
try {
|
|
||||||
const entryData = JSON.parse(e.currentTarget.dataset.entry);
|
|
||||||
|
|
||||||
window.ListModalManager.isInList = true;
|
|
||||||
window.ListModalManager.currentEntry = entryData;
|
|
||||||
window.ListModalManager.currentData = entryData;
|
|
||||||
|
|
||||||
window.ListModalManager.open(entryData, entryData.source);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error parsing entry data for modal:', error);
|
|
||||||
|
|
||||||
if (window.NotificationUtils) {
|
|
||||||
window.NotificationUtils.error('Could not open modal. Check HTML form IDs.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
return div;
|
|
||||||
|
function saveToList() {
|
||||||
|
const animeId = ListModalManager.currentData ? ListModalManager.currentData.id : null;
|
||||||
|
if (!animeId) return;
|
||||||
|
ListModalManager.save(animeId, 'anilist');
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteFromList() {
|
||||||
|
const animeId = ListModalManager.currentData ? ListModalManager.currentData.id : null;
|
||||||
|
if (!animeId) return;
|
||||||
|
ListModalManager.delete(animeId, 'anilist');
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeAddToListModal() {
|
||||||
|
ListModalManager.close();
|
||||||
}
|
}
|
||||||
@@ -70,7 +70,6 @@ async function scrape(url, handler, options = {}) {
|
|||||||
const type = req.resourceType();
|
const type = req.resourceType();
|
||||||
if (
|
if (
|
||||||
type === "font" ||
|
type === "font" ||
|
||||||
type === "stylesheet" ||
|
|
||||||
type === "media" ||
|
type === "media" ||
|
||||||
type === "manifest"
|
type === "manifest"
|
||||||
) return route.abort();
|
) return route.abort();
|
||||||
|
|||||||
Reference in New Issue
Block a user