Summary Files Commits Branches @commit @diff @stats
path: root / youtube-shorts-redirector.js
blob: 27ed51586b2358dc96f35ba14b6624648fcafd4f (plain) (blame)
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
// ==UserScript==
// @name         YouTube shorts redirector
// @description  Redirects all youtube shorts videos to normal video pages
// @author       Kamen Mladenov
// @match        *://*.youtube.com/*
// @icon         https://upload.wikimedia.org/wikipedia/commons/thumb/f/fc/Youtube_shorts_icon.svg/193px-Youtube_shorts_icon.svg.png
// @grant        none
// @run-at       document-end
// ==/UserScript==

function redirect() {
    if (window.location.pathname.indexOf('shorts') !== 1) {
        return;
    }

    const loc = 'sh_' + window.location.pathname.substr(8);

    if (localStorage.getItem(loc) === 'true') {
        return;
    }

    const latest = localStorage.getItem('sh_LATEST');
    if (latest) {
        localStorage.removeItem(latest);
    }

    localStorage.setItem(loc, true);
    localStorage.setItem('sh_LATEST', loc);
    window.location = window.location.href.replace("youtube.com/shorts/", "youtube.com/watch?v=");
}

const observer = new MutationObserver(redirect);
observer.observe(document.getElementsByTagName('ytd-app')[0], { childList: true, attributes: true, subtree: true, });