Last active
July 21, 2025 12:15
-
-
Save marcsello/c05d2d65109c4f65ba614de866a66354 to your computer and use it in GitHub Desktop.
Un-shorter: Automatically redirect youtube shorts to the actual videos.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Un-shorter | |
| // @namespace http://tampermonkey.net/ | |
| // @version 2024-02-23 | |
| // @description Automatically redirect youtube shorts to the actual videos. | |
| // @author Marcsello | |
| // @match https://www.youtube.com/* | |
| // @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com | |
| // @grant none | |
| // ==/UserScript== | |
| (function() { | |
| 'use strict'; | |
| function doMagic() { | |
| const path = window.location.pathname | |
| if (!path.startsWith("/shorts/")) { // not a short | |
| return | |
| } | |
| const videoId = path.split('/').slice(-1)[0] | |
| console.log("UNSHORTER: youtube short detected, redirecting to video with id: " + videoId) | |
| window.location.replace("https://www.youtube.com/watch?v=" + videoId) // this is a bit un-friendly but this is what we have... | |
| } | |
| window.navigation?.addEventListener("navigate", (event) => { | |
| doMagic() | |
| }) | |
| window.addEventListener("locationchange", function () { | |
| doMagic() | |
| }) | |
| window.addEventListener("popstate", function () { | |
| doMagic() | |
| }) | |
| // spa magic from https://stackoverflow.com/a/67825703 | |
| let previousUrl = location.href; | |
| const observer = new MutationObserver(function(mutations) { | |
| if (location.href !== previousUrl) { | |
| previousUrl = location.href; | |
| doMagic() | |
| } | |
| }); | |
| observer.observe(document, {subtree: true, childList: true}); | |
| console.log("UNSHORTER: ready!") | |
| doMagic() | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment