From 56d01efe6dae7b68eff759ab479c7b1564dceb8b Mon Sep 17 00:00:00 2001 From: Ashley Date: Fri, 28 Apr 2023 20:36:16 +0000 Subject: [PATCH] add cache for channels!! --- css/app.js | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/css/app.js b/css/app.js index f734f836..8780a9f8 100644 --- a/css/app.js +++ b/css/app.js @@ -250,4 +250,47 @@ videoElement.addEventListener("fullscreenchange", () => { videoElement.style.borderRadius = "16px"; } }); -// @license-end \ No newline at end of file + + +const chnlurl = document.querySelectorAll('a[href*="/channel?id="]'); // get all links with "/watch?v=" in href attribute + +let fetchedCountChannel = 0; + +chnlurl.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}`); + + fetch(url.href) + .then(response => { + if (response.status === 500) { + // do nothing + } + console.log(`Fetched ${url.origin}`); + fetchedCountChannel++; + console.clear() + + if (fetchedCountChannel === chnlurl.length) { + + document.body.classList.remove('blur'); + } + // Do something with the response + }) + .catch(error => { + + console.clear() + // Ignore network errors + if (!(error instanceof TypeError && error.message.includes('Failed to fetch'))) { + console.error(`Error fetching ${url.origin}: ${error}`); + } + + }); + } + } + +}); +// @license-end +