From 6af1f4942903fa7fe63956a982adce6baf527838 Mon Sep 17 00:00:00 2001 From: FireMaskterK <20838718+FireMasterK@users.noreply.github.com> Date: Thu, 11 Nov 2021 08:29:57 +0000 Subject: [PATCH] Rewrite Invidious instances to Piped. Closes #11 --- js/background.js | 12 +++++++++++- manifest.json | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/js/background.js b/js/background.js index 266225c..a0aea7d 100644 --- a/js/background.js +++ b/js/background.js @@ -1,12 +1,22 @@ window.browser = window.browser || window.chrome; +const INVIDIOUS_INSTANCES = []; + +fetch("https://api.invidious.io/instances.json") + .then((resp) => resp.json()) + .then((array) => array.forEach((json) => INVIDIOUS_INSTANCES.push(json[0]))); + browser.webRequest.onBeforeRequest.addListener( (details) => { const url = new URL(details.url); if (url.hostname.endsWith("youtu.be") && url.pathname.length > 1) { return { redirectUrl: "https://piped.kavin.rocks/watch?v=" + url.pathname.substr(1) }; } - if (url.hostname.endsWith("youtube.com") || url.hostname.endsWith("youtube-nocookie.com")) { + if ( + url.hostname.endsWith("youtube.com") || + url.hostname.endsWith("youtube-nocookie.com") || + INVIDIOUS_INSTANCES.includes(url.hostname) + ) { url.hostname = "piped.kavin.rocks"; return { redirectUrl: url.href }; } diff --git a/manifest.json b/manifest.json index 3cd3dcd..ed51707 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { "name": "Piped Redirects", - "version": "1.1", + "version": "1.2", "description": "Redirects YouTube links to Piped", "permissions": [ "webRequest",