Youtube Error fix

Forces YouTube links to load with a real page navigation instead of SPA routing.

Dieses Skript sollte nicht direkt installiert werden. Es handelt sich hier um eine Bibliothek für andere Skripte, welche über folgenden Befehl in den Metadaten eines Skriptes eingebunden wird // @require https://update.sleazyfork.org/scripts/579644/1834066/Youtube%20Error%20fix.js

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Youtube Error fix
// @version      1.0
// @description  Forces YouTube links to load with a real page navigation instead of SPA routing.
// @match        https://www.youtube.com/*
// @grant        none
// ==/UserScript==

(function () {
  'use strict';

  function isYouTubeLink(url) {
    try {
      const u = new URL(url, location.href);
      return u.hostname.endsWith('youtube.com') || u.hostname.endsWith('youtu.be');
    } catch {
      return false;
    }
  }

  function hardNavigate(url) {
    if (!url) return;
    location.href = url;
  }

  document.addEventListener(
    'click',
    (e) => {
      const a = e.target.closest && e.target.closest('a[href]');
      if (!a) return;

      const url = a.href;
      if (!isYouTubeLink(url)) return;

      // Let modified clicks behave normally
      if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || e.button !== 0) return;

      e.preventDefault();
      e.stopPropagation();
      hardNavigate(url);
    },
    true
  );

  // Also catch YouTube's SPA-style navigation attempts
  window.addEventListener('yt-navigate-start', (e) => {
    const url = e && e.detail && e.detail.url;
    if (url && isYouTubeLink(url)) {
      hardNavigate(url);
    }
  });
})();