puterich / Youtube Recommendation remover

// ==UserScript==
// @name         Youtube Recommendation remover
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Removes distractions from Youtube while you're studying. Removes recommendations on the Youtube frontpage, aswell as all video recommendations to the right of each video.
// @author       puterich
// @match        https://www.youtube.com/*
// @exclude      https://www.youtube.com/channel/*
// @grant        none
// @noframes
// @license MIT
// ==/UserScript==
var body = document.getElementsByTagName("body")[0];

var removeRecom = function () {
  'use strict';
  let prev = document.getElementsByClassName("style-scope ytd-two-column-browse-results-renderer");
  if (prev !== "undefined") {
    try {
      prev[0].innerHTML = "";
    }
    catch (error) {}
  }
};

var removeSidebar = function () {
  'use strict';
  let prev2 = document.getElementById("related");
  if (prev2 !== "undefined") {
    prev2.innerHTML = "";
  }
};

removeRecom();
removeSidebar();

body.addEventListener("yt-navigate-finish", function (event) {
  removeRecom();
  removeSidebar();
});