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

当前为 2021-11-12 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 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.7
// @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?*
// @match        https://consent.youtube.com/m?continue=*
// @grant        none
// @inject-into  content
// @license      GPL-3.0
// ==/UserScript==

(function() {
    // Edit your invidious instance in the variable below.
    // You can find a list with invidious instances at https://redirect.invidious.io/
    var invidiousInstance = "https://invidio.xamh.de";

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

    // Enable youtube consent page bypass
    var bypassConsent = false;
  
    // Initial script variables
    var currentLocation = window.location.href;
    var bypassedConsent = false;
    
  
    // Checks if the consent page appears and tries to bypass it the variable is enabled
    if (currentLocation.startsWith("https://consent.") && bypassConsent == true) {
      var firstFragment = currentLocation.split("%3D")[1];
      var videoID = firstFragment.split("&gl")[0];
      bypassedConsent = true;
      currentLocation = "https://www.youtube.com/watch?v=" + videoID;
    }
  
    // Other variables
    var instanceFix = currentLocation.replace("https://www.youtube.com/watch?", invidiousInstance + "/watch?");
    var newLocation = instanceFix.replace("&feature=youtu.be", "");
    var loginWarning;
    var subscribeDiv;
    var invButton;
    var adsOnScreen;
    var nsfwTag;
    var timedLoop = 0;

    // In case we just arrived at a normal video
    if (!bypassedConsent) {
      
      // 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']");
          nsfwTag = document.querySelector("ytd-metadata-row-renderer a.yt-formatted-string[href$='community_guidelines']");
          adsOnScreen = document.querySelector(".ytp-ad-module");
          subscribeDiv = document.querySelector("#meta-contents #analytics-button");
          invButton = document.getElementById("invidious-Button");
          if ((loginWarning && !adsOnScreen) || nsfwTag) {
              console.log("Redirecting to Invidious instance...")
              window.location.href = newLocation;
              clearInterval(checkExist);
          } else if (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";
              console.log("Potato")
              subscribeDiv.appendChild(watchOnInv);
          } else if (timedLoop >= 5) {
              clearInterval(checkExist);
          }
          timedLoop += 1;
      }, 1000);
      
    }
    // If we arrived at the consent page with bypassConsent enabled instead
    else {
      window.location.href = newLocation;
    }
  


})();