-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathYouTube Shorts to Watch Redirect.user.js
More file actions
39 lines (35 loc) · 1.26 KB
/
Copy pathYouTube Shorts to Watch Redirect.user.js
File metadata and controls
39 lines (35 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// ==UserScript==
// @name YouTube Shorts to Watch Redirect
// @namespace http://tampermonkey.net/
// @version 1.1
// @description Redirect YouTube Shorts to regular watch URL, including when navigating within site (SPA support)
// @author OpenAI
// @match https://www.youtube.com/*
// @run-at document-start
// @grant none
// ==/UserScript==
(function () {
'use strict';
function redirectIfShorts() {
const currentUrl = location.href;
const shortsMatch = currentUrl.match(/\/shorts\/([a-zA-Z0-9_-]+)/);
if (shortsMatch) {
const videoId = shortsMatch[1];
const newUrl = `https://www.youtube.com/watch?v=${videoId}`;
if (location.href !== newUrl) {
history.replaceState(null, '', newUrl); // update URL in history
location.reload(); // reload to load video in correct player
}
}
}
// Initial check
redirectIfShorts();
// Observe URL changes (for SPA)
let lastUrl = location.href;
new MutationObserver(() => {
if (location.href !== lastUrl) {
lastUrl = location.href;
redirectIfShorts();
}
}).observe(document, { subtree: true, childList: true });
})();