Skip to content

Instantly share code, notes, and snippets.

@m0n5t3r
Last active December 11, 2023 05:28
Show Gist options
  • Select an option

  • Save m0n5t3r/b7c13265152bd8c997f2d22afb4932e7 to your computer and use it in GitHub Desktop.

Select an option

Save m0n5t3r/b7c13265152bd8c997f2d22afb4932e7 to your computer and use it in GitHub Desktop.

Revisions

  1. m0n5t3r revised this gist May 7, 2021. 1 changed file with 10 additions and 4 deletions.
    14 changes: 10 additions & 4 deletions invidious-redirect.userscript.js
    Original file line number Diff line number Diff line change
    @@ -6,15 +6,21 @@
    // @include http://www.youtube.com/*
    // @include https://www.youtube.com/*
    // @include https://consent.youtube.com/*
    // @version 1.5
    // @version 1.6
    // @run-at document-start
    // @grant none
    // ==/UserScript==

    // prevent youtube content from loading; used to be a simple document.write, but greasemonkey complains
    var newDoc = document.implementation.createHTMLDocument ("");
    // prevent youtube content from loading; used to be a simple document.write, but
    // * at first, greasemonkey complained
    // * then google started redirecting everything to consent.youtube.com, which has CSP that requires trusted types
    var newDoc = document.implementation.createHTMLDocument (""),
    h1 = document.createElement("h1");

    h1.innerText = "Redirecting, please wait...";
    newDoc.body.appendChild(h1);

    document.replaceChild (document.importNode(newDoc.documentElement, true), document.documentElement);
    document.body.innerHTML = '<h1>Redirecting, please wait...</h1>';
    document.close();

    const blacklist = [
  2. m0n5t3r revised this gist May 4, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion invidious-redirect.userscript.js
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    // @description Redirects Youtube URLs to Invidio.us
    // @name Invidious Redirect
    // @namespace Backend
    // @downloadUrl https://gist.github.com/m0n5t3r/b7c13265152bd8c997f2d22afb4932e7/raw/invidious-redirect.userscript.js
    // @downloadURL https://gist.github.com/m0n5t3r/b7c13265152bd8c997f2d22afb4932e7/raw/invidious-redirect.userscript.js
    // @include http://www.youtube.com/*
    // @include https://www.youtube.com/*
    // @include https://consent.youtube.com/*
  3. m0n5t3r revised this gist May 4, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion invidious-redirect.userscript.js
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    // @description Redirects Youtube URLs to Invidio.us
    // @name Invidious Redirect
    // @namespace Backend
    // @downloadUrl https://gist.github.com/m0n5t3r/b7c13265152bd8c997f2d22afb4932e7/raw/d6bb7ce9ae049e06406b7fbc6ee9dce0110b0c0b/invidious-redirect.userscript.js
    // @downloadUrl https://gist.githubusercontent.com/m0n5t3r/b7c13265152bd8c997f2d22afb4932e7/raw/invidious-redirect.userscript.js
    // @include http://www.youtube.com/*
    // @include https://www.youtube.com/*
    // @include https://consent.youtube.com/*
  4. m0n5t3r revised this gist May 4, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion invidious-redirect.userscript.js
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    // @description Redirects Youtube URLs to Invidio.us
    // @name Invidious Redirect
    // @namespace Backend
    // @updateUrl https://gist.github.com/m0n5t3r/b7c13265152bd8c997f2d22afb4932e7/raw/d6bb7ce9ae049e06406b7fbc6ee9dce0110b0c0b/invidious-redirect.userscript.js
    // @downloadUrl https://gist.github.com/m0n5t3r/b7c13265152bd8c997f2d22afb4932e7/raw/d6bb7ce9ae049e06406b7fbc6ee9dce0110b0c0b/invidious-redirect.userscript.js
    // @include http://www.youtube.com/*
    // @include https://www.youtube.com/*
    // @include https://consent.youtube.com/*
  5. m0n5t3r revised this gist May 4, 2021. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions invidious-redirect.userscript.js
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,7 @@
    // @description Redirects Youtube URLs to Invidio.us
    // @name Invidious Redirect
    // @namespace Backend
    // @updateUrl https://gist.github.com/m0n5t3r/b7c13265152bd8c997f2d22afb4932e7/raw/d6bb7ce9ae049e06406b7fbc6ee9dce0110b0c0b/invidious-redirect.userscript.js
    // @include http://www.youtube.com/*
    // @include https://www.youtube.com/*
    // @include https://consent.youtube.com/*
  6. m0n5t3r revised this gist May 4, 2021. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions invidious-redirect.userscript.js
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@
    // @include http://www.youtube.com/*
    // @include https://www.youtube.com/*
    // @include https://consent.youtube.com/*
    // @version 1.4
    // @version 1.5
    // @run-at document-start
    // @grant none
    // ==/UserScript==
    @@ -16,11 +16,11 @@ document.replaceChild (document.importNode(newDoc.documentElement, true), docume
    document.body.innerHTML = '<h1>Redirecting, please wait...</h1>';
    document.close();

    // these seem to be poorly maintained and don't work most of the time
    const blacklist = [
    "invidious.xyz",
    "invidious.site",
    "invidiou.site",
    "invidious.reallyancient.tech",
    ];

    function find_parameter(name) {
    @@ -65,14 +65,14 @@ fetch("https://api.invidious.io/instances.json?sort_by=type,health").then((respo
    idx = Math.floor(Math.random() * filtered.length);
    domain = filtered[idx];

    if (/watch\?|channel|embed/.test(window.location.href) && window.location.href.indexOf('list=WL') < 0) {
    a = window.location.href.replace(/www\.youtube\.com/, domain);
    if (/watch\?|channel|embed|shorts/.test(window.location.href) && window.location.href.indexOf('list=WL') < 0) {
    a = window.location.href.replace(/www\.youtube\.com/, domain).replace('/shorts/', '/watch?v=');
    window.location.replace(a);
    }

    // youtu.be and youtube.com seem to force-redirect to the consent thing lately, handle it here
    if(/consent\.youtube\.com/.test(window.location.href)) {
    a = find_parameter('continue').replace(/www.youtube.com/, domain);
    a = find_parameter('continue').replace(/www.youtube.com/, domain).replace('/shorts/', '/watch?v=');
    window.location.replace(a);
    }
    });
  7. m0n5t3r revised this gist Apr 5, 2021. 1 changed file with 37 additions and 6 deletions.
    43 changes: 37 additions & 6 deletions invidious-redirect.userscript.js
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,8 @@
    // @namespace Backend
    // @include http://www.youtube.com/*
    // @include https://www.youtube.com/*
    // @version 1.3
    // @include https://consent.youtube.com/*
    // @version 1.4
    // @run-at document-start
    // @grant none
    // ==/UserScript==
    @@ -15,6 +16,26 @@ document.replaceChild (document.importNode(newDoc.documentElement, true), docume
    document.body.innerHTML = '<h1>Redirecting, please wait...</h1>';
    document.close();

    // these seem to be poorly maintained and don't work most of the time
    const blacklist = [
    "invidious.xyz",
    "invidious.site",
    "invidiou.site",
    ];

    function find_parameter(name) {
    var result = null,
    tmp = [];
    location.search
    .substr(1)
    .split("&")
    .forEach((item) => {
    tmp = item.split("=");
    if (tmp[0] === name) result = decodeURIComponent(tmp[1]);
    });
    return result;
    }

    // pick a random instance with a good health record
    fetch("https://api.invidious.io/instances.json?sort_by=type,health").then((response) => {
    response.json().then((instances) => {
    @@ -23,16 +44,20 @@ fetch("https://api.invidious.io/instances.json?sort_by=type,health").then((respo
    filtered = instances.filter((i) => {
    var monitor = i[1].monitor;
    var type = i[1].type;
    if(type != "https") {

    if(type != "https") {
    return false;
    }


    if(blacklist.includes(i[0])) {
    return false;
    }

    if (monitor) {
    return monitor.dailyRatios[0].ratio == "100.00";
    }
    // no monitoring data, let it through; might change later to filter in 2 steps and only

    // no monitoring data, let it through; might change later to filter in 2 steps and only
    // let unknown status instances through if no health info has been found
    return true;
    }).map((i) => { return i[0] });
    @@ -44,5 +69,11 @@ fetch("https://api.invidious.io/instances.json?sort_by=type,health").then((respo
    a = window.location.href.replace(/www\.youtube\.com/, domain);
    window.location.replace(a);
    }

    // youtu.be and youtube.com seem to force-redirect to the consent thing lately, handle it here
    if(/consent\.youtube\.com/.test(window.location.href)) {
    a = find_parameter('continue').replace(/www.youtube.com/, domain);
    window.location.replace(a);
    }
    });
    });
  8. m0n5t3r revised this gist Feb 3, 2021. 1 changed file with 14 additions and 2 deletions.
    16 changes: 14 additions & 2 deletions invidious-redirect.userscript.js
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    // @namespace Backend
    // @include http://www.youtube.com/*
    // @include https://www.youtube.com/*
    // @version 1.2
    // @version 1.3
    // @run-at document-start
    // @grant none
    // ==/UserScript==
    @@ -22,7 +22,19 @@ fetch("https://api.invidious.io/instances.json?sort_by=type,health").then((respo

    filtered = instances.filter((i) => {
    var monitor = i[1].monitor;
    return monitor && monitor.dailyRatios[0].ratio == "100.00";
    var type = i[1].type;

    if(type != "https") {
    return false;
    }

    if (monitor) {
    return monitor.dailyRatios[0].ratio == "100.00";
    }

    // no monitoring data, let it through; might change later to filter in 2 steps and only
    // let unknown status instances through if no health info has been found
    return true;
    }).map((i) => { return i[0] });

    idx = Math.floor(Math.random() * filtered.length);
  9. m0n5t3r revised this gist Jan 29, 2021. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions invidious-redirect.userscript.js
    Original file line number Diff line number Diff line change
    @@ -9,8 +9,11 @@
    // @grant none
    // ==/UserScript==

    // prevent youtube content from loading
    document.write("redirecting...");
    // prevent youtube content from loading; used to be a simple document.write, but greasemonkey complains
    var newDoc = document.implementation.createHTMLDocument ("");
    document.replaceChild (document.importNode(newDoc.documentElement, true), document.documentElement);
    document.body.innerHTML = '<h1>Redirecting, please wait...</h1>';
    document.close();

    // pick a random instance with a good health record
    fetch("https://api.invidious.io/instances.json?sort_by=type,health").then((response) => {
  10. m0n5t3r revised this gist Jan 26, 2021. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions invidious-redirect.userscript.js
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,10 @@
    // @grant none
    // ==/UserScript==

    // prevent youtube content from loading
    document.write("redirecting...");

    // pick a random instance with a good health record
    fetch("https://api.invidious.io/instances.json?sort_by=type,health").then((response) => {
    response.json().then((instances) => {
    var filtered, domain, idx, a;
  11. m0n5t3r revised this gist Jan 26, 2021. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions invidious-redirect.userscript.js
    Original file line number Diff line number Diff line change
    @@ -4,13 +4,13 @@
    // @namespace Backend
    // @include http://www.youtube.com/*
    // @include https://www.youtube.com/*
    // @version 1.1
    // @version 1.2
    // @run-at document-start
    // @grant none
    // ==/UserScript==

    document.write("redirecting...");
    fetch("https://instances.invidio.us/instances.json?sort_by=type,health").then((response) => {
    fetch("https://api.invidious.io/instances.json?sort_by=type,health").then((response) => {
    response.json().then((instances) => {
    var filtered, domain, idx, a;

  12. m0n5t3r revised this gist Jan 16, 2021. No changes.
  13. m0n5t3r revised this gist Jan 16, 2021. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions invidious-redirect.userscript.js
    Original file line number Diff line number Diff line change
    @@ -22,9 +22,9 @@ fetch("https://instances.invidio.us/instances.json?sort_by=type,health").then((r
    idx = Math.floor(Math.random() * filtered.length);
    domain = filtered[idx];

    if (/watch\?|channel/.test(window.location.href) && window.location.href.indexOf('list=WL') < 0) {
    a = window.parent.location.href.replace(/www\.youtube\.com/, domain);
    if (/watch\?|channel|embed/.test(window.location.href) && window.location.href.indexOf('list=WL') < 0) {
    a = window.location.href.replace(/www\.youtube\.com/, domain);
    window.location.replace(a);
    }
    });
    });
    });
  14. m0n5t3r revised this gist Jan 14, 2021. No changes.
  15. m0n5t3r created this gist Jan 14, 2021.
    30 changes: 30 additions & 0 deletions invidious-redirect.userscript.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    // ==UserScript==
    // @description Redirects Youtube URLs to Invidio.us
    // @name Invidious Redirect
    // @namespace Backend
    // @include http://www.youtube.com/*
    // @include https://www.youtube.com/*
    // @version 1.1
    // @run-at document-start
    // @grant none
    // ==/UserScript==

    document.write("redirecting...");
    fetch("https://instances.invidio.us/instances.json?sort_by=type,health").then((response) => {
    response.json().then((instances) => {
    var filtered, domain, idx, a;

    filtered = instances.filter((i) => {
    var monitor = i[1].monitor;
    return monitor && monitor.dailyRatios[0].ratio == "100.00";
    }).map((i) => { return i[0] });

    idx = Math.floor(Math.random() * filtered.length);
    domain = filtered[idx];

    if (/watch\?|channel/.test(window.location.href) && window.location.href.indexOf('list=WL') < 0) {
    a = window.parent.location.href.replace(/www\.youtube\.com/, domain);
    window.location.replace(a);
    }
    });
    });