mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-26 13:58:13 +01:00
add page cache owo
This commit is contained in:
parent
8721ad924d
commit
4fc2afd2d0
1 changed files with 32 additions and 17 deletions
|
@ -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
|
|
||||||
if (response.ok) {
|
|
||||||
fetchedCount++;
|
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");
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue