// ==UserScript== // @name YT redirect to Invidious on login request // @namespace http://tampermonkey.net/ // @version 1.1.2 // @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 // @license GPL-3.0 // @downloadURL none // ==/UserScript== (function() { // Edit your invidious instance here var invidiousInstance = "https://invidious.snopyta.org"; // 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 adsOnScreen; 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']"); adsOnScreen = document.querySelector(".ytp-ad-module"); subscribeDiv = document.getElementById("analytics-button"); invButton = document.getElementById("invidious-Button"); if (loginWarning && !adsOnScreen) { 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); })();