Mycc commited on
Commit
41f8001
·
1 Parent(s): 7ab1222

Upload Invidious Redirect.user.js

Browse files
Files changed (1) hide show
  1. Invidious Redirect.user.js +35 -0
Invidious Redirect.user.js ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // ==UserScript==
2
+ // @name Invidious Redirect
3
+ // @description Redirect YouTube video link
4
+ // @namespace
5
+ // @match *://youtube.com/watch*
6
+ // @match *://*.youtube.com/watch*
7
+ // @match *://youtu.be/*
8
+ // @run-at document-start
9
+ // @grant none
10
+ // @version 1.01
11
+ // @author Mycc
12
+ // ==/UserScript==
13
+
14
+ /* CONFIG */
15
+ const instances = ["https://invidious.snopyta.org", "https://yewtu.be", "https://invidious.xyz"];
16
+
17
+ /* SCRIPT START */
18
+ let url = new URL(window.location);
19
+ let videoID = url.searchParams.get("v");
20
+ let time = url.searchParams.get("t");
21
+
22
+ if (!videoID) {
23
+ let path = url.pathname.substring(1);
24
+ let parts = path.split('/');
25
+ videoID = parts[parts.length - 1];
26
+ }
27
+
28
+ let invidiousInstance = instances[Math.floor(Math.random() * instances.length)];
29
+ let redirectURL = new URL(`${invidiousInstance}/watch?v=${videoID}`);
30
+
31
+ if (time) {
32
+ redirectURL.searchParams.set("t", time);
33
+ }
34
+
35
+ window.location = redirectURL.toString();