1
0
Fork 0
mirror of https://codeberg.org/ashley/poke.git synced 2024-11-16 22:34:39 -05:00

make search faster :3

This commit is contained in:
Ashley 2023-06-10 08:10:26 +00:00
parent 37c4dc0ea1
commit 948f1c71e2

View file

@ -544,162 +544,7 @@ font-weight: 1000;
</div>
<script src="/css/custom-css.js"> </script>
<script>
// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-3.0-or-later
// Get all anchor links on the page
const links = document.querySelectorAll('a');
// Add a click event listener to each link
links.forEach(link => {
link.addEventListener('click', e => {
e.preventDefault(); // Prevent the default link behavior
// Create a loading spinner element
const spinner = document.createElement('div');
spinner.classList.add('spinner');
// Create a loading overlay element
const loading = document.createElement('div');
loading.classList.add('loading');
loading.appendChild(spinner);
// Add the loading overlay to the body
document.body.appendChild(loading);
// Redirect to the link after a short delay to show the loading overlay
setTimeout(() => {
window.location.href = link.href;
}, 500);
});
});
const audioElement = document.getElementById("audio");
audioElement.volume = 0.1;
let audioToggled = JSON.parse(localStorage.getItem("audioToggled"));
// When the audio player is loaded, check for stored time value and set current time
audioElement.addEventListener("loadedmetadata", () => {
if (audioToggled) {
const storedTime = localStorage.getItem("audioTime");
if (storedTime) {
audioElement.currentTime = storedTime;
}
}
});
// When the user leaves the page, store the current time value
window.addEventListener("beforeunload", () => {
if (audioToggled) {
localStorage.setItem("audioTime", audioElement.currentTime);
}
});
const audio = document.getElementById("audio");
const button = document.getElementById("audioButton");
const icon = document.getElementById("audioIcon");
function toggleAudio() {
if (audio.paused) {
audio.play();
audio.volume = 0.1;
button.classList.add("playing");
icon.classList.remove("fa-play");
icon.classList.add("fa-pause");
localStorage.setItem("audioToggled", true); // save that audio is toggled
} else {
audio.pause();
button.classList.remove("playing");
icon.classList.remove("fa-pause");
icon.classList.add("fa-play");
localStorage.setItem("audioToggled", false); // save that audio is not toggled
}
}
if (audioToggled === null || audioToggled === undefined) {
audioToggled = true;
}
if (audioToggled == false) {
audio.pause();
button.classList.remove("playing");
icon.classList.remove("fa-pause");
icon.classList.add("fa-play");
} else {
audio.play();
audio.volume = 0.1;
audio.src = "https://tube.kuylar.dev/proxy/media/MGPx242O--U/18"
button.classList.add("playing");
icon.classList.remove("fa-play");
icon.classList.add("fa-pause");
}
// Show the audio button
button.style.display = "block";
// @license-end
const urls = document.querySelectorAll('a[href*="/watch?v="]'); // get all links with "/watch?v=" in href attribute
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') {
if (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');
}
// Do something with the response
})
.catch(error => {
spinner.classList.add('hide');
text.classList.add('hide');
console.clear()
// Ignore network errors
if (!(error instanceof TypeError && error.message.includes('Failed to fetch'))) {
console.error(`Error fetching ${url.origin}: ${error}`);
}
});
}
}
});
console.clear()
</script>
</body>