top | item 47019694

(no title)

susam | 15 days ago

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()

discuss

order

I_like_tomato|14 days ago

susam|14 days ago

Thanks for sharing. I realised I have several userscripts I've written over time to tackle web browsing distractions. I found another one and this is probably the most effective for me because it hides Shorts at the CSS level. That means I don't need to rely on setTimeout(..., 1000) to catch elements that get inserted dynamically after the page loads.

  (function () {
    const css = `
      #secondary { display: none }
      .ytd-rich-shelf-renderer { display: none }
    `
    const style = document.createElement('style')
    style.textContent = css
    document.head.appendChild(style)
  })()