// ==UserScript== // @description Redirects Youtube URLs to Invidio.us // @name Invidious Redirect // @namespace Backend // @include http://www.youtube.com/* // @include https://www.youtube.com/* // @version 1.3 // @run-at document-start // @grant none // ==/UserScript== // prevent youtube content from loading; used to be a simple document.write, but greasemonkey complains var newDoc = document.implementation.createHTMLDocument (""); document.replaceChild (document.importNode(newDoc.documentElement, true), document.documentElement); document.body.innerHTML = '

Redirecting, please wait...

'; document.close(); // pick a random instance with a good health record fetch("https://api.invidious.io/instances.json?sort_by=type,health").then((response) => { response.json().then((instances) => { var filtered, domain, idx, a; filtered = instances.filter((i) => { var monitor = i[1].monitor; var type = i[1].type; if(type != "https") { return false; } if (monitor) { return monitor.dailyRatios[0].ratio == "100.00"; } // no monitoring data, let it through; might change later to filter in 2 steps and only // let unknown status instances through if no health info has been found return true; }).map((i) => { return i[0] }); idx = Math.floor(Math.random() * filtered.length); domain = filtered[idx]; if (/watch\?|channel|embed/.test(window.location.href) && window.location.href.indexOf('list=WL') < 0) { a = window.location.href.replace(/www\.youtube\.com/, domain); window.location.replace(a); } }); });