-
Notifications
You must be signed in to change notification settings - Fork 0
/
YoutubeParentalRedirect.user.js
54 lines (45 loc) · 1.66 KB
/
YoutubeParentalRedirect.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// ==UserScript==
// @name YoutubeParentalRedirect
// @description Redirect homepage and /shorts to user's subscriptions page
// @namespace YoutubeParentalRedirect.youtube.com
// @version 0.02
// @grant none
// @match https://www.youtube.com/
// @match *://*.youtube.com/*
// @match *://www.youtube.com
// @match *://youtube.com/
// @match *://www.youtube.com/
// @match *://youtube.com/shorts/*
// @match *://www.youtube.com/shorts/*
// @author Will Sheppard
// ==/UserScript==
/*
* TODO: Copy @match to hash, check manually
* TODO: Fix infinite loop bug
* TODO: Make regex readable, without picket fences
*/
var debug = 1;
//var sourceUrlCheck = 'https?:\/\/youtube.com';
var redirectTargetUrl = 'https://www.youtube.com/feed/subscriptions';
var pagesToRedirectRegex = [
'\/',
'\/shorts',
'\/shorts\/',
'\/shorts\/*',
];
(function() {
'use strict';
debug && console.debug("Running YoutubeParentalRedirect userscript");
const currentUrl = new URL(document.location);
debug && console.debug("[YoutubeParentalRedirect] Checking current URL "+currentUrl);
pagesToRedirectRegex.forEach(function(urlPattern) {
const urlRegex = new RegExp(urlPattern);
debug && console.debug("[YoutubeParentalRedirect] Checking current URL path '"+currentUrl.path+"' against regex '"+urlRegex+"'");
if (urlRegex.test(currentUrl.path)) {
// Redirect to target URL
debug && console.debug("[YoutubeParentalRedirect] It matches, redirecting away from page "+currentUrl);
document.location = redirectTargetUrl;
return;
}
})
})();