Search code examples
javascriptyoutubefirefox-addongreasemonkey

How to get grease monkey to run on Youtube link changes?


It's my first time using grease monkey, and I'm a novice at javascript, but I have some simple code to delete the suggested videos on the right-hand side of YouTube, which I find can distract me from work:

var elem = document.getElementById('watch-related'); elem.parentNode.removeChild(elem);

I've tried using addEventListener(); as well as a while loop with a setTimeOut(); and I've tried setInterval(). None worked. But they all, including the plain code, work if I refresh the page or arrive at the link from an external source, but if I arrive at the video from another YouTube page it doesn't.

I think it has something to do with the way YouTube loads pages, but I haven't been able to find any workarounds. Any ideas?

Edit: I also found this, which has some good info on this topic, but also doesn't work.


Solution

  • Option 1:

    Install uBlock Origin or Adblock Plus, and add a custom filter: youtube.com###watch-related.

    Option 2 (in case you have to use Greasemonkey):

    // ==UserScript==
    // @name         Youtube Suggested Video Hider
    // @include      https://www.youtube.com/watch?*
    // @grant        GM_addStyle
    // ==/UserScript==
    GM_addStyle('#watch-related { display: none; }')