-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
31 lines (26 loc) · 863 Bytes
/
main.js
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
let lastUrl = location.href;
new MutationObserver(() => {
const currentUrl = location.href;
if (currentUrl !== lastUrl) {
lastUrl = currentUrl;
if (isShortsPage(currentUrl)) {
shortsToNormal();
}
}
}).observe(document, { subtree: true, childList: true });
window.onload = shortsToNormal();
function shortsToNormal() {
var pathArray = window.location.pathname.split('/');
if (pathArray[1] === 'shorts') {
let query = pathArray[2];
const newUrl = new URL('https://www.youtube.com/watch');
newUrl.searchParams.set('v', query);
history.replaceState(null, '', newUrl.toString()); // Replace the URL in the history
location.href = newUrl;
}
}
// check whether the current URL is YouTube Shorts
function isShortsPage(url) {
var pathArray = new URL(url).pathname.split('/');
return pathArray[1] === 'shorts';
}