mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-22 17:37:51 +01:00
refactor code :3
This commit is contained in:
parent
23d1021ff0
commit
18edb4b110
1 changed files with 36 additions and 91 deletions
125
css/app.js
125
css/app.js
|
@ -105,51 +105,7 @@ timeLinks.forEach(link => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Fetch URLs and handle progress saving
|
|
||||||
const urls = document.querySelectorAll('a[href*="/watch?v="]');
|
|
||||||
const spinner = document.createElement('div');
|
|
||||||
spinner.id = 'fetch-spinner';
|
|
||||||
spinner.classList.add('hide');
|
|
||||||
document.body.appendChild(spinner);
|
|
||||||
const text = document.createElement('div');
|
|
||||||
text.id = 'fetch-text';
|
|
||||||
text.classList.add('hide');
|
|
||||||
document.body.appendChild(text);
|
|
||||||
document.body.classList.add('blur');
|
|
||||||
|
|
||||||
let fetchedCount = 0;
|
|
||||||
|
|
||||||
urls.forEach(link => {
|
|
||||||
const url = new URL(link.href);
|
|
||||||
if (url.host !== 'www.youtube.com' && url.host !== 'youtube.com' && url.host !== "redirect.poketube.fun") {
|
|
||||||
console.log(`Fetching ${url.origin}`);
|
|
||||||
spinner.classList.remove('hide');
|
|
||||||
text.classList.remove('hide');
|
|
||||||
|
|
||||||
fetch(url.href)
|
|
||||||
.then(response => {
|
|
||||||
if (response.status === 500) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
console.log(`Fetched ${url.origin}`);
|
|
||||||
fetchedCount++;
|
|
||||||
console.clear()
|
|
||||||
if (fetchedCount === urls.length) {
|
|
||||||
spinner.classList.add('hide');
|
|
||||||
text.classList.add('hide');
|
|
||||||
document.body.classList.remove('blur');
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
spinner.classList.add('hide');
|
|
||||||
text.classList.add('hide');
|
|
||||||
console.clear()
|
|
||||||
if (!(error instanceof TypeError && error.message.includes('Failed to fetch'))) {
|
|
||||||
console.error(`Error fetching ${url.origin}: ${error}`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Save and resume video progress
|
// Save and resume video progress
|
||||||
const videoId = new URLSearchParams(window.location.search).get('v');
|
const videoId = new URLSearchParams(window.location.search).get('v');
|
||||||
|
@ -190,57 +146,46 @@ videoElement.addEventListener("fullscreenchange", () => {
|
||||||
videoElement.style.borderRadius = document.fullscreenElement === videoElement ? "0em" : "16px";
|
videoElement.style.borderRadius = document.fullscreenElement === videoElement ? "0em" : "16px";
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function fetchUrls(urls) {
|
||||||
|
let fetchedCount = 0;
|
||||||
|
|
||||||
|
urls.forEach(link => {
|
||||||
|
const url = new URL(link.href);
|
||||||
|
if (url.host !== 'www.youtube.com' && url.host !== 'youtube.com' && url.host !== "redirect.poketube.fun") {
|
||||||
|
console.log(`Fetching ${url.origin}`);
|
||||||
|
fetch(url.href)
|
||||||
|
.then(response => {
|
||||||
|
if (response.status === 500) {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
console.log(`Fetched ${url.origin}`);
|
||||||
|
fetchedCount++;
|
||||||
|
console.clear();
|
||||||
|
if (fetchedCount === urls.length) {
|
||||||
|
document.body.classList.remove('blur');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.clear();
|
||||||
|
if (!(error instanceof TypeError && error.message.includes('Failed to fetch'))) {
|
||||||
|
console.error(`Error fetching ${url.origin}: ${error}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Fetch channel URLs
|
// Fetch channel URLs
|
||||||
const channelUrls = document.querySelectorAll('a[href*="/channel?id="]');
|
const channelUrls = document.querySelectorAll('a[href*="/channel?id="]');
|
||||||
let fetchedCountChannel = 0;
|
fetchUrls(channelUrls);
|
||||||
|
|
||||||
channelUrls.forEach(link => {
|
|
||||||
const url = new URL(link.href);
|
|
||||||
if (url.host !== 'www.youtube.com' && url.host !== 'youtube.com' && url.host !== "redirect.poketube.fun") {
|
|
||||||
console.log(`Fetching ${url.origin}`);
|
|
||||||
fetch(url.href)
|
|
||||||
.then(response => {
|
|
||||||
if (response.status === 500) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
console.log(`Fetched ${url.origin}`);
|
|
||||||
fetchedCountChannel++;
|
|
||||||
console.clear()
|
|
||||||
if (fetchedCountChannel === channelUrls.length) {
|
|
||||||
document.body.classList.remove('blur');
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.clear()
|
|
||||||
if (!(error instanceof TypeError && error.message.includes('Failed to fetch'))) {
|
|
||||||
console.error(`Error fetching ${url.origin}: ${error}`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Fetch download URLs
|
// Fetch download URLs
|
||||||
const downloadUrls = document.querySelectorAll('a[href*="/download?v="]');
|
const downloadUrls = document.querySelectorAll('a[href*="/download?v="]');
|
||||||
downloadUrls.forEach(link => {
|
fetchUrls(downloadUrls);
|
||||||
const url = new URL(link.href);
|
|
||||||
if (url.host !== 'www.youtube.com' && url.host !== 'youtube.com' && url.host !== "redirect.poketube.fun") {
|
// fetch videos urls
|
||||||
console.log(`Fetching ${url.origin}`);
|
const urls = document.querySelectorAll('a[href*="/watch?v="]');
|
||||||
fetch(url.href)
|
fetchUrls(urls);
|
||||||
.then(response => {
|
|
||||||
if (response.status === 500) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
console.log(`Fetched ${url.origin}`);
|
|
||||||
console.clear()
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.clear()
|
|
||||||
if (!(error instanceof TypeError && error.message.includes('Failed to fetch'))) {
|
|
||||||
console.error(`Error fetching ${url.origin}: ${error}`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var popupMenu = document.getElementById("popupMenu");
|
var popupMenu = document.getElementById("popupMenu");
|
||||||
var loopOption = document.getElementById("loopOption");
|
var loopOption = document.getElementById("loopOption");
|
||||||
|
|
Loading…
Reference in a new issue