add page cache owo

This commit is contained in:
Ashley 2023-03-26 18:42:44 +00:00
parent 8721ad924d
commit 4fc2afd2d0

View file

@ -1512,47 +1512,62 @@ links.forEach(link => {
} }
}); });
}); });
const urls = document.querySelectorAll('a[href*="/watch?v="]'); // get all links with "/watch?v=" in href attribute const urls = document.querySelectorAll('a[href*="/watch?v="]'); // get all links with "/watch?v=" in href attribute
const fetchCount = urls.length; const spinner = document.createElement('div');
let fetchedCount = 0; spinner.id = 'fetch-spinner';
spinner.classList.add('hide');
document.body.appendChild(spinner);
const fetchCountElement = document.getElementById('fetch-count'); const text = document.createElement('div');
fetchCountElement.textContent = ``; text.id = 'fetch-text';
text.classList.add('hide');
document.body.appendChild(text);
document.body.classList.add('blur');
let fetchedCount = 0;
urls.forEach(link => { urls.forEach(link => {
const url = new URL(link.href); const url = new URL(link.href);
if (url.host !== 'www.youtube.com' && url.host !== 'youtube.com') { if (url.host !== 'www.youtube.com' && url.host !== 'youtube.com') {
if (url.host !== "redirect.poketube.fun") {
console.log(`Fetching ${url.origin}`); console.log(`Fetching ${url.origin}`);
spinner.classList.remove('hide');
text.classList.remove('hide');
fetch(url.href) fetch(url.href)
.then(response => { .then(response => {
if (response.status === 500) { if (response.status === 500) {
throw new Error('Server Error'); // do nothing
} }
console.log(`Fetched ${url.origin}`); console.log(`Fetched ${url.origin}`);
// Only increment fetchedCount if the response is not a 500 error fetchedCount++;
if (response.ok) {
fetchedCount++; if (fetchedCount === urls.length) {
spinner.classList.add('hide');
text.classList.add('hide');
document.body.classList.remove('blur');
} }
fetchCountElement.textContent = ``; // Do something with the response
// Check if all URLs have been fetched and hide the element if they have })
if (fetchedCount === fetchCount) {
fetchCountElement.style.display = 'none';
}
console.clear();
})
.catch(error => { .catch(error => {
spinner.classList.add('hide');
text.classList.add('hide');
// Ignore network errors // Ignore network errors
if (!(error instanceof TypeError && error.message.includes('Failed to fetch'))) { if (!(error instanceof TypeError && error.message.includes('Failed to fetch'))) {
console.clear(); console.error(`Error fetching ${url.origin}: ${error}`);
} }
}); });
} }
}
}); });
console.clear()
const videoElement = document.getElementById("video"); const videoElement = document.getElementById("video");