diff options
| author | Tim Keller <tjk@tjkeller.xyz> | 2026-09-21 23:18:15 -0500 |
|---|---|---|
| committer | Tim Keller <tjk@tjkeller.xyz> | 2026-09-21 23:18:15 -0500 |
| commit | b88ff9fe8e80cc4d8aa0db2a3595ab10f40f4439 (patch) | |
| tree | 234e442aaaff83d1a50fb15998690dc4f0bfe6c6 /scripts/youtube-remove-home-shorts.user.js | |
| parent | 531a76993e2babcecc69be7b5333729078c8dd9b (diff) | |
| download | userscripts-b88ff9fe8e80cc4d8aa0db2a3595ab10f40f4439.tar.xz userscripts-b88ff9fe8e80cc4d8aa0db2a3595ab10f40f4439.zip | |
move all scripts to scripts dir
Diffstat (limited to 'scripts/youtube-remove-home-shorts.user.js')
| -rw-r--r-- | scripts/youtube-remove-home-shorts.user.js | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/scripts/youtube-remove-home-shorts.user.js b/scripts/youtube-remove-home-shorts.user.js new file mode 100644 index 0000000..5e75ef1 --- /dev/null +++ b/scripts/youtube-remove-home-shorts.user.js @@ -0,0 +1,64 @@ +// ==UserScript== +// @name Remove youtube home and shorts +// @namespace Violentmonkey Scripts +// @include *youtube.com* +// @grant GM_addStyle +// @homepageURL https://git.tjkeller.xyz/userscripts/about +// @downloadURL https://git.tjkeller.xyz/userscripts/plain/scripts/youtube-remove-home-shorts.user.js +// @version 1.1 +// @author tjkeller.xyz +// @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() + }) +} |
