aboutsummaryrefslogtreecommitdiff
path: root/youtube/remove-home-shorts.js
blob: 42ea0d0a53387a8c4e41ae7d8e6be46d5ffc96ba (plain)
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
55
56
57
58
59
60
61
62
// ==UserScript==
// @name        Remove youtube home and shorts
// @namespace   Violentmonkey Scripts
// @include      *youtube.com*
// @grant       GM_addStyle
// @version     1.0
// @author      tjk918
// @description 9/21/2023, 9:44:13 AM
// @license     MIT
// ==/UserScript==


// Remove home and shorts button
GM_addStyle(`
	tp-yt-app-drawer a[title=Home],
	tp-yt-app-drawer a[title=Shorts],
	ytd-mini-guide-renderer a[title=Home],
	ytd-mini-guide-renderer a[title=Shorts]
	{
		display: none !important; /* Needs !important flag */
	}
`)


// Subscriptions page is new homepage
const subscriptionsPath = "/feed/subscriptions"

function redirectToSubscriptions() {
	// Invoke clicking the subscriptions button to use youtube's hot page reloading if possible instead of reloading the whole page
	const subscriptionsButton = document.querySelector("tp-yt-app-drawer a[title=Subscriptions]")
	if (subscriptionsButton)
		subscriptionsButton.click()
	else
		window.location.replace(subscriptionsPath)
}


// Redirect to new homepage
function redirectIfHome() {
	 if (window.location.pathname === "/")
		redirectToSubscriptions()
}

redirectIfHome()
window.addEventListener("popstate", redirectIfHome)
//document.body.addEventListener("yt-navigate-finish", redirectIfHome)


// Youtube logo navigate to subscriptions
/* Needs to be done safely in case youtube changes and also because it throws
 * an error otherwise because violentmonkey seems to load the script twice */

const logo = document.querySelector("#logo a")
if (logo) {
	logo.href = subscriptionsPath
	logo.addEventListener("click", e => {
		// Seems there is an event listener that forces redirect to site root, so stop that first
		e.stopPropagation()
		e.preventDefault()
		redirectToSubscriptions()
	})
}