Forces YouTube links to load with a real page navigation instead of SPA routing.
Script này sẽ không được không được cài đặt trực tiếp. Nó là một thư viện cho các script khác để bao gồm các chỉ thị meta
// @require https://update.sleazyfork.org/scripts/579644/1834066/Youtube%20Error%20fix.js
// ==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);
}
});
})();