Here is another one I found in my personal userscripts. I believe this script is more effective than my previous one because it prevents recommendations for Shorts or other videos from being shown.
// ==UserScript==
// @name No YT Sidebar and Shorts
// @match https://www.youtube.com/*
// ==/UserScript==
function noYTSidebar () {
const element = document.getElementById('secondary')
if (element === null) {
window.setTimeout(noYTSidebar, 1000)
return
}
element.getElementById('secondary').style.display = 'none'
}
function noYTShorts () {
const elements = document.querySelectorAll('ytd-rich-shelf-renderer')
if (elements.length === 0) {
window.setTimeout(noYTShorts, 1000)
return
}
for (e of document.querySelectorAll('ytd-rich-shelf-renderer')) {
e.style.display = 'none'
}
}
noYTSidebar()
noYTShorts()