Invidious Redirect

Redirects Youtube URLs to Invidio.us

目前为 2018-07-20 提交的版本。查看 最新版本

// ==UserScript==
// @description Redirects Youtube URLs to Invidio.us
// @name Invidious Redirect
// @namespace Backend
// @include http://www.youtube.com/*
// @include https://www.youtube.com/*
// @version 0.1.0
// @run-at document-start
// @grant none
// ==/UserScript==

function replace_beginning(str, beginning, replacement) {
    if (str.startsWith(beginning)) {
        return replacement + str.slice(beginning.length);
    }

    return str;
}

function urls_list(str) {
  return [str, "http://" + str, "https://" + str];
}

function replace_yt(str) {
    yt_list = [];
    yt_list = yt_list.concat(urls_list("www.youtube.com/watch"));

    yt_list.forEach((b) => {
        str = replace_beginning(str, b, "https://invidio.us/watch");
    });

    return str;
}

let loc = window.location.href;
loc = replace_yt(loc);
if (window.location.href !== loc) {
    window.location.href = loc;
}