Reload YouTube once

adds "#" to URL, making YouTube reload once to avoid its sneaky error shit.

// ==UserScript==
// @name       Reload YouTube once
// @namespace  Mattari
// @version    0.1
// @description  adds "#" to URL, making YouTube reload once to avoid its sneaky error shit.
// @include      *.youtube.com/*
// ==/UserScript==

function redirect_yt() {
    if (!window.location.hash) {
      if (document.location.toString().indexOf("watch?v=") != -1) {
        window.location.replace(window.location.href+"#fix");
      }
    }
}

var url = document.location.toString();
document.querySelector('html').addEventListener('DOMNodeInserted', function(ev){
  var new_url = document.location.toString();
  if (url == new_url) return; // already checked or processed
  url = new_url;

  redirect_yt() // run when URL changes
});

setTimeout(() => { redirect_yt(); }, 1000);