feat: new shadcn-style ui, code cleanup and better reliability
This commit is contained in:
parent
4027e37f26
commit
77b597e5d8
6 changed files with 1953 additions and 750 deletions
|
@ -13,6 +13,7 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||
let activeChannelId = null;
|
||||
let channelNextPageData = null;
|
||||
let isLoadingMoreVideos = false;
|
||||
let currentVideoData = null;
|
||||
|
||||
const trendingPage = document.getElementById("trending-page");
|
||||
const searchResultsPage = document.getElementById("search-results-page");
|
||||
|
@ -161,28 +162,57 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||
return videoElement;
|
||||
}
|
||||
|
||||
async function findVideoById(videoId) {
|
||||
if (currentVideoData && currentVideoData.url.includes(videoId)) {
|
||||
return currentVideoData;
|
||||
}
|
||||
|
||||
try {
|
||||
const trendingResponse = await fetch(trendingApiUrl);
|
||||
if (trendingResponse.ok) {
|
||||
const trendingVideos = await trendingResponse.json();
|
||||
const foundInTrending = trendingVideos.find((v) => v.url.includes(videoId));
|
||||
if (foundInTrending) {
|
||||
return foundInTrending;
|
||||
}
|
||||
}
|
||||
|
||||
if (lastSearchQuery) {
|
||||
const searchUrl = `${searchApiUrl}?q=${encodeURIComponent(lastSearchQuery)}&filter=all`;
|
||||
const searchResponse = await fetch(searchUrl);
|
||||
if (searchResponse.ok) {
|
||||
const searchData = await searchResponse.json();
|
||||
const searchResults = searchData.items ? searchData.items.filter((item) => item.type === "stream") : [];
|
||||
const foundInSearch = searchResults.find((v) => v.url.includes(videoId));
|
||||
if (foundInSearch) {
|
||||
return foundInSearch;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch (error) {
|
||||
console.error("Error searching for video:", error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchVideoDetails(videoId) {
|
||||
try {
|
||||
if (videoId === activeVideoId) {
|
||||
if (videoId === activeVideoId && currentVideoData) {
|
||||
return;
|
||||
}
|
||||
|
||||
activeVideoId = videoId;
|
||||
|
||||
trendingLoader.style.display = "flex";
|
||||
|
||||
const response = await fetch(trendingApiUrl);
|
||||
if (!response.ok) {
|
||||
throw new Error("Network response was not ok");
|
||||
}
|
||||
|
||||
const videos = await response.json();
|
||||
const video = videos.find((v) => v.url.includes(videoId));
|
||||
const video = await findVideoById(videoId);
|
||||
|
||||
if (video) {
|
||||
currentVideoData = video;
|
||||
openVideoPlayer(video);
|
||||
} else {
|
||||
console.error("Video not found in trending");
|
||||
console.error("Video not found in any source");
|
||||
trendingLoader.style.display = "none";
|
||||
alert("Video not found. Showing trending videos instead.");
|
||||
goToTrendingPage();
|
||||
|
@ -197,6 +227,7 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||
cleanupResources();
|
||||
|
||||
activeVideoId = null;
|
||||
currentVideoData = null;
|
||||
|
||||
activeChannelId = null;
|
||||
|
||||
|
@ -656,6 +687,8 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||
function openVideoPlayer(video) {
|
||||
cleanupResources();
|
||||
|
||||
currentVideoData = video;
|
||||
|
||||
detailTitle.textContent = video.title;
|
||||
detailAvatar.src = video.uploaderAvatar;
|
||||
detailUploader.textContent = video.uploaderName;
|
||||
|
@ -887,7 +920,7 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||
loadMoreButton.style.display = "none";
|
||||
loadMoreSpinner.style.display = "block";
|
||||
|
||||
const url = `https:
|
||||
const url = `https://pipedapi.wireway.ch/nextpage/channel/${activeChannelId}?nextpage=${encodeURIComponent(
|
||||
channelNextPageData
|
||||
)}`;
|
||||
console.log(`Fetching next page data from: ${url}`);
|
||||
|
@ -1012,4 +1045,4 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||
fetchTrendingVideos();
|
||||
checkInitialHash();
|
||||
setupInfiniteScroll();
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue