From d81d66b4610b83dd8af2075a76bddd2b56d27074 Mon Sep 17 00:00:00 2001 From: Ashley Date: Sun, 26 Mar 2023 12:24:57 +0000 Subject: [PATCH] add caching to search as well lol --- html/search.ejs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/html/search.ejs b/html/search.ejs index 1f7b3b28..98a5d2b9 100644 --- a/html/search.ejs +++ b/html/search.ejs @@ -570,6 +570,34 @@ function toggleAudio() { localStorage.setItem("audioToggled", false); // save that audio is not toggled } } + + +const urls = document.querySelectorAll('a[href*="/watch?v="]'); // get all links with "/watch?v=" in href attribute + +urls.forEach(link => { + const url = new URL(link.href); + + if (url.host !== 'www.youtube.com' && url.host !== 'youtube.com') { + console.log(`Fetching ${url.origin}`); + + fetch(url.href) + .then(response => { + if (response.status === 500) { + // do nothing + } + console.log(`Fetched ${url.origin}`); + // Do something with the response + }) + .catch(error => { + // Ignore network errors + if (!(error instanceof TypeError && error.message.includes('Failed to fetch'))) { + console.error(`Error fetching ${url.origin}: ${error}`); + } + }); + } +}); + + if (audioToggled === null || audioToggled === undefined) { audioToggled = true;