Greasy Fork

Greasy Fork is available in English.

YT redirect to Invidious on login request

Redirects youtube links to invidious instances if youtube requires you to login for geo-blocking or age restriction

当前为 2020-07-31 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         YT redirect to Invidious on login request
// @namespace    http://tampermonkey.net/
// @version      1.1.0
// @description  Redirects youtube links to invidious instances if youtube requires you to login for geo-blocking or age restriction
// @author       Xynoth
// @match        https://www.youtube.com/watch?*
// @grant        none
// ==/UserScript==

(function() {
    // Edit your invidious instance here
    var invidiousInstance = "https://invidio.us";

    // Enable button to Invidious on youtube?
    var enableInvButton = true;

    // Other variables
    var currentLocation = window.location.href;
    var newLocation = currentLocation.replace("https://www.youtube.com/watch?", invidiousInstance + "/watch?");
    var loginWarning;
    var subscribeDiv;
    var invButton;
    var timedLoop = 0;

    // We append the "watch on invidious" button here
    subscribeDiv = document.getElementById("analytics-button");

    // We check for the "Must login" container for 5 seconds before removing checker
    var checkExist = setInterval(function() {
        loginWarning = document.querySelector(".ytp-error[role='alert']");
        subscribeDiv = document.getElementById("analytics-button");
        invButton = document.getElementById("invidious-Button");
        if (loginWarning) {
            window.location.href = newLocation;
            clearInterval(checkExist);
        } else if (subscribeDiv && invButton == null && enableInvButton) {
            var watchOnInv = document.createElement("a");
            watchOnInv.setAttribute('id', "invidious-Button");
            watchOnInv.href = newLocation;
            watchOnInv.style.background = "#444";
            watchOnInv.style.fontSize = "14px";
            watchOnInv.style.textDecoration = "none";
            watchOnInv.style.color = "#fff";
            watchOnInv.style.padding = "11px 15px";
            watchOnInv.style.borderRadius = "5px";
            watchOnInv.innerHTML = "INVIDIOUS";
            subscribeDiv.appendChild(watchOnInv);
        } else if (timedLoop >= 5) {
            clearInterval(checkExist);
        }
        timedLoop += 1;
    }, 1000);

})();