Rewrite Invidious instances to Piped.

Closes #11
This commit is contained in:
FireMaskterK 2021-11-11 08:29:57 +00:00
parent 0002eb04d7
commit 6af1f49429
No known key found for this signature in database
GPG Key ID: 49451E4482CC5BCD
2 changed files with 12 additions and 2 deletions

View File

@ -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 };
}

View File

@ -1,6 +1,6 @@
{
"name": "Piped Redirects",
"version": "1.1",
"version": "1.2",
"description": "Redirects YouTube links to Piped",
"permissions": [
"webRequest",