Greasy Fork is available in English.
Redirects youtube links to invidious instances if youtube requires you to login for geo-blocking or age restriction
当前为
// ==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);
})();